I've been profiling some code using Devel::SmallProf, and figured it would be
nice if it displayed the average time for each LoC, in a manner similar to
Devel::DProf.
SmallProf outputs lines in the form
2 0.000412 0.010000 1:The code for (eval
a b c d e
where a = the number of times the line was executed, b = the total wall
clock time for the line, c = the total cpu time, d = the line number, and e =
the code itself (or first few characters thereof).
I'd like to be able to also display b/a in context, directly after field b.
SmallProf also outputs informational lines of the form
^L ================ SmallProf version 0.9 ================
Profile of ./test.pl Page 1
=================================================================
count wall tm cpu time line
these are to be output verbatim.
My first attempt:
perl -p
@_=split;splice@_,0,2,join' ',@_[0..1],$_[1]/$_[0]if$_[0]>0;$_=join' ',@_,"\n"
for an ugly 81 characters including the -p.
which was quickly followed by
-p s#(\d)\s+([\d\.]+)#"$1 $2 ".($1>0?$2/$1:'0')#e;
for a slightly more respectable 50 characters.
Any takers?
Si.