Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

measuring time of tcl command

1,052 views
Skip to first unread message

Soumen

unread,
Apr 24, 2009, 9:53:07 AM4/24/09
to
Hi,

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


jeff_g...@pobox.com

unread,
Apr 24, 2009, 9:58:57 AM4/24/09
to
On Apr 24, 8:53 am, Soumen <soume...@gmail.com> wrote:

> 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

Bryan Oakley

unread,
Apr 24, 2009, 10:02:10 AM4/24/09
to
On Apr 24, 8:53 am, Soumen <soume...@gmail.com> wrote:
> Hi,
>
> 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?


set time [time {report_something -opt1 -opt2 arg2}]
puts "time: $time"

http://tcl.tk/man/tcl8.5/TclCmd/time.htm

Neil Madden

unread,
Apr 24, 2009, 10:12:50 AM4/24/09
to

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

Soumen

unread,
Apr 27, 2009, 4:52:11 AM4/27/09
to
On Apr 24, 7:12 pm, Neil Madden <n...@cs.nott.ac.uk> wrote:
> Soumen wrote:
> > Hi,
>
> > 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.
>
> 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, seehttp://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

Soumen

unread,
Apr 27, 2009, 6:39:33 AM4/27/09
to

Thanks Bryan and Jeff. Is there a way to get CPU time?

dkf

unread,
Apr 27, 2009, 6:45:43 AM4/27/09
to
On 27 Apr, 11:39, Soumen <soume...@gmail.com> wrote:
> 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.

Soumen

unread,
Apr 27, 2009, 8:39:14 AM4/27/09
to

Is it part of Tcl Development Kit? I can find that in my company n/w
but not able to find TclX there.

Cameron Laird

unread,
Apr 27, 2009, 10:36:31 AM4/27/09
to
In article <71711678-246e-48e6...@s1g2000prd.googlegroups.com>,

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].

Neil Madden

unread,
Apr 29, 2009, 6:11:04 AM4/29/09
to

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

0 new messages