function() clock -> long does
return pic_ticks
type _ProfileEntry is
_ProfileEntry _next
cstr fname
long total_time
long exclusive_time
long exc_entry_time
long tot_entry_time
int stack_count
int entrance_count
endtype
_ProfileEntry __profiler_entry_chain_head
_ProfileEntry __profiler_entry_chain_tail
function(cstr name) orth::internal::hooks::make_profile_entry -> _ProfileEntry does
_ProfileEntry entry = malloc(@sizeof(_ProfileEntry)@)|_ProfileEntry
entry.fname=name
entry.total_time=0|long
entry.exclusive_time=0|long
entry.exc_entry_time=0|long
entry.tot_entry_time=0|long
entry.stack_count=0
entry.entrance_count=0
entry._next=null|_ProfileEntry
return entry
function(cstr name) orth::internal::hooks::get_profile_entry -> _ProfileEntry does
_ProfileEntry curr=__profiler_entry_chain_head
while curr|ptr|int!=null|int do
if curr.fname==name do
return curr
done
curr=curr._next
done
__profiler_entry_chain_tail._next=orth::internal::hooks::make_profile_entry(name)
__profiler_entry_chain_tail=__profiler_entry_chain_tail._next
return __profiler_entry_chain_tail
function(cstr name) orth::internal::hooks::profile_enter -> void does
if __profiler_entry_chain_tail|ptr|int!=__profiler_entry_chain_head|ptr|int do
_ProfileEntry last = orth::internal::hooks::get_profile_entry(__stack_tail.name)
last.exclusive_time+=clock()-last.exc_entry_time
done
_ProfileEntry this = orth::internal::hooks::get_profile_entry(name)
if this.stack_count==0 do
this.tot_entry_time=clock()
this.exc_entry_time=this.tot_entry_time
else do
this.exc_entry_time=clock()
done
this.stack_count+=1
this.entrance_count+=1
return
function(cstr name) orth::internal::hooks::profile_exit -> void does
_ProfileEntry this = orth::internal::hooks::get_profile_entry(name)
this.exclusive_time+=clock()-this.exc_entry_time
this.stack_count-=1
if this.stack_count==0 do
this.total_time+=clock()-this.tot_entry_time
done
orth::internal::hooks::get_profile_entry(__stack_tail._prev.name).exc_entry_time=clock()
return
function() orth::internal::profile::display_profiling_data -> void does
__in_err=true
kterm:print("Profiling Data:\n")
_ProfileEntry curr=__profiler_entry_chain_head
while curr|ptr!=null do
if (curr.fname!="<dummy>") & (curr.fname!="main") & (-curr.fname:startswith("orth$$internal$$")) do
kterm:print(" tot:")
kterm:dumphexi(curr.total_time|int)
kterm:print(" exc:")
kterm:dumphexi(curr.exclusive_time|int)
kterm:print(" ent:")
kterm:dumphexi(curr.entrance_count)
kterm:print(" - ")
kterm:print(curr.fname)
kterm:print("\n")
done
curr=curr._next
done
__in_err=false
return
function() orth::internal::profile::install_profiler -> void does
__fex_addtl_callback_enter = orth::internal::hooks::profile_enter|AddtlEnterExitCallback
__fex_addtl_callback_exit = orth::internal::hooks::profile_exit|AddtlEnterExitCallback
__profiler_entry_chain_head=orth::internal::hooks::make_profile_entry("<dummy>")
__profiler_entry_chain_tail=__profiler_entry_chain_head
return
function() orth::internal::profile::disable_profiler -> void does
__fex_addtl_callback_enter = null|AddtlEnterExitCallback
__fex_addtl_callback_exit = null|AddtlEnterExitCallback
return