I’ve been doing some scripting in perl lately. I’ve been writing a script that generates a slew of data files and it was running really slow. I wanted to find out the bottleneck. Fortunately for me, Perl includes a nice high-level profiler. Here’s how to use it.
First run your script using the -d:dProf option:
bash-4.1$ perl -d:dProf myScript.pl
This generates a tmon.out file that contains the profile information.
Next run the dprofpp command:
bash-4.1$ perl dprofpp -u
This generates a usage report like this:
Exporter::export has -2 unstacked calls in outer
Exporter::Heavy::heavy_export has 2 unstacked calls in outer
Total Elapsed Time = 0.168504 Seconds
User Time = 0.122504 Seconds Exclusive
Times %Time ExclSec CumulS #Calls sec/call Csec/c Name
13.0 0.016 0.016 3 0.0053 0.0053 vars::BEGIN
13.0 0.016 0.016 5 0.0032 0.0031 IO::Seekable::BEGIN
13.0 0.016 0.032 7 0.0023 0.0045 IO::File::BEGIN
13.0 0.016 0.016 1 0.0159 0.0158 main::parseConfigFile
12.2 0.015 0.015 2 0.0075 0.0075 Exporter::as_heavy
12.2 0.015 0.015 3 0.0050 0.0050 File::Bsename::BEGIN
0.00 0.000 0.000 2 0.0000 0.0000 Exporter::Heavy::heavy_export
0.00 - -0.000 1 - - Fcntl::BEGIN
... etc
From there it’s pretty easy to figure out what’s happening. There are a lot of cool options to the dprofpp command. Check them out with the -h option.
Happy scripting!