Index: openacs-4/packages/acs-developer-support/tcl/acs-developer-support-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-developer-support/tcl/acs-developer-support-procs.tcl,v diff -u -r1.28 -r1.29 --- openacs-4/packages/acs-developer-support/tcl/acs-developer-support-procs.tcl 19 Mar 2004 12:14:16 -0000 1.28 +++ openacs-4/packages/acs-developer-support/tcl/acs-developer-support-procs.tcl 20 Apr 2004 21:12:39 -0000 1.29 @@ -537,22 +537,34 @@ return $comments } -ad_proc -public ds_profile { command tag } { +ad_proc -public ds_profile { command {tag {}} } { Helper proc for performance profiling. This will count the number of invocations of the given tag, the total time spent within all invocations (between the corresponding 'ds_profile start' and 'ds_profile stop' invocations). The results will be output at the bottom of the page, and include the average time spent per invocation. - @param command start or stop. + @param command + + @param tag The name of the operation you're timing. Could be the name of a procedure, or some other unique identifier. } { global ds_profile__total_ms ds_profile__iterations ds_profile__start_clock switch $command { start { + if { [empty_string_p $tag] } { + error "Tag parameter is required" + } set ds_profile__start_clock($tag) [clock clicks -milliseconds] } stop { + if { [empty_string_p $tag] } { + error "Tag parameter is required" + } set num_ms [expr [clock clicks -milliseconds] - $ds_profile__start_clock($tag)] set ds_profile__start_clock($tag) {} @@ -564,8 +576,28 @@ set ds_profile__total_ms($tag) [expr [set ds_profile__total_ms($tag)] + $num_ms] set ds_profile__iterations($tag) [expr [set ds_profile__iterations($tag)] + 1] } + log { + if { ![empty_string_p $tag] } { + set tags [list $tag] + } else { + set tags [list] + if { [info exists ds_profile__total_ms] } { + set tags [lsort [array names ds_profile__total_ms]] + } + } + foreach tag $tags { + set total_ms [lc_numeric [set ds_profile__total_ms($tag)]] + set iterations [set ds_profile__iterations($tag)] + if { $iterations > 0 } { + set average_ms [lc_numeric [expr $total_ms / $iterations]] + } else { + set average_ms {} + } + ns_log Notice "Developer Support Profiling: Tag '$tag' | Total time: $total_ms ms | \# iterations: $iterations | Time per iteration: $average_ms ms" + } + } default { - error "Invalid command. Valid commands are 'start' and 'stop'." + error "Invalid command. Valid commands are 'start', 'stop', and 'log'." } } -} \ No newline at end of file +}