Prev: Perplexing memory allocation pattern in Tk under Windows
Next: Tcl-URL! - weekly Tcl news and links (Aug 13)
From: Fredrik Karlsson on 13 Aug 2010 07:12 Dear list, sorry if this is a stupid question, but I would like to get into profiling of some of my TclOO classes, i.e. some use cases for their methods. Now, I see that the Tcllib profiler package redefines the "proc" command to do the dynamic source code analysis. Now, would that behave anywhere near correctly on a TclOO object method call? If not, which I would guess is the case, are there alternatives which would work? /Fredrik
From: Donal K. Fellows on 13 Aug 2010 07:30
On 13 Aug, 12:12, Fredrik Karlsson <dargo...(a)gmail.com> wrote: > sorry if this is a stupid question, but I would like to get into > profiling of some of my TclOO classes, i.e. some use cases for their > methods. Now, I see that the Tcllib profiler package redefines the > "proc" command to do the dynamic source code analysis. Now, would that > behave anywhere near correctly on a TclOO object method call? No. > If not, which I would guess is the case, are there alternatives which > would work? Mix in some kind of interceptor class into an object you want to watch, like this: oo::class create interceptor { filter INTERCEPT method INTERCEPT args { set t [time { catch {next {*}$args} msg opts }] puts "[lindex $t 0]ms for [lindex $args 0] on [self]" return -options $opts $msg } } # A silly example class oo::class create example { method bar x { for {set i 0} {$i<$x} {incr i} { incr out $i } return $out } } example create foo puts [foo bar 500] # Attach the instrumentation and rerun with a little profiling... oo::objdefine foo mixin interceptor puts [foo bar 500] OK, that's a very noddy example but it shows how to do it. Donal. |