| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package HTTP::Engine::Middleware::Profile; |
|
2
|
2
|
|
|
2
|
|
766
|
use HTTP::Engine::Middleware; |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
10
|
|
|
3
|
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
with 'HTTP::Engine::Middleware::Role::Logger'; |
|
5
|
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
9
|
use Carp (); |
|
|
2
|
|
|
|
|
2
|
|
|
|
2
|
|
|
|
|
431
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
has profiler_class => ( |
|
9
|
|
|
|
|
|
|
is => 'ro', |
|
10
|
|
|
|
|
|
|
default => 'Runtime', |
|
11
|
|
|
|
|
|
|
); |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
has 'profiler' => ( |
|
14
|
|
|
|
|
|
|
is => 'rw', |
|
15
|
|
|
|
|
|
|
required => 1, |
|
16
|
|
|
|
|
|
|
lazy_build => 1, |
|
17
|
|
|
|
|
|
|
); |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
has 'config' => ( |
|
20
|
|
|
|
|
|
|
is => 'rw', |
|
21
|
|
|
|
|
|
|
isa => 'HashRef', |
|
22
|
|
|
|
|
|
|
default => sub { +{} }, |
|
23
|
|
|
|
|
|
|
); |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub _build_profiler { |
|
26
|
2
|
|
|
2
|
|
4
|
my $self = shift; |
|
27
|
2
|
|
|
|
|
7
|
my $class = $self->profiler_class; |
|
28
|
2
|
100
|
|
|
|
11
|
$class = "HTTP::Engine::Middleware::Profile::$class" |
|
29
|
|
|
|
|
|
|
unless $class =~ s/^\+//; |
|
30
|
2
|
|
|
|
|
843
|
Any::Moose::load_class($class); |
|
31
|
2
|
50
|
|
|
|
18
|
$@ and Carp::croak($@); |
|
32
|
2
|
|
|
|
|
90
|
$class->new($self->config); |
|
33
|
|
|
|
|
|
|
} |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
before_handle { |
|
37
|
|
|
|
|
|
|
my ( $c, $self, $req ) = @_; |
|
38
|
|
|
|
|
|
|
$self->profiler->start(@_); |
|
39
|
|
|
|
|
|
|
$req; |
|
40
|
|
|
|
|
|
|
}; |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
after_handle { |
|
43
|
|
|
|
|
|
|
my ( $c, $self, $req, $res ) = @_; |
|
44
|
|
|
|
|
|
|
$self->profiler->end(@_); |
|
45
|
|
|
|
|
|
|
$self->profiler->report(@_); |
|
46
|
|
|
|
|
|
|
$res; |
|
47
|
|
|
|
|
|
|
}; |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
__MIDDLEWARE__ |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
__END__ |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head1 NAME |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
HTTP::Engine::Middleware::Profile - stopwatch for request processing time |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
my $mw = HTTP::Engine::Middleware->new; |
|
60
|
|
|
|
|
|
|
$mw->install( 'HTTP::Engine::Middleware::Profile' => { |
|
61
|
|
|
|
|
|
|
logger => sub { |
|
62
|
|
|
|
|
|
|
warn @_; |
|
63
|
|
|
|
|
|
|
}, |
|
64
|
|
|
|
|
|
|
}); |
|
65
|
|
|
|
|
|
|
HTTP::Engine->new( |
|
66
|
|
|
|
|
|
|
interface => { |
|
67
|
|
|
|
|
|
|
module => 'YourFavoriteInterfaceHere', |
|
68
|
|
|
|
|
|
|
request_handler => $mw->handler( \&handler ), |
|
69
|
|
|
|
|
|
|
} |
|
70
|
|
|
|
|
|
|
)->run(); |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
This module profile request processing time. |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head1 AUTHORS |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
dann |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=cut |