Devel::SimpleProfiler - quick and dirty perl code profiler
use Devel::SimpleProfiler; Devel::SimpleProfiler::init( "/tmp/tmpfile", qr/RegexToMatchSubNames/ ); Devel::SimpleProfiler::start; .... if( ! fork ) { # must restart for child process Devel::SimpleProfiler::start; } .... Devel::SimpleProfiler::analyze('total'); exit; # ---- PRINTS OUT (and sorts by total) ----- performance stats ( all times are in ms) sub | # calls | total t | mean t | avg t | max t | min t -----------------+---------+---------+--------+-------+-------+------ main::test_suite | 1 | 2922 | 2922 | 2922 | 2922 | 2922 OtherThing::fun | 27 | 152 | 1 | 5 | 63 | 0 SomeObj::new | 3 | 26 | 8 | 8 | 8 | 8 ....
This is meant to be a simple way to get a performance benchmark for perl subs. It uses the fantastic Aspect module written by Adam Kennedy, Marcel Gruenauer and Ran Eilam to monkey patch select perl subs and gather statistics about them.
init takes two arguments : a temp file to use and a regular expression to find subs to measure. By default, the file is /tmp/foo and the regex is qr/^main:/; init should be called once for a run.
analyze simply outputs the data collected from the profiler so far in a table with the columns * sub name * total number of calls * total time in ms * mean time in ms * average time in ms * max time in ms * min time in ms This can be called as many times as desired. It takes an optional argument to sort by, which can be one of : 'calls', 'total', 'mean', 'avg', 'max', 'min' The default sorting is by average.
This is called to start or continue the data collection process. It takes an option regex parameter in case something different is desired than the one given at init. This must be called to continue the profiling in a child thread if one is forked.
This does not work so well if the subs are dynamically attached methods.
Eric Wolf coyocanid@gmail.com
Copyright (c) 2015 Eric Wolf. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Version 1.00 (November 18, 2015))
To install Devel::SimpleProfiler, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Devel::SimpleProfiler
CPAN shell
perl -MCPAN -e shell install Devel::SimpleProfiler
For more information on module installation, please visit the detailed CPAN module installation guide.