line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Plack::Middleware::Debug::Profiler::NYTProf; |
2
|
1
|
|
|
1
|
|
30
|
use 5.008; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
36
|
|
3
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
31
|
|
4
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
38
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
1755
|
use Plack::Util::Accessor qw(root exclude base_URL minimal no_merge_evals); |
|
1
|
|
|
|
|
279
|
|
|
1
|
|
|
|
|
7
|
|
7
|
1
|
|
|
1
|
|
10360
|
use Time::HiRes; |
|
1
|
|
|
|
|
16326
|
|
|
1
|
|
|
|
|
10
|
|
8
|
1
|
|
|
1
|
|
225
|
use File::Path qw(make_path); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
103
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
1832
|
use parent 'Plack::Middleware::Debug::Base'; |
|
1
|
|
|
|
|
555
|
|
|
1
|
|
|
|
|
17
|
|
11
|
|
|
|
|
|
|
our $VERSION = '0.06'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub prepare_app { |
14
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
15
|
0
|
|
0
|
|
|
|
$self->root($self->root || '/tmp'); |
16
|
0
|
|
0
|
|
|
|
$self->base_URL($self->base_URL || ''); |
17
|
0
|
|
0
|
|
|
|
$self->minimal($self->minimal || '0'); |
18
|
0
|
|
0
|
|
|
|
$self->no_merge_evals($self->no_merge_evals || '0'); |
19
|
0
|
|
|
|
|
|
$self->{files} = Plack::App::File->new(root => $self->root); |
20
|
|
|
|
|
|
|
|
21
|
0
|
0
|
|
|
|
|
unless(-d $self->root){ |
22
|
0
|
0
|
|
|
|
|
make_path($self->root) or die "Cannot create directory " . $self->root; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# start=begin - start immediately (the default) |
26
|
|
|
|
|
|
|
# start=init - start at beginning of INIT phase (after compilation) |
27
|
|
|
|
|
|
|
# start=end - start at beginning of END phase |
28
|
|
|
|
|
|
|
# start=no - don't automatically start |
29
|
0
|
|
0
|
|
|
|
$ENV{NYTPROF} ||= "addpid=1:start=begin:file=".$self->root."/nytprof.null.out"; |
30
|
0
|
|
|
|
|
|
require Devel::NYTProf::Core; |
31
|
0
|
|
|
|
|
|
require Devel::NYTProf; |
32
|
|
|
|
|
|
|
|
33
|
0
|
|
0
|
|
|
|
$self->exclude($self->exclude || [qw(.*\.css .*\.png .*\.ico .*\.js)]); |
34
|
0
|
0
|
|
|
|
|
Carp::croak "exclude not an array" if ref($self->exclude) ne 'ARRAY'; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub call { |
38
|
0
|
|
|
0
|
1
|
|
my($self, $env) = @_; |
39
|
0
|
|
|
|
|
|
my $panel = $self->default_panel; |
40
|
|
|
|
|
|
|
|
41
|
0
|
0
|
|
|
|
|
if ($env->{PATH_INFO} =~ m!nytprofhtml!) { |
42
|
0
|
|
|
|
|
|
$env->{'plack.debug.disabled'} = 1; |
43
|
0
|
|
|
|
|
|
return $self->{files}->call($env); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
|
foreach my $pattern (@{$self->exclude}) { |
|
0
|
|
|
|
|
|
|
47
|
0
|
0
|
|
|
|
|
if ($env->{PATH_INFO} =~ m!^$pattern$!) { |
48
|
0
|
|
|
|
|
|
return $self->SUPER::call($env); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
# $ENV{NYTPROF}'s addpid=1 will append ".$$" to the file |
53
|
0
|
|
|
|
|
|
DB::enable_profile($self->root."/nytprof.out"); |
54
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
my $res = $self->SUPER::call($env); |
56
|
0
|
|
|
|
|
|
DB::disable_profile(); |
57
|
0
|
|
|
|
|
|
DB::enable_profile($self->root."/nytprof.null.out"); |
58
|
0
|
|
|
|
|
|
DB::disable_profile(); |
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
$self->report($env); |
61
|
0
|
|
|
|
|
|
return $res; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub run { |
65
|
0
|
|
|
0
|
1
|
|
my($self, $env, $panel) = @_; |
66
|
|
|
|
|
|
|
return sub { |
67
|
0
|
|
|
0
|
|
|
my $res = shift; |
68
|
0
|
0
|
|
|
|
|
$panel->nav_subtitle(join ', ', 'OK', ( $self->minimal ? 'Minimal' : () )); |
69
|
0
|
|
|
|
|
|
$panel->content('(open in a new window) |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
Your browser does not support iframes. |
72
|
|
|
|
|
|
|
'); |
73
|
0
|
|
|
|
|
|
}; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub report { |
77
|
0
|
|
|
0
|
0
|
|
my ( $self, $env ) = @_; |
78
|
0
|
0
|
|
|
|
|
if ( -f $self->root . "/nytprof.out.$$" ) { |
79
|
0
|
0
|
|
|
|
|
system "nytprofhtml" |
|
|
0
|
|
|
|
|
|
80
|
|
|
|
|
|
|
, ( $self->minimal ? '--minimal' : () ) |
81
|
|
|
|
|
|
|
, ( $self->no_merge_evals ? '--no-mergeevals' : () ) |
82
|
|
|
|
|
|
|
, "-f", $self->root . "/nytprof.out.$$" |
83
|
|
|
|
|
|
|
, "-o", $self->root . "/nytprofhtml.$$"; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub DESTROY { |
88
|
0
|
|
|
0
|
|
|
DB::finish_profile(); |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
1; |
92
|
|
|
|
|
|
|
__END__ |