line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Plack::Middleware::Profiler::KYTProf; |
2
|
4
|
|
|
4
|
|
2387
|
use strict; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
143
|
|
3
|
4
|
|
|
4
|
|
20
|
use warnings; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
127
|
|
4
|
4
|
|
|
4
|
|
4415
|
use parent qw(Plack::Middleware); |
|
4
|
|
|
|
|
1917
|
|
|
4
|
|
|
|
|
26
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.08'; |
6
|
|
|
|
|
|
|
|
7
|
4
|
|
|
|
|
27
|
use Plack::Util::Accessor qw( |
8
|
|
|
|
|
|
|
namespace_regex |
9
|
|
|
|
|
|
|
ignore_class_regex |
10
|
|
|
|
|
|
|
context_classes_regex |
11
|
|
|
|
|
|
|
logger |
12
|
|
|
|
|
|
|
threshold |
13
|
|
|
|
|
|
|
remove_linefeed |
14
|
|
|
|
|
|
|
profiles |
15
|
|
|
|
|
|
|
mutes |
16
|
|
|
|
|
|
|
enable_profile_if |
17
|
4
|
|
|
4
|
|
126443
|
); |
|
4
|
|
|
|
|
10
|
|
18
|
4
|
|
|
4
|
|
13689
|
use Module::Load qw(load); |
|
4
|
|
|
|
|
11437
|
|
|
4
|
|
|
|
|
35
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
my %PROFILER_SETUPED; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub prepare_app { |
23
|
3
|
|
|
3
|
1
|
239
|
my $self = shift; |
24
|
|
|
|
|
|
|
|
25
|
3
|
|
|
|
|
70
|
$self->_setup_enable_profile_if; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub _setup_enable_profile_if { |
29
|
3
|
|
|
3
|
|
15
|
my $self = shift; |
30
|
3
|
50
|
|
3
|
|
27
|
$self->enable_profile_if( sub {1} ) unless $self->enable_profile_if; |
|
3
|
|
|
|
|
29
|
|
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub _setup_profiler_if_needed { |
34
|
3
|
|
|
3
|
|
9
|
my ( $self, $env ) = @_; |
35
|
|
|
|
|
|
|
|
36
|
3
|
|
|
|
|
14
|
my $pid = $$; |
37
|
3
|
50
|
|
|
|
19
|
return if $PROFILER_SETUPED{$pid}; |
38
|
3
|
|
|
|
|
12
|
$PROFILER_SETUPED{$pid} = 1; |
39
|
|
|
|
|
|
|
|
40
|
3
|
|
|
|
|
22
|
my $is_profiler_enabled = $self->enable_profile_if->($env); |
41
|
3
|
50
|
|
|
|
18
|
return unless $is_profiler_enabled; |
42
|
|
|
|
|
|
|
|
43
|
3
|
|
|
|
|
19
|
$self->_setup_profiler; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub _setup_profiler { |
47
|
3
|
|
|
3
|
|
9
|
my $self = shift; |
48
|
|
|
|
|
|
|
|
49
|
3
|
|
|
|
|
16
|
$self->_load_kytprof; |
50
|
3
|
|
|
|
|
22
|
$self->_set_kytprof_options; |
51
|
3
|
|
|
|
|
29
|
$self->_load_profiles; |
52
|
3
|
|
|
|
|
719
|
$self->_diable_module_profiling; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub _load_kytprof { |
56
|
3
|
|
|
3
|
|
7
|
my $self = shift; |
57
|
3
|
|
|
|
|
18
|
$self->_load_module('Devel::KYTProf'); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub _set_kytprof_options { |
61
|
3
|
|
|
3
|
|
9
|
my $self = shift; |
62
|
3
|
50
|
|
|
|
23
|
Devel::KYTProf->namespace_regex( $self->namespace_regex ) |
63
|
|
|
|
|
|
|
if $self->namespace_regex; |
64
|
3
|
50
|
|
|
|
365
|
Devel::KYTProf->ignore_class_regex( $self->ignore_class_regex ) |
65
|
|
|
|
|
|
|
if $self->ignore_class_regex; |
66
|
3
|
50
|
|
|
|
33
|
Devel::KYTProf->context_classes_regex( $self->context_classes_regex ) |
67
|
|
|
|
|
|
|
if $self->context_classes_regex; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
# TODO Should we create logger adapter for popular logging framework? |
70
|
3
|
50
|
|
|
|
35
|
Devel::KYTProf->logger( $self->logger ) if $self->logger; |
71
|
3
|
100
|
|
|
|
31
|
Devel::KYTProf->threshold( $self->threshold ) if $self->threshold; |
72
|
3
|
50
|
|
|
|
46
|
Devel::KYTProf->remove_linefeed( $self->remove_linefeed ) |
73
|
|
|
|
|
|
|
if $self->remove_linefeed; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub _diable_module_profiling { |
77
|
3
|
|
|
3
|
|
8
|
my $self = shift; |
78
|
3
|
50
|
|
|
|
9
|
foreach my $module ( keys %{ $self->mutes || {} } ) { |
|
3
|
|
|
|
|
19
|
|
79
|
0
|
|
|
|
|
0
|
my $method = $self->mutes->{$module}; |
80
|
0
|
|
|
|
|
0
|
Devel::KYTProf->mute( $module, $method ); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub _load_profiles { |
85
|
3
|
|
|
3
|
|
9
|
my $self = shift; |
86
|
|
|
|
|
|
|
|
87
|
3
|
|
66
|
|
|
28
|
my $profiles ||= $self->profiles; |
88
|
3
|
|
100
|
|
|
35
|
$profiles ||= [ |
89
|
|
|
|
|
|
|
'Plack::Middleware::Profiler::KYTProf::Profile::TemplateEngine', |
90
|
|
|
|
|
|
|
'Plack::Middleware::Profiler::KYTProf::Profile::KVS' |
91
|
|
|
|
|
|
|
]; |
92
|
3
|
|
|
|
|
12
|
foreach my $profile (@$profiles) { |
93
|
4
|
|
|
|
|
747
|
$self->_load_module($profile); |
94
|
4
|
50
|
|
|
|
82
|
die "profile class must implement load method" |
95
|
|
|
|
|
|
|
unless $profile->can('load'); |
96
|
4
|
|
|
|
|
22
|
$profile->load; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub _load_module { |
101
|
7
|
|
|
7
|
|
27
|
my ( $self, $module ) = @_; |
102
|
7
|
50
|
|
|
|
14
|
eval { load $module; 1; } or die "Can't load ${module}"; |
|
7
|
|
|
|
|
50
|
|
|
7
|
|
|
|
|
159023
|
|
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub call { |
106
|
3
|
|
|
3
|
1
|
98399
|
my ( $self, $env ) = @_; |
107
|
3
|
|
|
|
|
21
|
$self->_setup_profiler_if_needed($env); |
108
|
|
|
|
|
|
|
|
109
|
3
|
|
|
|
|
111
|
my $res = $self->app->($env); |
110
|
|
|
|
|
|
|
|
111
|
3
|
50
|
33
|
|
|
220
|
if ( ref($res) && ref($res) eq 'ARRAY' ) { |
112
|
3
|
|
|
|
|
43
|
return $res; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
Plack::Util::response_cb( |
116
|
|
|
|
|
|
|
$res, |
117
|
0
|
|
|
0
|
|
|
sub { |
118
|
|
|
|
|
|
|
} |
119
|
0
|
|
|
|
|
|
); |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
1; |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
__END__ |