(statprof)
is intended to be a fairly simple statistical profiler for
guile. It is in the early stages yet, so consider its output still suspect, and
please report any bugs to guile-devel at gnu.org, or to me directly at
rlb at defaultvalue.org.
A simple use of statprof would look like this:
(statprof-reset 0 50000 #t) (statprof-start) (do-something) (statprof-stop) (statprof-display)
This would reset statprof, clearing all accumulated statistics, then start profiling, run some code, stop profiling, and finally display a gprof flat-style table of statistics which will look something like this:
% cumulative self self total time seconds seconds calls ms/call ms/call name 35.29 0.23 0.23 2002 0.11 0.11 - 23.53 0.15 0.15 2001 0.08 0.08 positive? 23.53 0.15 0.15 2000 0.08 0.08 + 11.76 0.23 0.08 2000 0.04 0.11 do-nothing 5.88 0.64 0.04 2001 0.02 0.32 loop 0.00 0.15 0.00 1 0.00 150.59 do-something ...
All of the numerical data with the exception of the calls column is statistically approximate. In the following column descriptions, and in all of statprof, "time" refers to execution time (both user and system), not wall clock time.
The profiler uses eq?
and the procedure object itself to identify the
procedures, so it won't confuse different procedures with the same name. They
will show up as two different rows in the output.
Right now the profiler is quite simplistic. I cannot provide call-graphs or other higher level information. What you see in the table is pretty much all there is. Patches are welcome :-)
The profiler works by setting the unix profiling signal ITIMER_PROF
to go
off after the interval you define in the call to statprof-reset
. When the
signal fires, a sampling routine is run which looks at the current procedure
that's executing, and then crawls up the stack, and for each procedure
encountered, increments that procedure's sample count. Note that if a procedure
is encountered multiple times on a given stack, it is only counted once. After
the sampling is complete, the profiler resets profiling timer to fire again
after the appropriate interval.
Meanwhile, the profiler keeps track, via get-internal-run-time
, how much
CPU time (system and user – which is also what ITIMER_PROF
tracks), has
elapsed while code has been executing within a statprof-start/stop block.
The profiler also tries to avoid counting or timing its own code as much as possible.
Returns
#t
ifstatprof-start
has been called more times thanstatprof-stop
,#f
otherwise.
Reset the statprof sampler interval to sample-seconds and sample-microseconds. If count-calls? is true, arrange to instrument procedure calls as well as collecting statistical profiling data.
Enables traps and debugging as necessary.
Fold proc over the call-data accumulated by statprof. Cannot be called while statprof is active. proc should take two arguments,
(
call-data prior-result)
.Note that a given proc-name may appear multiple times, but if it does, it represents different functions with the same name.
Returns the call-data associated with proc, or
#f
if none is available.
Displays a gprof-like summary of the statistics collected. Unless an optional port argument is passed, uses the current output port.