Re: Pofiling or timing in TCL
- From: "R. T. Wurth" <rwurth@xxxxxxx>
- Date: Sat, 20 Aug 2005 00:29:08 GMT
"Cassy" <harshakasi@xxxxxxxxx> wrote in
news:1124355120.148241.130220@xxxxxxxxxxxxxxxxxxxxxxxxxxxx:
> OK I found it ...
>
> The command and usage is :
>
> profile ?-commands? ?-eval? on
>
> I have two questions now:
>
> 1. Where the heck should I place the above command in my code,
> supposing that I have a main procedure "RVE_main" that internally
> calls many other ? I want to profile my RVE_main basically.
Place the command some place where it will be executed before the code
you want profiled. If you have some one-time executed code that sets up
your environment, parses arguments, opens files, etc., followed by a
processing loop that does the real heart of your work, place it between
the two.
> 2. Then for reporting the profiled information, we use the "profrep"
> syntax that includes an "array variable" which I need to get from the
> above command (I don't know how, can somebody throw some light on
> this) ?
You missed a step: profile off arrayVar
This step stops the profiling and dumps the raw results into the named
array variable, which the profile command will create. Place this some
place where it will be run after the main code of interest has executed.
Then you can run profrep. It's array variable argument is the same
array you supplied to [profile off].
If your main processing loop runs tens to hundreds of thousands of
times, you might get too much data, and it might take too long, because
profiling dramatically slows down the code. In such cases, I introduce
an extra loop counter set to zero immediately before the loop, and
incremented at the top of the loop before anything else. That is
immediately followed by an if statement that turns profiling on if the
count is, for example, 10 (choose a number greater than 1 to ensure that
the byte-code compilation overhead the first time through doesn't skew
your data, choosing 10 may (or may not, depending on the complexity of
your code's logic and the nature of your data) ensure that you have
traversed (and thus byte compiled) many or most of the paths through
your code. Then, place another if statement that turns the profiling
off at some suitably higher loop count, such as 110, or 1010, or some
other number, depending on how accurate you want your data, how complex
your logic is, and how long you are willing to wait for results. You
should also have another variable that tracks the on/off state of
profiling so that if the loop finishes before you expect it to, you can
check this variable following the loop and if profiling is still
running, turn it off.
Sorry for the delay getting back to you, but it's been a busy week for
me. I hope this helps.
And yes, as you surmised in a later posting, you have to use
package require Tclx
to obtain access to Tclx (assuming your Tcl interpreter was packaged
with Tclx. If you use ActiveTcl from ActiveState, it is, otherwise, if
you hand-compiled your own Tcl/Tk from sources, I think you can get Tclx
from <<http://tclx.sf.net/>>.
--
Rich Wurth / rwurth@xxxxxxx / Rumson, NJ USA
.
- References:
- Pofiling or timing in TCL
- From: Cassy
- Re: Pofiling or timing in TCL
- From: R. T. Wurth
- Re: Pofiling or timing in TCL
- From: Cassy
- Re: Pofiling or timing in TCL
- From: Cassy
- Pofiling or timing in TCL
- Prev by Date: Tclx package ...
- Next by Date: Re: tackling the packer
- Previous by thread: Re: Pofiling or timing in TCL
- Next by thread: Update command
- Index(es):
Relevant Pages
|