bigpresh / dancer-plugin-nytprof Goto Github PK
View Code? Open in Web Editor NEWDancer plugin to profile Dancer apps with Devel::NYTProf
Home Page: http://search.cpan.org/dist/Dancer-Plugin-NYTProf
Dancer plugin to profile Dancer apps with Devel::NYTProf
Home Page: http://search.cpan.org/dist/Dancer-Plugin-NYTProf
NAME Dancer::Plugin::NYTProf - easy Devel::NYTProf profiling for Dancer apps SYNOPSIS package MyApp; use Dancer ':syntax'; # enables profiling and "/nytprof" use Dancer::Plugin::NYTProf; Or, if you want to enable it only under development environment (as you should!), you can do something like: package MyApp; use Dancer ':syntax'; # enables profiling and "/nytprof" if (setting('environment') eq 'development') { eval 'use Dancer::Plugin::NYTProf'; } DESCRIPTION A plugin to provide easy profiling for Dancer applications, using the venerable Devel::NYTProf. By simply loading this plugin, you'll have the detailed, helpful profiling provided by Devel::NYTProf. Each individual request to your app is profiled. Going to the URL `/nytprof' in your app will present a list of profiles; selecting one will invoke `nytprofhtml' to generate the HTML reports (unless they already exist), then serve them up. WARNING This is an early version of this code which is still in development. In general this isn't a plugin I'd advise to use in a production environment anyway, but in particular, it uses `system' to execute `nytprofhtml', and I need to very carefully re-examine the code to make sure that user input cannot be used to nefarious effect. You are recommended to only use this in your development environment. CONFIGURATION The plugin will work by default without any configuration required - it will default to writing profiling data into a dir named `profdir' within your Dancer application's `appdir', present profiling output at `/nytprof' (not yet configurable), and profile all requests. Below is an example of the options you can configure: plugins: NYTProf: enabled: 1 profdir: '/tmp/profiledata' nytprofhtml_path: '/usr/local/bin/nytprofhtml' show_durations: 1 profdir Where to store profiling data. Defaults to: `$appdir/nytprof' nytprofhtml_path Path to the `nytprofhtml' script that comes with Devel::NYTProf. Defaults to the first one we can find in your PATH environment. You should only need to change this in very specific environments, where `nytprofhtml' can't be found by this plugin. enabled Profiling comes with a penalty, and even in development environments you might want to enable/disable it via configuration file. This lets you do so. You can toggle this plugin by setting the `enabled' option to 0 or 1. It is, of course, enabled by default. More configuration (such as the URL at which output is produced, and options to control which requests get profiled) will be added in a future version. (If there's something you'd like to see soon, do contact me and let me know - it'll likely get done a lot quicker then!) show_durations When listing profile runs, show the duration of each run, extracted from the profiling data. If you have a lot of profiled runs, this might get slow, so this option is provided if you don't need the profile durations displayed when listing profiles, preferring a faster list. Defaults to 1. AUTHOR David Precious, `<davidp at preshweb.co.uk>' ACKNOWLEDGEMENTS Stefan Hornburg (racke) Neil Hooey (nhooey) J. Bobby Lopez (jbobbylopez) leejo Breno G. de Oliveira (garu) BUGS Please report any bugs or feature requests at http://github.com/bigpresh/Dancer-Plugin-NYTProf/issues. CONTRIBUTING This module is developed on GitHub: http://github.com/bigpresh/Dancer-Plugin-NYTProf Bug reports, suggestions and pull requests all welcomed! SEE ALSO Dancer Devel::NYTProf Plack::Middleware::Debug::Profiler::NYTProf LICENSE AND COPYRIGHT Copyright 2011-2014 David Precious. This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License. See http://dev.perl.org/licenses/ for more information.
I tried to enable this plugin using the "config" method, as described in the POD, but it did not work. /nytprof gave a 404 and no data was gathered in the directory indicated by the "profdir" setting.
Including "use Dancer::Plugin::NYTProf;" in the app itself (as described here: http://advent.perldancer.org/2011/9) did work.
Tested with Dancer 1.311 on Ubuntu 12.04, and uptodate modules from CPAN.
My dancer application has an application path of 'app' (in apache config), so http://host:port/app/ is a request for '/'. The generated nytprof files are correctly placed in /app/nytprof, but the index contains links to /nytprof/module instead of /app/nytprof/module (where the html files really are).
With Dancer-Plugin-NYTProf-0.40:
# Failed test 'Pod coverage on Dancer::Plugin::NYTProf'
# at /opt/perl-5.10.1/lib/site_perl/5.10.1/Test/Pod/Coverage.pm line 133.
# Dancer::Plugin::NYTProf: requiring 'Dancer::Plugin::NYTProf' failed
# Looks like you failed 1 test of 1.
t/pod-coverage.t ..
blopez$ perl bin/app.pl
Could not find nytprofhtml script. Ensure it's in your path, or set the nytprofhtml_path option in your config. at /opt/local/lib/perl5/site_perl/5.12.4/Dancer/Plugin/NYTProf.pm line 64.
Compilation failed in require at /App/lib/App.pm line 11.
BEGIN failed--compilation aborted at /App/lib/App.pm line 11.
Compilation failed in require at bin/app.pl line 4.
BEGIN failed--compilation aborted at bin/app.pl line 4.
blopez$ export PATH="$PATH:/opt/local/libexec/perl5.12/sitebin/"
blopez$ perl bin/app.pl
Segmentation fault: 11
blopez$
I tried using placing the nytprofhtml configuration in config.yml according the instructions on the github wiki, but that didn't do anything (didn't work, and no warnings/errors).
Let me know if there's anything else I can check to help out.
Directory structure for stuff NYTProf related:
/opt/local/lib/perl5/site_perl/5.12.4/Dancer/Plugin/NYTProf.pm
/opt/local/lib/perl5/site_perl/5.12.4/darwin-thread-multi-2level/auto/Dancer/Plugin/NYTProf
/opt/local/lib/perl5/site_perl/5.12.4/darwin-thread-multi-2level/auto/Dancer/Plugin/NYTProf/.packlist
/opt/local/lib/perl5/site_perl/5.12.4/darwin-thread-multi-2level/auto/Devel/NYTProf
/opt/local/lib/perl5/site_perl/5.12.4/darwin-thread-multi-2level/auto/Devel/NYTProf/.packlist
/opt/local/lib/perl5/site_perl/5.12.4/darwin-thread-multi-2level/auto/Devel/NYTProf/NYTProf.bs
/opt/local/lib/perl5/site_perl/5.12.4/darwin-thread-multi-2level/auto/Devel/NYTProf/NYTProf.bundle
/opt/local/lib/perl5/site_perl/5.12.4/darwin-thread-multi-2level/Devel/auto/Devel/NYTProf
/opt/local/lib/perl5/site_perl/5.12.4/darwin-thread-multi-2level/Devel/auto/Devel/NYTProf/NYTProf.bundle
/opt/local/lib/perl5/site_perl/5.12.4/darwin-thread-multi-2level/Devel/NYTProf
/opt/local/lib/perl5/site_perl/5.12.4/darwin-thread-multi-2level/Devel/NYTProf/Apache.pm
/opt/local/lib/perl5/site_perl/5.12.4/darwin-thread-multi-2level/Devel/NYTProf/Constants.pm
/opt/local/lib/perl5/site_perl/5.12.4/darwin-thread-multi-2level/Devel/NYTProf/Core.pm
/opt/local/lib/perl5/site_perl/5.12.4/darwin-thread-multi-2level/Devel/NYTProf/Data.pm
/opt/local/lib/perl5/site_perl/5.12.4/darwin-thread-multi-2level/Devel/NYTProf/FileHandle.pm
/opt/local/lib/perl5/site_perl/5.12.4/darwin-thread-multi-2level/Devel/NYTProf/FileInfo.pm
/opt/local/lib/perl5/site_perl/5.12.4/darwin-thread-multi-2level/Devel/NYTProf/js
/opt/local/lib/perl5/site_perl/5.12.4/darwin-thread-multi-2level/Devel/NYTProf/js/asc.png
/opt/local/lib/perl5/site_perl/5.12.4/darwin-thread-multi-2level/Devel/NYTProf/js/bg.png
/opt/local/lib/perl5/site_perl/5.12.4/darwin-thread-multi-2level/Devel/NYTProf/js/desc.png
/opt/local/lib/perl5/site_perl/5.12.4/darwin-thread-multi-2level/Devel/NYTProf/js/jit
/opt/local/lib/perl5/site_perl/5.12.4/darwin-thread-multi-2level/Devel/NYTProf/js/jit/gradient-cushion1.png
/opt/local/lib/perl5/site_perl/5.12.4/darwin-thread-multi-2level/Devel/NYTProf/js/jit/gradient.png
/opt/local/lib/perl5/site_perl/5.12.4/darwin-thread-multi-2level/Devel/NYTProf/js/jit/gradient20.png
/opt/local/lib/perl5/site_perl/5.12.4/darwin-thread-multi-2level/Devel/NYTProf/js/jit/gradient30.png
/opt/local/lib/perl5/site_perl/5.12.4/darwin-thread-multi-2level/Devel/NYTProf/js/jit/gradient40.png
/opt/local/lib/perl5/site_perl/5.12.4/darwin-thread-multi-2level/Devel/NYTProf/js/jit/gradient50.png
/opt/local/lib/perl5/site_perl/5.12.4/darwin-thread-multi-2level/Devel/NYTProf/js/jit/jit-yc.js
/opt/local/lib/perl5/site_perl/5.12.4/darwin-thread-multi-2level/Devel/NYTProf/js/jit/jit.js
/opt/local/lib/perl5/site_perl/5.12.4/darwin-thread-multi-2level/Devel/NYTProf/js/jit/Treemap.css
/opt/local/lib/perl5/site_perl/5.12.4/darwin-thread-multi-2level/Devel/NYTProf/js/jquery-min.js
/opt/local/lib/perl5/site_perl/5.12.4/darwin-thread-multi-2level/Devel/NYTProf/js/jquery-tablesorter-min.js
/opt/local/lib/perl5/site_perl/5.12.4/darwin-thread-multi-2level/Devel/NYTProf/js/style-tablesorter.css
/opt/local/lib/perl5/site_perl/5.12.4/darwin-thread-multi-2level/Devel/NYTProf/Reader.pm
/opt/local/lib/perl5/site_perl/5.12.4/darwin-thread-multi-2level/Devel/NYTProf/ReadStream.pm
/opt/local/lib/perl5/site_perl/5.12.4/darwin-thread-multi-2level/Devel/NYTProf/Run.pm
/opt/local/lib/perl5/site_perl/5.12.4/darwin-thread-multi-2level/Devel/NYTProf/SubInfo.pm
/opt/local/lib/perl5/site_perl/5.12.4/darwin-thread-multi-2level/Devel/NYTProf/Test.pm
/opt/local/lib/perl5/site_perl/5.12.4/darwin-thread-multi-2level/Devel/NYTProf/Util.pm
/opt/local/lib/perl5/site_perl/5.12.4/darwin-thread-multi-2level/Devel/NYTProf.pm
/opt/local/libexec/perl5.12/sitebin/nytprofcg
/opt/local/libexec/perl5.12/sitebin/nytprofcsv
/opt/local/libexec/perl5.12/sitebin/nytprofhtml
/opt/local/libexec/perl5.12/sitebin/nytprofmerge
/opt/local/share/perl5.12/siteman/man1/nytprofcg.1
/opt/local/share/perl5.12/siteman/man1/nytprofcsv.1
/opt/local/share/perl5.12/siteman/man1/nytprofhtml.1
/opt/local/share/perl5.12/siteman/man1/nytprofmerge.1
/opt/local/share/perl5.12/siteman/man3/Dancer::Plugin::NYTProf.3pm
/opt/local/share/perl5.12/siteman/man3/Devel::NYTProf.3pm
/opt/local/share/perl5.12/siteman/man3/Devel::NYTProf::Apache.3pm
/opt/local/share/perl5.12/siteman/man3/Devel::NYTProf::Core.3pm
/opt/local/share/perl5.12/siteman/man3/Devel::NYTProf::Data.3pm
/opt/local/share/perl5.12/siteman/man3/Devel::NYTProf::FileInfo.3pm
/opt/local/share/perl5.12/siteman/man3/Devel::NYTProf::ReadStream.3pm
/opt/local/share/perl5.12/siteman/man3/Devel::NYTProf::Run.3pm
/opt/local/share/perl5.12/siteman/man3/Devel::NYTProf::Util.3pm
Right now the "nytprof.out" file gets written to the current working directory from where the Dancer application is run.
Could you make an option to configure where the file is written, or have it written to that other profile directory in the configuration?
Hey there, thanks for your great work on this plugin :).
Some weird stuff happens when I try to profile the /
endpoint of my app (which happens to be the main endpoint, so I basically can't use the plugin lol). Check it out:
<ul>
<li><a href="URL/nytprof/nytprof.out..24" "=""></a> (PID 24,Fri May 27 19:24:01 2022,0.2409 secs)</li>
<li><a href="URL/nytprof/nytprof.out.checkstatus.25" "="">checkstatus</a> (PID 25,Fri May 27 19:20:41 2022,0.0092 secs)</li>
<li><a href="URL/nytprof/nytprof.out.swag.28" "="">swag</a> (PID 28,Fri May 27 19:20:36 2022,0.0004 secs)</li>
</ul>
I believe that can be attributed to this line: $path =~ s{^/}{};
.
Now that I'm looking at the HTML there seem to be some other issues too. E.g. <a href="URL/nytprof/nytprof.out.checkstatus.25" "="">
, not sure what's going on there...
I don't know what the best way to fix this would be, maybe replacing a path consisting only of a /
with root
? Seems hacky, I don't know if there's any sentinel value we can use that wouldn't conflict with possible endpoint names.
After figuring out the problem reported as #13, going to /nytprof in a browser (Firefox 21 on Ubuntu 12.04) displayed this, directly in the browser:
Reading /home/magnus/scripts/Ebooksforlib/nytprof/nytprof.out.creator_s_11.27701
Processing /home/magnus/scripts/Ebooksforlib/nytprof/nytprof.out.creator_s_11.27701 data
Reading /home/magnus/scripts/Ebooksforlib/nytprof/nytprof.out.book_s_9.27701
Processing /home/magnus/scripts/Ebooksforlib/nytprof/nytprof.out.book_s_9.27701 data
Reading /home/magnus/scripts/Ebooksforlib/nytprof/nytprof.out.creator_s_10.27701
Processing /home/magnus/scripts/Ebooksforlib/nytprof/nytprof.out.creator_s_10.27701 data
Reading /home/magnus/scripts/Ebooksforlib/nytprof/nytprof.out.book_s_12.27701
Processing /home/magnus/scripts/Ebooksforlib/nytprof/nytprof.out.book_s_12.27701 data
Reading /home/magnus/scripts/Ebooksforlib/nytprof/nytprof.out..27701
Processing /home/magnus/scripts/Ebooksforlib/nytprof/nytprof.out..27701 data
Reading /home/magnus/scripts/Ebooksforlib/nytprof/nytprof.out.library_s_set_s_2.27701
Processing /home/magnus/scripts/Ebooksforlib/nytprof/nytprof.out.library_s_set_s_2.27701 data
Reading /home/magnus/scripts/Ebooksforlib/nytprof/nytprof.out.book_s_1.27701
Processing /home/magnus/scripts/Ebooksforlib/nytprof/nytprof.out.book_s_1.27701 data
Reading /home/magnus/scripts/Ebooksforlib/nytprof/nytprof.out.library_s_choose.27701
Processing /home/magnus/scripts/Ebooksforlib/nytprof/nytprof.out.library_s_choose.27701 data
HTTP/1.0 200 OK
Server: Perl Dancer 1.311
Content-Length: 1567
Content-Type: text/html; charset=utf-8
Set-Cookie: dancer.session=94729453110568340886508926857159539; path=/; domain=localhost; HttpOnly
X-Powered-By: Perl Dancer 1.311
Select a profile run output from the list to view the HTML reports as produced by Devel::NYTProf.
Generated by Dancer::Plugin::NYTProf v0.31
Copying and pasting one of the URLs indicated, like e.g. http://localhost:3000/nytprof/nytprof.out.library_s_choose.27701, does give the expected output.
At the bottom of my lib/MyApp.pm I do have line that says:
set serializer => 'JSON';
Not sure if that might be relevant?
*** Installing Dancer::Plugin::NYTProf...
Running [/usr/bin/perl -e use strict; BEGIN { my $old = select STDERR; $|++; select $old; $|++; $0 = shift(@ARGV); my $rv = do($0); die $@ if $@; } /home/ambs/.cpanplus/5.10.0/build/Dancer-Plugin-NYTProf-0.03/Makefile.PL]...
Writing Makefile for Dancer::Plugin::NYTProf
Writing MYMETA.yml and MYMETA.json
Running [/usr/bin/make test UNINST=1]...
make[1]: Entering directory `/home/ambs/.cpanplus/5.10.0/build/Dancer-Plugin-NYTProf-0.03'
PERL_DL_NONLAZY=1 /usr/bin/perl "-MExtUtils::Command::MM" "-e" "test_harness(0, 'blib/lib', 'blib/arch')" t/*.t
Bailout called. Further testing stopped:
# Failed test 'use Dancer::Plugin::NYTProf;'
# at t/00-load.t line 6.
# Tried to use 'Dancer::Plugin::NYTProf'.
# Error: Insecure dependency in require while running with -T switch at /usr/lib/perl5/site_perl/5.10.0/Time/HiRes.pm line 43.
# BEGIN failed--compilation aborted at /usr/lib/perl5/site_perl/5.10.0/Time/HiRes.pm line 43.
# Compilation failed in require at /usr/share/perl5/site_perl/5.10.0/Dancer/Timer.pm line 6.
# BEGIN failed--compilation aborted at /usr/share/perl5/site_perl/5.10.0/Dancer/Timer.pm line 6.
# Compilation failed in require at /usr/share/perl5/site_perl/5.10.0/Dancer/SharedData.pm line 5.
# BEGIN failed--compilation aborted at /usr/share/perl5/site_perl/5.10.0/Dancer/SharedData.pm line 5.
# Compilation failed in require at /usr/share/perl5/site_perl/5.10.0/Dancer/Request.pm line 11.
# BEGIN failed--compilation aborted at /usr/share/perl5/site_perl/5.10.0/Dancer/Request.pm line 11.
# Compilation failed in require at /usr/share/perl5/site_perl/5.10.0/Dancer/Route.pm line 11.
# BEGIN failed--compilation aborted at /usr/share/perl5/site_perl/5.10.0/Dancer/Route.pm line 11.
# Compilation failed in require at /usr/share/perl5/site_perl/5.10.0/Dancer/Route/Registry.pm line 5.
# BEGIN failed--compilation aborted at /usr/share/perl5/site_perl/5.10.0/Dancer/Route/Registry.pm line 5.
# Compilation failed in require at /usr/share/perl5/site_perl/5.10.0/Dancer/App.pm line 10.
# BEGIN failed--compilation aborted at /usr/share/perl5/site_perl/5.10.0/Dancer/App.pm line 10.
# Compilation failed in require at /usr/share/perl5/site_perl/5.10.0/Dancer.pm line 11.
# BEGIN failed--compilation aborted at /usr/share/perl5/site_perl/5.10.0/Dancer.pm line 11.
# Compilation failed in require at /home/ambs/.cpanplus/5.10.0/build/Dancer-Plugin-NYTProf-0.03/blib/lib/Dancer/Plugin/NYTProf.pm line 8.
# BEGIN failed--compilation aborted at /home/ambs/.cpanplus/5.10.0/build/Dancer-Plugin-NYTProf-0.03/blib/lib/Dancer/Plugin/NYTProf.pm line 8.
# Compilation failed in require at (eval 4) line 2.
# BEGIN failed--compilation aborted at (eval 4) line 2.
Use of uninitialized value $Dancer::Plugin::NYTProf::VERSION in concatenation (.) or string at t/00-load.t line 10.
# Testing Dancer::Plugin::NYTProf , Perl 5.010000, /usr/bin/perl
# Looks like you failed 1 test of 1.
FAILED--Further testing stopped.
make[1]: *** [test_dynamic] Error 1
make[1]: Leaving directory `/home/ambs/.cpanplus/5.10.0/build/Dancer-Plugin-NYTProf-0.03'
[ERROR] Unable to create a new distribution object for 'Dancer::Plugin::NYTProf' -- cannot continue
DBI::st::execute is listed on the index page as an expensive subroutine, but the link for this subroutine is of this form:
Dancer-Plugin-NYTProf-pm-1-line.html#DBI__st__execute
Which takes me to the Dancer::Plugin::NYTProf profiling page. Because there's no anchor matching DBI__st__execute on that page, I see the top of the page. Naturally there's no 'DBI::st::execute' sub in the Dancer::Plugin::NYTProf package.
in line 159, the code has <a href="/nytprof..." instead it would be better to have <a href=".request->uri_base().q{/nytprof...}
so for those apps mounted in different path will work without any change in the url.
Thanks,
Mopi.
Hello David
small mistake
in your doc you indicate
plugins:
NYTProf:
profdir: '/tmp/profiledata'
nytprofhtmlpath: '/usr/local/bin/nytprofhtml'
but in your code /usr/local/share/perl5/Dancer/Plugin/NYTProf.pm line 64
your code waitting my $nytprofhtml_path = $setting->{nytprofhtml_path} with a underscore.
I've upate my setting to
nytprofhtml_path: '/usr/local/bin/nytprofhtml'
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.