Next Tricks of the Wizards 188

Simple Profiler

        package Devel::Profile;
        sub DB::DB {
          my ($package, $file) = caller();
          my ($subroutine) = (caller(1))[3];
          return if $subroutine  eq '(eval)';
          $subroutine = "<$file>" unless defined $subroutine;
          ++$count{$subroutine};
        }
        END {
          for $subr (sort {$count{$b} <=> $count{$a}} (keys %count)) {
            printf STDERR "%8d %s\n", $count{$subr}, $subr;
          }
        }
     798 main::page
      66 </usr/local/bin/perldoc>
      57 Exporter::import
      49 main::check_file
      39 main::minusf_nocase
         (etc.)


Next Copyright © 2003 M. J. Dominus