Devel::SmallProf(3)
π Devel::SmallProf β the per-line Perl profiler bestie π
okay so this is Devel::SmallProf(3) from the User Contributed Perl Documentation section, and honestly? she's a little icon. let's get into it π«Ά
β¨ NAME β¨
Devel::SmallProf β a per-line Perl profiler. yes. per. line. she's looking at every single line of ur code and telling u where the time went π
πΈ SYNOPSIS πΈ
perl5 -d:SmallProf test.pl
that's it. that's the whole vibe check. β¨
π¦ DESCRIPTION π¦
okay so bestie, here's the tea β β the Devel::SmallProf profiler is focused on the time taken for a program run on a line-by-line basis. like, per line. not per sub, not per vibes. per LINE.
she's designed to be as "small" as possible in two ways:
- in terms of impact on the speed and memory usage of the program being profiled, and
- in terms of being simple to use.
lowkey the whole point. no cap. π
all those stats get dropped into a file called smallprof.out, and the format is this:
<num> <time> <ctime> <line>:<text>
breaking that down for u, bestie:
<num>β the number of times that line got executed<time>β the amount of "wall time" (that's time according to the clock on the wall vs. cpu time) spent executing it<ctime>β the amount of cpu time expended on it<line>β the line number<text>β the actual text of the executed line (read from the file)
this package uses the debugging hooks in Perl, so she needs the -d switch. so to profile test.pl, u use this command:
perl5 -d:SmallProf test.pl
once the script is done, the statistics in smallprof.out can be sorted to show which lines took the most time π₯. u can sort to find which lines take the longest either with the sort command:
sort -k 2nr,2 smallprof.out | less
or with a perl script:
open(PROF,"smallprof.out");
@sorted = sort {(split(/\s+/,$b))[2] <=>
(split(/\s+/,$a))[2]} <PROF>;
close PROF;
print join('',@sorted);
pick ur fighter. both slay. π
π NOTES π
bullet points, but make them iconic:
- the "wall time" readings come from
Time::HiResand are reasonably useful, at least on the author's system. the cpu times come from the'times'built-in and the granularity is not necessarily as small as with the wall time. on some systems this column may be useful. on others it may not. so likeβ¦ it depends π SmallProfdoes attempt to make up for its shortcomings by subtracting a small amount from each timing (null time compensation). this should help somewhat with the accuracy. she's trying her best ok πSmallProfdepends on theTime::HiRespackage to do its timings. it claims to require version 1.20, but may work with earlier versions, depending on ur platform. (not making promises bestie, she's just saying)
π OPTIONS π
SmallProf has 4 variables which u can use during ur script to affect what gets profiled. four. lil squad. π
$DB::drop_zeros(z) β if u do not wish to see lines which were never called, set the variable$DB::drop_zeros = 1. withdrop_zerosset,SmallProfcan be used for basic coverage analysis. π$DB::profile(p) β to turn off profiling for a time, insert a$DB::profile = 0into ur code (profiling may be turned back on with$DB::profile = 1). all of the time between profiling being turned off and back on again will be lumped together and reported on the$DB::profile = 0line. this can be used to summarize a subroutine call or a chunk of code. group chat energy fr fr π«Ά%DB::packagesβ to only profile code in a certain package, set the%DB::packagesarray. for example, to see only the code in packagesmainandTest1, do this:
%DB::packages = ( 'main' => 1, 'Test1' => 1 );
$DB::grep_format(g) β generates output on a format similar togrep, easily parseable from tools like Emacs (see below). π
grep format output appears as:
file name : line num : count : time : ctime : source
or
file name : line num : count : time : ctime : (eval n: line num) source
for code inside evals.
times appear in miliseconds.
okay so these variables can be put in a file called .smallprof in the current directory. for example, a .smallprof containing
$DB::drop_zeros = 1;
$DB::profile = 0;
will set SmallProf to not report lines which are never touched for any file profiled in that directory, and will set profiling off initially (presumably to be turned on only for a small portion of code). she's being strategic π
the environment variable SMALLPROF_CONFIG can also be used to set those flags, i.e:
SMALLPROF_CONFIG=zg perl -d:SmallProf my_script.plx
that activates drop_zeros and grep_format modes. two birds, one env var. slay. π
π INSTALLATION π
just the usual:
perl Makefile.PL
make
make test
make install
and she should install fine via the CPAN module. iconic behavior, no notes. β¨
π BUGS π
okay bestie, sit down, we gotta talk π«
- Subroutine calls are currently not under the control of
%DB::packages. this should not be a great inconvenience in general. (she said, reassuringly) - The handling of evals is bad news. π this is due to Perl's handling of evals under the
-dflag. for certain evals,caller()returns'(eval n)'for the filename and for others it doesn't. for some of those which it does, the array@{'_<filename'}contains the code of the eval. for others it doesn't. sometime, when the author has an extra tuit or two, they'll figure out why and how to compensate for this. (Note: 5.6.0 made some debugging changes. This may now be fixed, I'm not sure.) SmallProfmust be invoked from the command line. if it is included on the shebang line, the file in which it is included will not be visible in the symbol table. profiling will continue as expected, but the contents of the source lines will not be listed. this is new as of 5.6.0.- Comments, advice and questions are welcome. if u see inefficent stuff in this module and have a better way, please let them know. π«Ά (yes, "inefficent" β we're quoting the vibe exactly)
π EMACS/XEMACS HACK π
three steps, bestie, and ur living ur best debugging life:
- use the
DB::grep_formatflag to turn on grep like format, i.e.
SMALLPROF_CONFIG=g perl -d:SmallProf myscript.pl
- tell Emacs/XEmacs to read
smallprof.outas grep output:
M-x grep RET C-a C-k cat smallprof.out RET
- point and click to go to the script hot spots! π₯π₯π₯
π AUTHOR π
Devel::SmallProf was developed by Ted Ashton <ashted@cpan.org>. it is currently being maintained by Salvador FandiΓ±o <sfandino@yahoo.com>.
SmallProf was developed from code originally posted to usenet by Philippe Verdret <philippe.verdret@sonovision-itep.fr>. special thanks to Geoffrey Broadwell <habusan2@sprynet.com> for his assistance on the Win32 platform and to Philippe for his patient assistance in testing and debugging. legends only π
π COPYRIGHT AND LICENSE π
- Copyright (c) 1997-2000 Ted Ashton
- Copyright (c) 2003-2007 Salvador FandiΓ±o
this module is free software and can be redistributed and/or modified under the same terms as Perl itself. periodt. π
π SEE ALSO π
Devel::FastProfis a simplified and much faster version of this module.Devel::DProf,Time::HiRes.
π POD ERRORS π
hey! the above document had some coding errors, which are explained below:
around line 384:
Non-ASCII character seen before =encoding in 'FandiΓ±o'. Assuming
CP1252
not her fault, it's the Γ±. she's international π
and that's the whole page bestie β this was perl v5.42.0, dated 2025-07-25, from Devel::SmallProf(3). go profile something and tell me what ate the most wall time π«Άβ¨π
π¦ where this page comes from
- fedora 43: perl-Devel-SmallProf 2.02-51.fc43 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms