We've an application, developed and maintained by us. And user
interface to this is a tcl shell. I want to create a setup through
which we can track performance degradation/ improvement for each the
command exposed to user. Is there any Unix time like command which can
tell me how much time my command is taking? Can somebody enlighten me
how this can be done?
Say my tool has a tcl command "report_something [-opt1] [-opt2 arg2]"
Is there any std tcl way which will tell me CPU time or elapsed time
of "report_something" with/without its options?
I want to avoid a approach like create a script of command for our
application and use /usr/bin/time to measure over-all time to invoke
tool, execute script and quit.
Regards,
- Soumen
> Is there any std tcl way which will tell me CPU time or elapsed time
> of "report_something" with/without its options?
See the Tcl [time] command.
Jeff
set time [time {report_something -opt1 -opt2 arg2}]
puts "time: $time"
For a particular command, you can use the [time] command, e.g.:
set msg [time { report_something ... } 10]
That will run report_something ... 10 times and produce a message in the
form "NNN microseconds per iteration" for elapsed time. If you want a
report of time usage of lots/all commands in your application then there
are various profiler solutions available, see http://wiki.tcl.tk/782. I
recommend Salvatore Sanfilippo's etprof linked to from that wiki page.
These packages generally only profile Tcl procedures. If you want to
profile C commands, then a more complete profiler (e.g., perhaps
ActiveState's TclDevKit) could do it, or you could roll your own with
[trace add execution ... enter/leave] and [clock microseconds].
-- Neil
Thanks Neil and others.
I tried etprof - but it doesn't report anything. Gives o/p like
following:
my_app_tcl_shell> ::etprof::printLiveInfo
+-----------------+--------------+------+--------+--------------
+--------------+
|PROCNAME | EXCLUSIVETOT| %| CALLNUM| AVGPERCALL|
CUMULTOT|
+-----------------+--------------+------+--------+--------------
+--------------+
|TOPLEVEL | 0| 0.00%| 1| 0| NOT
AVAILABLE|
+-----------------+--------------+------+--------+--------------
+--------------+
(*) = Incomplete result, program inside that function.
I used it like following:
my_app_tcl_shell> source etprof.tcl
my_app_tcl_shell> report_something -opt1 arg1
my_app_tcl_shell> report_something_else
my_app_tcl_shell> ::etprof::printLiveInfo
My report_something and report_something_else are TCL i/f but their
actual implementation is in C.
Could it because of that? My requirement is not to profile down to C-
level. Rather to measure time
of report_something and report_something_else.
Regards,
~ Soumen
Thanks Bryan and Jeff. Is there a way to get CPU time?
If you have the TclX package, use its [times] command. Be aware that
it also counts time spent in subprocesses.
Donal.
Is it part of Tcl Development Kit? I can find that in my company n/w
but not able to find TclX there.
Briefly, if you have TDK, you have [times] and far, far more.
The documentation is more of a mess than I realized.
package require Tclx
info commands times
should demonstrate, though, that you have [times].
As I said, etprof only profiles Tcl procedures. You'll need to either
manually do the timing using [trace add execution]/[time] or find a more
comprehensive profiler.
Cheers,
Neil