1Devel::SmallProf(3)   User Contributed Perl Documentation  Devel::SmallProf(3)
2
3
4

NAME

6       Devel::SmallProf - per-line Perl profiler
7

SYNOPSIS

9               perl5 -d:SmallProf test.pl
10

DESCRIPTION

12       The Devel::SmallProf profiler is focused on the time taken for a
13       program run on a line-by-line basis.  It is intended to be as "small"
14       in terms of impact on the speed and memory usage of the profiled
15       program as possible and also in terms of being simple to use.  Those
16       statistics are placed in the file smallprof.out in the following
17       format:
18
19               <num> <time> <ctime> <line>:<text>
20
21       where <num> is the number of times that the line was executed, <time>
22       is the amount of "wall time" (time according the the clock on the wall
23       vs. cpu time) spent executing it, <ctime> is the amount of cpu time
24       expended on it and <line> and <text> are the line number and the actual
25       text of the executed line (read from the file).
26
27       The package uses the debugging hooks in Perl and thus needs the -d
28       switch, so to profile test.pl, use the command:
29
30               perl5 -d:SmallProf test.pl
31
32       Once the script is done, the statistics in smallprof.out can be sorted
33       to show which lines took the most time.  The output can be sorted to
34       find which lines take the longest, either with the sort command:
35
36               sort -k 2nr,2 smallprof.out | less
37
38       or a perl script:
39
40               open(PROF,"smallprof.out");
41               @sorted = sort {(split(/\s+/,$b))[2] <=>
42                               (split(/\s+/,$a))[2]} <PROF>;
43               close PROF;
44               print join('',@sorted);
45

NOTES

47       ·   The "wall time" readings come from Time::HiRes and are reasonably
48           useful, at least on my system.  The cpu times come from the 'times'
49           built-in and the granularity is not necessarily as small as with
50           the wall time.  On some systems this column may be useful.  On
51           others it may not.
52
53       ·   SmallProf does attempt to make up for its shortcomings by
54           subtracting a small amount from each timing (null time
55           compensation).  This should help somewhat with the accuracy.
56
57       ·   SmallProf depends on the Time::HiRes package to do its timings.  It
58           claims to require version 1.20, but may work with earlier versions,
59           depending on your platform.
60

OPTIONS

62       SmallProf has 4 variables which can be used during your script to
63       affect what gets profiled.
64
65       $DB::drop_zeros (z)
66           If you do not wish to see lines which were never called, set the
67           variable "$DB::drop_zeros = 1".  With "drop_zeros" set, SmallProf
68           can be used for basic coverage analysis.
69
70       $DB::profile (p)
71           To turn off profiling for a time, insert a "$DB::profile = 0" into
72           your code (profiling may be turned back on with "$DB::profile =
73           1").  All of the time between profiling being turned off and back
74           on again will be lumped together and reported on the "$DB::profile
75           = 0" line.  This can be used to summarize a subroutine call or a
76           chunk of code.
77
78       %DB::packages
79           To only profile code in a certain package, set the %DB::packages
80           array.  For example, to see only the code in packages "main" and
81           "Test1", do this:
82
83                   %DB::packages = ( 'main' => 1, 'Test1' => 1 );
84
85       $DB::grep_format (g)
86           Generates output on a format similar to grep easily parseable from
87           tools like Emacs (see below).
88
89           grep format output appears as:
90
91             file name : line num : count : time : ctime : source
92
93           or
94
95             file name : line num : count : time : ctime : (eval n: line num) source
96
97           for code inside evals.
98
99           Times appear in miliseconds.
100
101       These variables can be put in a file called .smallprof in the current
102       directory.  For example, a .smallprof containing
103
104               $DB::drop_zeros = 1;
105               $DB::profile = 0;
106
107       will set SmallProf to not report lines which are never touched for any
108       file profiled in that directory and will set profiling off initially
109       (presumably to be turned on only for a small portion of code).
110
111       Environment variable "SMALLPROF_CONFIG" can be also used to set those
112       flags, i.e:
113
114          SMALLPROF_CONFIG=zg perl -d:SmallProf my_script.plx
115
116       activates "drop_zeros" and "grep_format" modes.
117

INSTALLATION

119       Just the usual
120
121               perl Makefile.PL
122               make
123               make test
124               make install
125
126       and should install fine via the CPAN module.
127

BUGS

129       Subroutine calls are currently not under the control of %DB::packages.
130       This should not be a great inconvenience in general.
131
132       The handling of evals is bad news.  This is due to Perl's handling of
133       evals under the -d flag.  For certain evals, caller() returns '(eval
134       n)' for the filename and for others it doesn't.  For some of those
135       which it does, the array "@{'_<filename'}" contains the code of the
136       eval.  For others it doesn't.  Sometime, when I've an extra tuit or
137       two, I'll figure out why and how I can compensate for this.  (Note:
138       5.6.0 made some debugging changes.  This may now be fixed, I'm not
139       sure).
140
141       SmallProf must be invoked from the command line.  If it is included on
142       the shebang line, the file in which it is included will not be visible
143       in the symbol table.  Profiling will continue as expected, but the
144       contents of the source lines will not be listed.  This is new as of
145       5.6.0.
146
147       Comments, advice and questions are welcome.  If you see inefficent
148       stuff in this module and have a better way, please let me know.
149

EMACS/XEMACS HACK

151       1.  Use the "DB::grep_format" flag to turn on grep like format, i.e.
152
153             SMALLPROF_CONFIG=g perl -d:SmallProf myscript.pl
154
155       2.  Tell Emacs/XEmacs to read smallprof.out as grep output:
156
157             M-x grep RET C-a C-k cat smallprof.out RET
158
159       3.  Point and click to go to the script hot spots!
160

AUTHOR

162       Devel::SmallProf was developed by Ted Ashton <ashted@cpan.org>. It is
163       currently being maintained by Salvador Fandiño <sfandino@yahoo.com>.
164
165       SmallProf was developed from code originally posted to usenet by
166       Philippe Verdret <philippe.verdret@sonovision-itep.fr>.  Special thanks
167       to Geoffrey Broadwell <habusan2@sprynet.com> for his assistance on the
168       Win32 platform and to Philippe for his patient assistance in testing
169       and debugging.
170
172       Copyright (c) 1997-2000 Ted Ashton
173
174       Copyright (c) 2003-2007 Salvador Fandiño
175
176       This module is free software and can be redistributed and/or modified
177       under the same terms as Perl itself.
178

SEE ALSO

180       Devel::FastProf is a simplified and much faster version of this module.
181
182       Devel::DProf, Time::HiRes.
183

POD ERRORS

185       Hey! The above document had some coding errors, which are explained
186       below:
187
188       Around line 384:
189           Non-ASCII character seen before =encoding in 'Fandiño'. Assuming
190           CP1252
191
192
193
194perl v5.32.0                      2020-07-28               Devel::SmallProf(3)
Impressum