After I’ve complained on #perl channel that dprofpp
(perl profiler) dies on me, I received a number of suggestions on how to profile the code without using dprofpp
. Ideas ranged from elemetary insertion of ‘print “Started”, time,”\n”‘ to all sorts of dynamic subroutine overloading. Here is one elegant solution that was suggested:
sub foo { print "foo (@_)\n" } sub bar { print "bar (@_)\n" } for (qw(foo bar)) { my $name = "main::" . $_; my $old = *$name{CODE}; *$name = sub { print scalar(localtime), " Started $name\n"; &$old; print scalar(localtime), " Finished $name\n"; }; } foo(qw(one two)); bar(qw(three four));
Oh, and someone also mentioned that dprofpp
is known to be buggy. Here is a quote from the “Profiling Perl” article at perl.com:
The other problem you might face is that
Devel::DProf
, being somewhat venerable, occasionally has problems keeping up on certain recent Perls, (particularly the 5.6.x series) and may end up segfaulting all over the place.