Sam, I built a very simple general-purpose profiling tool that I use 
often for profiling database calls.
Basically, at load time it runs through the whole package tree and 
dynamically overloads methods, allowing for callback of the overloaded 
methods as well. The beauty of the system is that no original code is 
ever touched. The only thing necessary is to add "use HPDTT" at the end 
of your module loading (for example in httpd.conf under Apache).

In the case of db profiling, I tell it to overload DBI::st::execute 
with a profiling method that does the following:


my $ru1 = time;
my $result = &{"DBI::st::_overload_execute"} (@_);
my $ru2 = time;

my $sp_name = lc($DBI::lasth->{Statement});
$sp_name =~ s/exec ([^ ]+).*$/$1/iog;

open OUTFILE, ">>$profiling_log";
print OUTFILE join(",", '$thepackage$themethod', $sp_name, 
'"'.$DBI::lasth->\{Statement}.'"', sprintf('%.4f',$ru2-$ru1)."\n");
close OUTFILE;



The module is totally generic, allowing for dynamic overloading of any 
method in any package, and is perfect for mod_perl usage.
You can see from the code above that I capture the real time used for 
the execution and write to a csv file.

I also have methods that warn or profile using user time, to calculate 
the actual running cost of pure perl code. In the case of DBI, you 
can't use user time because all the time is spent outside the perl code.

Let me know if you're interested in that simple module.

Henri.

Reply via email to