Devel::SmallProf - per-line Perl profiler


        perl5 -d:SmallProf


The Devel::SmallProf is a small profiler which I find useful (or at least interesting :-) when used in conjuction with Devel::DProf. It collects statistics on the run times of the lines in the various files being run. Those statistics are placed in the file smallprof.out in one of two formats. If $DB::print_lines is false (the default), it prints:

        <num> <time> <file>:<line>

where <num> is the number of times that the line was executed, <time> is the amount of time spent executing it and <file> and <line> are the filename and line number, respectively.

If, on the other hand, $DB::print_lines is true, it print:

        <num> <time> <text>

where <num> and <time> are as above and <text> is the actual text of the executed line (read from the file).

Eval lines print <num> and <time> like the others, but also print the package, the eval number and, if possible, the text of the line. This is not affected by $DB::print_lines.

The package uses the debugging hooks in Perl and thus needs the -d switch, so to profile, use the command:

        perl5 -d:SmallProf

Once the script is done, the statistics in smallprof.out can be sorted to show which lines took the most time. The output can be sorted to find which lines take the longest, either with the sort command:

        sort -nrk 2 smallprof.out | less

or a perl script:

        @sorted = sort {(split(/\s+/,$b))[2] <=> 
                        (split(/\s+/,$a))[2]} <PROF>;
        close PROF;
        print join('',@sorted);


  • Determining the accuracy or signifiance of the results is left as an exercise for the reader. I've tried to keep the timings pretty much just to the profiled code, but no guarantees of any kind are made.

  • SmallProf depends on syscall() and gettimeofday() (see "syscall" in perlfunc) to do its timings. If your system lacks them SmallProf won't work.


The handling of evals is better than version 0.1, but still poor. For some reason, the @{'_<filename'} array for some evals is empty. When this is true, there isn't a lot that can be done.

Comments, advice and questions are welcome. If you see inefficent stuff in this module and have a better way, please let me know.


Ted Ashton <>

SmallProf was developed from code orignally posted to usenet by Philippe Verdret. I've attempted to contact him but have had no success.

Copyright (c) 1997 Ted Ashton

This module is free software and can be redistributed and/or modified under the same terms as Perl itself.


Devel::DProf, gettimeofday()