Perl/Profiling: Difference between revisions
From charlesreid1
| Line 50: | Line 50: | ||
==Running with NYTProf== | ==Running with NYTProf== | ||
After installing it, run a Perl script with the NYTProf module turned on: | |||
<pre> | <pre> | ||
perl -d:NYTProf myscript.pl | perl -d:NYTProf myscript.pl | ||
</pre> | |||
This results in an incomprehensible nytprof.out file. | |||
Some tools: | |||
* nytprofcsv - export as csv file | |||
* nytprofcfg - generates nytprof.callgraph | |||
* nytprofhtml - generate html version | |||
<pre> | |||
/usr/local/Cellar/perl/5.24.0_1/bin/nytprofhtml | |||
</pre> | </pre> | ||
Revision as of 04:42, 19 March 2017
TLDR: Use Devel::NYTProf
How to profile Perl
Before you begin
Installing cpanm
Start by installing cpanm to take care of all your Perl packages:
brew install cpanm
Installing NYTProf
Install the best Perl profiling tool out there, the NYTProf, originally written by Adam Kaplan at the New York Times: https://www.perl.org/about/whitepapers/perl-profiling.html
cpanm Devel::NYTProf
This also installs the dependencies, of which there are multiple: https://metacpan.org/pod/Devel::NYTProf
Profiling Code using the NYTProf
Normally, we can time code using the time function, which gives a really high-level description of how long the code took to do stuff. Like, "this much user time, this much real wall time." Here's an example of output from the time command:
************************************** Running 8 queens problem with Perl... total 92 solutions real 0m0.112s user 0m0.025s sys 0m0.008s ************************************** Running 12 queens problem with Perl... total 14200 solutions real 0m11.726s user 0m11.519s sys 0m0.032s
We want to get a more detailed description of what's going on with the code to find bottlenecks.
Running with NYTProf
After installing it, run a Perl script with the NYTProf module turned on:
perl -d:NYTProf myscript.pl
This results in an incomprehensible nytprof.out file.
Some tools:
- nytprofcsv - export as csv file
- nytprofcfg - generates nytprof.callgraph
- nytprofhtml - generate html version
/usr/local/Cellar/perl/5.24.0_1/bin/nytprofhtml
Resources
NYTProf
Official package info (some documentation, but nothing high-level at all): https://metacpan.org/pod/Devel::NYTProf
Slide deck explaining a bit more about how to use NYTProf: www.slideshare.net/Tim.Bunce/develnytprof-200907