1Devel::GraphVizProf(3)User Contributed Perl DocumentationDevel::GraphVizProf(3)
2
3
4

NAME

6       Devel::GraphVizProf - per-line Perl profiler (with graph output)
7

SYNOPSIS

9               perl -d:GraphVizProf test.pl > test.dot
10               dot -Tpng test.dot > test.png
11

DESCRIPTION

13       NOTE: This module is a hack of Devel::SmallProf by Ted Ashton. It has
14       been modified by Leon Brocard to produce output for GraphViz, but
15       otherwise the only thing I have done is change the name. I hope to get
16       my patches put into the main Devel::SmallProf code eventually, or
17       alternatively read the output of Devel::SmallProf. Anyway, the normal
18       documentation, which you can probably ignore, follows.
19
20       The Devel::GraphVizProf profiler is focused on the time taken for a
21       program run on a line-by-line basis.  It is intended to be as "small"
22       in terms of impact on the speed and memory usage of the profiled
23       program as possible and also in terms of being simple to use.  Those
24       statistics are placed in the file smallprof.out in the following
25       format:
26
27               <num> <time> <ctime> <line>:<text>
28
29       where <num> is the number of times that the line was executed, <time>
30       is the amount of "wall time" (time according the the clock on the wall
31       vs. cpu time) spent executing it, <ctime> is the amount of cpu time
32       expended on it and <line> and <text> are the line number and the actual
33       text of the executed line (read from the file).
34
35       The package uses the debugging hooks in Perl and thus needs the -d
36       switch, so to profile test.pl, use the command:
37
38               perl5 -d:GraphVizProf test.pl
39
40       Once the script is done, the statistics in smallprof.out can be sorted
41       to show which lines took the most time.  The output can be sorted to
42       find which lines take the longest, either with the sort command:
43
44               sort -k 2nr,2 smallprof.out | less
45
46       or a perl script:
47
48               open(PROF,"smallprof.out");
49               @sorted = sort {(split(/\s+/,$b))[2] <=>
50                               (split(/\s+/,$a))[2]} <PROF>;
51               close PROF;
52               print join('',@sorted);
53

NOTES

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

OPTIONS

70       GraphVizProf has 3 variables which can be used during your script to
71       affect what gets profiled.
72
73       •   If you do not wish to see lines which were never called, set the
74           variable "$DB::drop_zeros = 1".  With "drop_zeros" set,
75           GraphVizProf can be used for basic coverage analysis.
76
77       •   To turn off profiling for a time, insert a "$DB::profile = 0" into
78           your code (profiling may be turned back on with "$DB::profile =
79           1").  All of the time between profiling being turned off and back
80           on again will be lumped together and reported on the "$DB::profile
81           = 0" line.  This can be used to summarize a subroutine call or a
82           chunk of code.
83
84       •   To only profile code in a certain package, set the %DB::packages
85           array.  For example, to see only the code in packages "main" and
86           "Test1", do this:
87
88                   %DB::packages = ( 'main' => 1, 'Test1' => 1 );
89
90       •   These variables can be put in a file called .smallprof in the
91           current directory.  For example, a .smallprof containing
92
93                   $DB::drop_zeros = 1;
94                   $DB::profile = 0;
95
96           will set GraphVizProf to not report lines which are never touched
97           for any file profiled in that directory and will set profiling off
98           initially (presumably to be turned on only for a small portion of
99           code).
100

INSTALLATION

102       Just the usual
103
104               perl Makefile.PL
105               make
106               make test
107               make install
108
109       and should install fine via the CPAN module.
110

BUGS

112       Subroutine calls are currently not under the control of %DB::packages.
113       This should not be a great inconvenience in general.
114
115       The handling of evals is bad news.  This is due to Perl's handling of
116       evals under the -d flag.  For certain evals, caller() returns '(eval
117       n)' for the filename and for others it doesn't.  For some of those
118       which it does, the array "@{'_<filename'}" contains the code of the
119       eval.  For others it doesn't.  Sometime, when I've an extra tuit or
120       two, I'll figure out why and how I can compensate for this.
121
122       Comments, advice and questions are welcome.  If you see inefficent
123       stuff in this module and have a better way, please let me know.
124

AUTHOR

126       Ted Ashton <ashted@southern.edu>
127
128       GraphVizProf was developed from code originally posted to usenet by
129       Philippe Verdret <philippe.verdret@sonovision-itep.fr>.  Special thanks
130       to Geoffrey Broadwell <habusan2@sprynet.com> for his assistance on the
131       Win32 platform and to Philippe for his patient assistance in testing
132       and debugging.
133
134       Copyright (c) 1997 Ted Ashton
135
136       This module is free software; you can redistribute it or modify it
137       under the Perl License, a copy of which is available at
138       <http://dev.perl.org/licenses/>.
139

SEE ALSO

141       Devel::DProf, Time::HiRes.
142
143
144
145perl v5.34.0                      2021-07-22            Devel::GraphVizProf(3)
Impressum