| 1 | package Dancer::Plugin::NYTProf; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use Capture::Tiny ':all'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use Dancer::Plugin; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use base 'Dancer::Plugin'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use Dancer qw(:syntax); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Dancer::FileUtils; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use File::stat; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use File::Temp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use File::Which; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 1 | our $VERSION = '0.50'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | Dancer::Plugin::NYTProf - easy Devel::NYTProf profiling for Dancer apps | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | package MyApp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | use Dancer ':syntax'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | # enables profiling and "/nytprof" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | use Dancer::Plugin::NYTProf; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | Or, if you want to enable it only under development environment (as you should!), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | you can do something like: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | package MyApp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | use Dancer ':syntax'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | # enables profiling and "/nytprof" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | if (setting('environment') eq 'development') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | eval 'use Dancer::Plugin::NYTProf'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | A plugin to provide easy profiling for Dancer applications, using the venerable | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | L<Devel::NYTProf>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | By simply loading this plugin, you'll have the detailed, helpful profiling | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | provided by Devel::NYTProf. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | Each individual request to your app is profiled. Going to the URL | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | C</nytprof> in your app will present a list of profiles; selecting one will | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | invoke C<nytprofhtml> to generate the HTML reports (unless they already exist), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | then serve them up. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | B<WARNING> This is an early version of this code which is still in development. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | In general this isn't a plugin I'd advise to use in a production environment | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | anyway, but in particular, it uses C<system> to execute C<nytprofhtml>, and I | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | need to very carefully re-examine the code to make sure that user input cannot | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | be used to nefarious effect. You are recommended to only use this in your | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | development environment. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | =head1 CONFIGURATION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | The plugin will work by default without any configuration required - it will | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | default to writing profiling data into a dir named C<profdir> within your Dancer | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | application's C<appdir>, present profiling output at C</nytprof> (not yet | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | configurable), and profile all requests. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | Below is an example of the options you can configure: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | plugins: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | NYTProf: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | enabled: 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | profiling_enabled: 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | profdir: '/tmp/profiledata' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | nytprofhtml_path: '/usr/local/bin/nytprofhtml' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | show_durations: 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | =head2 profdir | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | Where to store profiling data. Defaults to: C<$appdir/nytprof> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | =head2 nytprofhtml_path | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | Path to the C<nytprofhtml> script that comes with L<Devel::NYTProf>. Defaults to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | the first one we can find in your PATH environment. You should only need to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | change this in very specific environments, where C<nytprofhtml> can't be found by | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | this plugin. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | =head2 enabled | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | Whether the plugin as a whole is enabled; disabling this setting will disable | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | profiling route executions, and also disable the route which serves up the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | results at C</nytprof>. Enabled by default, so you only have to provide this | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | setting if you wish to set it to a false value. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | =head2 profiling_enabled | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | Whether route executions are profiled or not; if this is set to a false value, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | the before hook which would usually cause L<Devel::NYTProf> to profile that | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | route execution will not do so. This allows you to disable profiling but still | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | be able to browse the results of existing profiled executions. Enabled by | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | default, so you only have to provide this setting if you wish to set it to a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | false value. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | =head2 show_durations | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | When listing profile runs, show the duration of each run, extracted from the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | profiling data. If you have a lot of profiled runs, this might get slow, so | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | this option is provided if you don't need the profile durations displayed when | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | listing profiles, preferring a faster list. Defaults to 1. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | More configuration (such as the URL at which output is produced, and options to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | control which requests get profiled) will be added in a future version. (If | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | there's something you'd like to see soon, do contact me and let me know - it'll | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | likely get done a lot quicker then!) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 1 | my $setting = plugin_setting; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 1 | ▶ | if (!exists $setting->{enabled} || $setting->{enabled}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not exists $setting->{"enabled"} or $setting->{"enabled"}
MC/DC0%0/2
not exists $setting->{"enabled"} or $setting->{"enabled"}
not exists $setting->{"enabled"}
$setting->{"enabled"}
Truth table33%1/3
not(A) or B
A= not exists $setting->{"enabled"}B= $setting->{"enabled"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | # Work out where nytprof_html is, or die with a sensible error | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | my $nytprofhtml_path = $setting->{nytprofhtml_path} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 1 | ▶ | || File::Which::which('nytprofhtml') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$setting->{'nytprofhtml_path'} || File::Which::which('nytprofhtml')
MC/DC0%0/2
$setting->{'nytprofhtml_path'} || File::Which::which('nytprofhtml')
$setting->{'nytprofhtml_path'}
File::Which::which('nytprofhtml')
Truth table33%1/3
A || B
A= $setting->{'nytprofhtml_path'}B= File::Which::which('nytprofhtml')
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | or die "Could not find nytprofhtml script. Ensure it's in your path, " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | . "or set the nytprofhtml_path option in your config."; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | # Make sure that the directories we need to put profiling data in exist | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | # first: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 1 | ▶ | $setting->{profdir} ||= Dancer::FileUtils::path( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$setting->{"profdir"} ||= Dancer::FileUtils::path(setting("appdir"), "nytprof")
MC/DC0%0/2
$setting->{"profdir"} ||= Dancer::FileUtils::path(setting("appdir"), "nytprof")
$setting->{"profdir"}
Dancer::FileUtils::path(setting("appdir"), "nytprof")
Truth table33%1/3
A ||= B
A= $setting->{"profdir"}B= Dancer::FileUtils::path(setting("appdir"), "nytprof")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | setting('appdir'), 'nytprof' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 1 | ▶ | if (! -d $setting->{profdir}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | mkdir $setting->{profdir} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 1 | ▶ | or die "$setting->{profdir} does not exist and cannot create" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | . " - $!"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 1 | ▶ | if (!-d Dancer::FileUtils::path($setting->{profdir}, 'html')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 1 | ▶ | mkdir Dancer::FileUtils::path($setting->{profdir}, 'html') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | or die "Could not create html dir."; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | # Need to load Devel::NYTProf at runtime after setting env var, as it will | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | # insist on creating an nytprof.out file immediately - even if we tell it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | # not to start profiling. Dirty workaround: get a temp file, then let | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | # Devel::NYTProf use that, with addpid enabled so that it will append the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | # PID too (so the filename won't exist), load Devel::NYTProf, then unlink | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | # the file. This is dirty, hacky shit that needs to die, but should make | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | # things work for now. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 1 | my $tempfh = File::Temp->new; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 1 | my $file = $tempfh->filename; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 1 | $tempfh = undef; # let the file get deleted | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 1 | $ENV{NYTPROF} = "start=no:file=$file"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 1 | require Devel::NYTProf; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 1 | unlink $file; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | # Set up the hook that will start profiling each route execution. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | ▶ | hook 'before' => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | my $path = request->path; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | # Do nothing if profiling is disabled, or if we're disabled globally. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | # (Note: if we were disabled globally by the config file's enabled | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | # setting, then this hook won't have even been installed - but check | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | # anyway in order to do the expected thing if someone has modified the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | # config at runtime) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | return if ((exists $setting->{enabled} && !$setting->{enabled}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | || (exists $setting->{profiling_enabled} && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | !$setting->{profiling_enabled}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | ▶ | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/9
exists $setting->{"enabled"} and not $setting->{"enabled"} or exists $setting->{"profiling_enabled"} and not $setting->{"profiling_enabled"}
exists $setting->{"enabled"} and not $setting->{"enabled"}
exists $setting->{"profiling_enabled"} and not $setting->{"profiling_enabled"}
MC/DC0%0/4
exists $setting->{"enabled"} and not $setting->{"enabled"} or exists $setting->{"profiling_enabled"} and not $setting->{"profiling_enabled"}
exists $setting->{"enabled"}
not $setting->{"enabled"}
exists $setting->{"profiling_enabled"}
not $setting->{"profiling_enabled"}
Truth table0%0/7
A and not(B) or C and not(D)
A= exists $setting->{"enabled"}B= not $setting->{"enabled"}C= exists $setting->{"profiling_enabled"}D= not $setting->{"profiling_enabled"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | # Go no further if this request was to view profiling output: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 0 | ▶ | return if $path =~ m{^/nytprof}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | # Now, fix up the path into something we can use for a filename: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | $path =~ s{^/}{}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | $path =~ s{/}{_s_}g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 0 | $path =~ s{[^a-z0-9]}{_}gi; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | # Start profiling, and let the request continue | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | ▶ | if ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not exists $setting->{"profiling_enabled"} or $setting->{"profiling_enabled"}
MC/DC0%0/2
not exists $setting->{"profiling_enabled"} or $setting->{"profiling_enabled"}
not exists $setting->{"profiling_enabled"}
$setting->{"profiling_enabled"}
Truth table0%0/3
not(A) or B
A= not exists $setting->{"profiling_enabled"}B= $setting->{"profiling_enabled"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | !exists $setting->{profiling_enabled} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | || $setting->{profiling_enabled} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | DB::enable_profile( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | Dancer::FileUtils::path( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | $setting->{profdir}, "nytprof.out.$path.$$" | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 0 | ▶ | hook 'after' => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | ▶ | if (!exists $setting->{profiling_enabled} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not exists $setting->{"profiling_enabled"} or $setting->{"profiling_enabled"}
MC/DC0%0/2
not exists $setting->{"profiling_enabled"} or $setting->{"profiling_enabled"}
not exists $setting->{"profiling_enabled"}
$setting->{"profiling_enabled"}
Truth table0%0/3
not(A) or B
A= not exists $setting->{"profiling_enabled"}B= $setting->{"profiling_enabled"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | || $setting->{profiling_enabled}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | DB::disable_profile(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 0 | DB::finish_profile(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 0 | ▶ | get '/nytprof' => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | # First of all, if we were enabled initially, so the route got | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | # installed, but later enabled was set to a false value at runtime, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | # refuse to serve: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | ▶ | if (exists $setting->{enabled} && !$setting->{enabled}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
exists $setting->{"enabled"} and not $setting->{"enabled"}
MC/DC0%0/2
exists $setting->{"enabled"} and not $setting->{"enabled"}
exists $setting->{"enabled"}
not $setting->{"enabled"}
Truth table0%0/3
A and not(B)
A= exists $setting->{"enabled"}B= not $setting->{"enabled"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | return "Disabled via 'enabled' setting"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 0 | require Devel::NYTProf::Data; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | opendir my $dirh, $setting->{profdir} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 0 | ▶ | or die "Unable to open profiles dir $setting->{profdir} - $!"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 0 | my @files = grep { /^nytprof\.out/ } readdir $dirh; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | closedir $dirh; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | # HTML + CSS here is a bit ugly, but I want this to be usable as a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | # single-file plugin that Just Works, without needing to copy over templates | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | # / CSS etc. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | my $html = <<LISTSTART; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | <html><head><title>NYTProf profile run list</title> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | <style> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | * { font-family: Verdana, Arial, Helvetica, sans-serif; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | </style> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | </head> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | <body> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | <h1>Profile run list</h1> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | <p>Select a profile run output from the list to view the HTML reports as | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | produced by <tt>Devel::NYTProf</tt>.</p> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | <ul> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | LISTSTART | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | for my $file ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | sort { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | (stat Dancer::FileUtils::path($setting->{profdir},$b))->ctime | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | <=> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | (stat Dancer::FileUtils::path($setting->{profdir},$a))->ctime | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | } @files | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | my $fullfilepath = Dancer::FileUtils::path( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 0 | $setting->{profdir}, $file, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 0 | my $label = $file; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 0 | $label =~ s{nytprof\.out\.}{}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 0 | $label =~ s{_s_}{/}g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 0 | $label =~ s{\.(\d+)$}{}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 0 | my $pid = $1; # refactor this crap | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 0 | my $created = scalar localtime( (stat $fullfilepath)->ctime ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | # read the profile to find out the duration of the profiled request. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | # Done in an eval to catch errors (e.g. if a profile run died, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | # the data will be incomplete) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 0 | my ($profile,$duration); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | ▶ | if (!defined $setting->{show_durations} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not defined $setting->{"show_durations"} or $setting->{"show_durations"}
MC/DC0%0/2
not defined $setting->{"show_durations"} or $setting->{"show_durations"}
not defined $setting->{"show_durations"}
$setting->{"show_durations"}
Truth table0%0/3
not(A) or B
A= not defined $setting->{"show_durations"}B= $setting->{"show_durations"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | || $setting->{show_durations}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 0 | eval { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 0 | ▶ | my ($stdout, $stderr, @result) = Capture::Tiny::capture { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 0 | $profile = Devel::NYTProf::Data->new( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | { filename => $fullfilepath }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 0 | ▶ | if ($profile) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | $duration = sprintf '%.4f secs', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 0 | $profile->attributes->{profiler_duration}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 0 | $duration = '??? seconds - corrupt profile data?'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | $pid = "PID $pid"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 0 | my $url = request->uri_for("/nytprof/$file")->as_string; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | $html .= qq{<li><a href="$url"">$label</a> (} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | . join(',', grep { defined $_ } ($pid, $created, $duration)) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | . qq{)</li>}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | my $nytversion = $Devel::NYTProf::VERSION; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 0 | $html .= <<LISTEND; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | </ul> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | <p>Generated by <a href="http://github.com/bigpresh/Dancer-Plugin-NYTProf"> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | Dancer::Plugin::NYTProf</a> v$VERSION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | (using <a href="http://metacpan.org/dist/Devel::NYTProf"> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | Devel::NYTProf</a> v$nytversion)</p> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | </body> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | </html> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | LISTEND | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 0 | return $html; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | # Serve up HTML reports | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 0 | ▶ | get '/nytprof/html/**' => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | # First of all, if we were enabled initially, so the route got | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | # installed, but later enabled was set to a false value at runtime, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | # refuse to serve: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 0 | ▶ | if (exists $setting->{enabled} && !$setting->{enabled}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
exists $setting->{"enabled"} and not $setting->{"enabled"}
MC/DC0%0/2
exists $setting->{"enabled"} and not $setting->{"enabled"}
exists $setting->{"enabled"}
not $setting->{"enabled"}
Truth table0%0/3
A and not(B)
A= exists $setting->{"enabled"}B= not $setting->{"enabled"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 0 | return "Disabled via 'enabled' setting"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 0 | my ($path) = splat; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | send_file Dancer::FileUtils::path( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 0 | $setting->{profdir}, 'html', map { _safe_filename($_) } @$path | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | ), system_path => 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 0 | ▶ | get '/nytprof/:filename' => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=9 SCAR=45.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | # First of all, if we were enabled initially, so the route got | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | # installed, but later enabled was set to a false value at runtime, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | # refuse to serve: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 0 | ▶ | if (exists $setting->{enabled} && !$setting->{enabled}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
exists $setting->{"enabled"} and not $setting->{"enabled"}
MC/DC0%0/2
exists $setting->{"enabled"} and not $setting->{"enabled"}
exists $setting->{"enabled"}
not $setting->{"enabled"}
Truth table0%0/3
A and not(B)
A= exists $setting->{"enabled"}B= not $setting->{"enabled"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 0 | return "Disabled via 'enabled' setting"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | my $profiledata = Dancer::FileUtils::path( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 0 | $setting->{profdir}, _safe_filename(param('filename')) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 0 | ▶ | if (!-f $profiledata) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 0 | send_error 'not_found'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 0 | return "No such profile run found."; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | # See if we already have the HTML for this run stored; if not, invoke | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | # nytprofhtml to generate it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | # Right, do we already have generated HTML for this one? If so, use it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | my $htmldir = Dancer::FileUtils::path( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 0 | $setting->{profdir}, 'html', _safe_filename(param('filename')) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 0 | ▶ | if (! -f Dancer::FileUtils::path($htmldir, 'index.html')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | # TODO: scrutinise this very carefully to make sure it's not | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | # exploitable | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 0 | system($nytprofhtml_path, "--file=$profiledata", "--out=$htmldir"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 0 | ▶ | if ($? == -1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 0 | die "'$nytprofhtml_path' failed to execute: $!"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | } elsif ($? & 127) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 0 | ▶ | die sprintf "'%s' died with signal %d, %s coredump", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | $nytprofhtml_path,, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | ($? & 127), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | ($? & 128) ? 'with' : 'without'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | } elsif ($? != 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 0 | die sprintf "'%s' exited with value %d", | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | $nytprofhtml_path, $? >> 8; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | # Redirect off to view it: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 0 | return redirect '/nytprof/html/' | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | . param('filename') . '/index.html'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | # Rudimentary security - remove any directory traversal or poison null | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | # attempts. We're dealing with user input here, and if they're a sneaky | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | # bastard, they could convince us to send a file we shouldn't, or have | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | # nytprofhtml write its output to somewhere it shouldn't. We don't want that. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 0 | ▶ | sub _safe_filename { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_safe_filename: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 0 | my $filename = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 0 | $filename =~ s/\\//g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 0 | $filename =~ s/\0//g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 0 | $filename =~ s/\.\.//g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 0 | $filename =~ s/[\/]//g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 0 | return $filename; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | David Precious, C<< <davidp at preshweb.co.uk> >> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | =head1 ACKNOWLEDGEMENTS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | Stefan Hornburg (racke) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | Neil Hooey (nhooey) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | J. Bobby Lopez (jbobbylopez) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | leejo | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | Breno G. de Oliveira (garu) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | =head1 BUGS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | Please report any bugs or feature requests at | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | L<http://github.com/bigpresh/Dancer-Plugin-NYTProf/issues>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | =head1 CONTRIBUTING | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | This module is developed on GitHub: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | L<http://github.com/bigpresh/Dancer-Plugin-NYTProf> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | Bug reports, suggestions and pull requests all welcomed! | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | L<Dancer> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | L<Devel::NYTProf> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | L<Plack::Middleware::Debug::Profiler::NYTProf> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | =head1 LICENSE AND COPYRIGHT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | Copyright 2011-2014 David Precious. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | This program is free software; you can redistribute it and/or modify it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | under the terms of either: the GNU General Public License as published | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | by the Free Software Foundation; or the Artistic License. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | See http://dev.perl.org/licenses/ for more information. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | 1 | 1; # Sam Kington didn't like that this said "End of Dancer::Plugin::NYTProf", | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | # as it's fairly obvious. So, just for Sam's pleasure, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | # "It's the end of the world as we know it!" ... or something. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||