1Devel::GraphVizProf(3)User Contributed Perl DocumentationDevel::GraphVizProf(3)
2
3
4
6 Devel::GraphVizProf - per-line Perl profiler (with graph output)
7
9 perl -d:GraphVizProf test.pl > test.dot
10 dot -Tpng test.dot > test.png
11
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 oth‐
15 erwise the only thing I have done is change the name. I hope to get my
16 patches put into the main Devel::SmallProf code eventually, or alterna‐
17 tively read the output of Devel::SmallProf. Anyway, the normal documen‐
18 tation, 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 pro‐
23 gram as possible and also in terms of being simple to use. Those sta‐
24 tistics are placed in the file smallprof.out in the following format:
25
26 <num> <time> <ctime> <line>:<text>
27
28 where <num> is the number of times that the line was executed, <time>
29 is the amount of "wall time" (time according the the clock on the wall
30 vs. cpu time) spent executing it, <ctime> is the amount of cpu time
31 expended on it and <line> and <text> are the line number and the actual
32 text of the executed line (read from the file).
33
34 The package uses the debugging hooks in Perl and thus needs the -d
35 switch, so to profile test.pl, use the command:
36
37 perl5 -d:GraphVizProf test.pl
38
39 Once the script is done, the statistics in smallprof.out can be sorted
40 to show which lines took the most time. The output can be sorted to
41 find which lines take the longest, either with the sort command:
42
43 sort -k 2nr,2 smallprof.out ⎪ less
44
45 or a perl script:
46
47 open(PROF,"smallprof.out");
48 @sorted = sort {(split(/\s+/,$b))[2] <=>
49 (split(/\s+/,$a))[2]} <PROF>;
50 close PROF;
51 print join('',@sorted);
52
54 · The "wall time" readings come from Time::HiRes and are reasonably
55 useful, at least on my system. The cpu times come from the 'times'
56 built-in and the granularity is not necessarily as small as with
57 the wall time. On some systems this column may be useful. On oth‐
58 ers it may not.
59
60 · GraphVizProf does attempt to make up for its shortcomings by sub‐
61 tracting a small amount from each timing (null time compensation).
62 This should help somewhat with the accuracy.
63
64 · GraphVizProf depends on the Time::HiRes package to do its timings.
65 It claims to require version 1.20, but may work with earlier ver‐
66 sions, depending on your platform.
67
69 GraphVizProf has 3 variables which can be used during your script to
70 affect what gets profiled.
71
72 · If you do not wish to see lines which were never called, set the
73 variable "$DB::drop_zeros = 1". With "drop_zeros" set,
74 GraphVizProf can be used for basic coverage analysis.
75
76 · To turn off profiling for a time, insert a "$DB::profile = 0" into
77 your code (profiling may be turned back on with "$DB::profile =
78 1"). All of the time between profiling being turned off and back
79 on again will be lumped together and reported on the "$DB::profile
80 = 0" line. This can be used to summarize a subroutine call or a
81 chunk of code.
82
83 · To only profile code in a certain package, set the %DB::packages
84 array. For example, to see only the code in packages "main" and
85 "Test1", do this:
86
87 %DB::packages = ( 'main' => 1, 'Test1' => 1 );
88
89 · These variables can be put in a file called .smallprof in the cur‐
90 rent directory. For example, a .smallprof containing
91
92 $DB::drop_zeros = 1;
93 $DB::profile = 0;
94
95 will set GraphVizProf to not report lines which are never touched
96 for any file profiled in that directory and will set profiling off
97 initially (presumably to be turned on only for a small portion of
98 code).
99
101 Just the usual
102
103 perl Makefile.PL
104 make
105 make test
106 make install
107
108 and should install fine via the CPAN module.
109
111 Subroutine calls are currently not under the control of %DB::packages.
112 This should not be a great inconvenience in general.
113
114 The handling of evals is bad news. This is due to Perl's handling of
115 evals under the -d flag. For certain evals, caller() returns '(eval
116 n)' for the filename and for others it doesn't. For some of those
117 which it does, the array "@{'_<filename'}" contains the code of the
118 eval. For others it doesn't. Sometime, when I've an extra tuit or
119 two, I'll figure out why and how I can compensate for this.
120
121 Comments, advice and questions are welcome. If you see inefficent
122 stuff in this module and have a better way, please let me know.
123
125 Ted Ashton <ashted@southern.edu>
126
127 GraphVizProf was developed from code originally posted to usenet by
128 Philippe Verdret <philippe.verdret@sonovision-itep.fr>. Special thanks
129 to Geoffrey Broadwell <habusan2@sprynet.com> for his assistance on the
130 Win32 platform and to Philippe for his patient assistance in testing
131 and debugging.
132
133 Copyright (c) 1997 Ted Ashton
134
135 This module is free software and can be redistributed and/or modified
136 under the same terms as Perl itself.
137
139 Devel::DProf, Time::HiRes.
140
141
142
143perl v5.8.8 2004-12-02 Devel::GraphVizProf(3)