I would like to know techniques (coding, libraries, configurations) for measuring the duration of execution of CGI Perl code at various stages:
- starting up the Perl int开发者_如何转开发erpreter
- beginning running the Perl code
- loading in local Perl .pm modules for routines
- completed running the code
I'm particularly interested in 3 and 4, I don't believe there is much I can do about 1) or 2) as I wouldn't want to try to optimise the Perl interpreter, the only thing I can do here is upgrade the hardware to a faster machine and/or use mod_perl instead of classic CGI.
With 3) loading the local Perl modules I would like to measure how long it takes but I'm not sure how to code this as I don't know (or am not sure) how to get code to execute before loading these modules. If I did know, then I would record the time before they load, then record the time after they have loaded and calculate the difference.
4) should be the easiest to obtain as I would record the time (in a variable) at start of execution and then at end.
I've done a search at stackoverflow.com and found:
- How can I speed up my Perl program? - which is what I expect to be using at some point. BUT I need to prove the reduced time (i.e. speed improvement, so I need to be able to measure in the first place). The tool http://search.cpan.org/dist/Devel-NYTProf looks useful for profiling my source code but I'm not sure it covers 3) loading of modules
- Does Perl language aim at producing fast programs at runtime? - more of a verbose discussion rather than succinct answers, but a good read later when time
Google search results included:
- http://www.testingreflections.com/node/view/3622 - not enough information here
You can reduce 1) with FastCGI. It will reduce stages 2) and 3) too.
For measuring 3) you can use BEGIN blocks. Example:
use Benchmark ':hireswallclock';
my ($t0,$t1);
BEGIN {$t0 = Benchmark->new;}
use DBIx::Class;
BEGIN {$t1 = Benchmark->new;}
print "the loading took:",timestr(timediff($t1, $t0)),"\n";
Deve::NYTProf will help you with 4). Also there are specific modules like Template::Timer, CGI::Application::Plugin::DevPopup::Timing, DBIx::Class::Storage::Statistics.
In addition to FastCGI, there is also mod_perl and more importantly PSGI. With PSGI you can decouple your app from concrete webserver backend.
精彩评论