line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Plack::Middleware::ProcessTimes; |
2
|
|
|
|
|
|
|
$Plack::Middleware::ProcessTimes::VERSION = '0.001000'; |
3
|
1
|
|
|
1
|
|
2310
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
44
|
|
4
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
52
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# ABSTRACT: Include process times of a request in the Plack env |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
21
|
use Time::HiRes qw(time); |
|
1
|
|
|
|
|
8
|
|
|
1
|
|
|
|
|
11
|
|
9
|
1
|
|
|
1
|
|
193
|
use parent 'Plack::Middleware'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
8
|
|
10
|
1
|
|
|
1
|
|
96
|
use Plack::Util::Accessor qw( measure_children ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
11
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub call { |
13
|
2
|
|
|
2
|
1
|
28556
|
my ($self, $env) = @_; |
14
|
|
|
|
|
|
|
|
15
|
2
|
|
|
|
|
29
|
my @times = (time, times); |
16
|
|
|
|
|
|
|
|
17
|
2
|
|
|
|
|
22
|
my $res = $self->app->($env); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
return $self->response_cb($res, sub{ |
20
|
2
|
|
|
2
|
|
41
|
my $inner = shift; |
21
|
|
|
|
|
|
|
|
22
|
2
|
100
|
|
|
|
11
|
if ($self->measure_children) { |
23
|
1
|
|
|
|
|
17
|
1 while waitpid(-1, 1) > 0; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
2
|
|
|
|
|
18
|
@times = map { $_ - shift @times } time, times; |
|
10
|
|
|
|
|
21
|
|
27
|
|
|
|
|
|
|
|
28
|
2
|
|
|
|
|
4
|
my $CPU = 0; |
29
|
2
|
|
|
|
|
12
|
$CPU += $times[$_] for 1..4; |
30
|
2
|
|
|
|
|
4
|
push @times, $CPU; |
31
|
|
|
|
|
|
|
|
32
|
2
|
|
|
|
|
5
|
@times = map { sprintf "%.3f", $_ } @times; |
|
12
|
|
|
|
|
77
|
|
33
|
|
|
|
|
|
|
|
34
|
2
|
|
|
|
|
4
|
push @{$inner->[1]}, |
|
2
|
|
|
|
|
10
|
|
35
|
|
|
|
|
|
|
x_time_real => $times[0], |
36
|
|
|
|
|
|
|
x_time_cpu_user => $times[1], |
37
|
|
|
|
|
|
|
x_time_cpu_sys => $times[2]; |
38
|
|
|
|
|
|
|
|
39
|
2
|
100
|
|
|
|
8
|
if ($self->measure_children) { |
40
|
1
|
|
|
|
|
4
|
push @{$inner->[1]}, |
|
1
|
|
|
|
|
3
|
|
41
|
|
|
|
|
|
|
x_time_cpu_cuser => $times[3], |
42
|
|
|
|
|
|
|
x_time_cpu_csys => $times[4]; |
43
|
|
|
|
|
|
|
} else { |
44
|
1
|
|
|
|
|
8
|
push @{$inner->[1]}, |
|
1
|
|
|
|
|
13
|
|
45
|
|
|
|
|
|
|
x_time_cpu_cuser => '-', |
46
|
|
|
|
|
|
|
x_time_cpu_csys => '-'; |
47
|
|
|
|
|
|
|
}; |
48
|
|
|
|
|
|
|
|
49
|
2
|
|
|
|
|
7
|
return; |
50
|
2
|
|
|
|
|
95
|
}); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
1; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
__END__ |