line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mail::MtPolicyd::Profiler::Timer; |
2
|
|
|
|
|
|
|
|
3
|
8
|
|
|
8
|
|
918
|
use Moose; |
|
8
|
|
|
|
|
282049
|
|
|
8
|
|
|
|
|
45
|
|
4
|
8
|
|
|
8
|
|
33776
|
use namespace::autoclean; |
|
8
|
|
|
|
|
5326
|
|
|
8
|
|
|
|
|
44
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '2.02'; # VERSION |
7
|
|
|
|
|
|
|
# ABSTRACT: a profiler for the mtpolicyd |
8
|
|
|
|
|
|
|
|
9
|
8
|
|
|
8
|
|
3321
|
use Time::HiRes 'gettimeofday', 'tv_interval'; |
|
8
|
|
|
|
|
6346
|
|
|
8
|
|
|
|
|
39
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
has 'name' => ( is => 'rw', isa => 'Str', required => 1 ); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
has 'start_time' => ( is => 'rw', isa => 'ArrayRef', |
14
|
|
|
|
|
|
|
default => sub { [gettimeofday()] }, |
15
|
|
|
|
|
|
|
); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
has 'ticks' => ( is => 'ro', isa => 'ArrayRef', lazy => 1, |
18
|
|
|
|
|
|
|
default => sub { [] }, |
19
|
|
|
|
|
|
|
); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
has 'parent' => ( is => 'ro', isa => 'Maybe[Mail::MtPolicyd::Profiler::Timer]' ); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
around BUILDARGS => sub { |
24
|
|
|
|
|
|
|
my $orig = shift; |
25
|
|
|
|
|
|
|
my $class = shift; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
if ( @_ == 1 && !ref $_[0] ) { |
28
|
|
|
|
|
|
|
return $class->$orig( name => $_[0] ); |
29
|
|
|
|
|
|
|
} else { |
30
|
|
|
|
|
|
|
return $class->$orig(@_); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
}; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub tick { |
35
|
19
|
|
|
19
|
0
|
108
|
my ( $self, $msg ) = @_; |
36
|
19
|
|
|
|
|
42
|
my $now = [gettimeofday()]; |
37
|
19
|
|
|
|
|
510
|
my $delay = tv_interval($self->start_time, $now); |
38
|
19
|
|
|
|
|
148
|
push( @{$self->ticks}, [ $delay, $msg ] ); |
|
19
|
|
|
|
|
466
|
|
39
|
19
|
|
|
|
|
31
|
return; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub stop { |
43
|
7
|
|
|
7
|
0
|
81
|
my $self = shift; |
44
|
7
|
|
|
|
|
11
|
$self->tick('timer stopped'); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub new_child { |
48
|
6
|
|
|
6
|
0
|
766
|
my $self = shift; |
49
|
6
|
|
|
|
|
165
|
my $timer = __PACKAGE__->new( |
50
|
|
|
|
|
|
|
parent => $self, |
51
|
|
|
|
|
|
|
@_ |
52
|
|
|
|
|
|
|
); |
53
|
6
|
|
|
|
|
158
|
$self->tick('started timer '.$timer->name); |
54
|
6
|
|
|
|
|
6
|
push( @{$self->ticks}, $timer ); |
|
6
|
|
|
|
|
146
|
|
55
|
6
|
|
|
|
|
14
|
return( $timer ); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub to_string { |
59
|
4
|
|
|
4
|
0
|
19
|
my $self = shift; |
60
|
4
|
|
|
|
|
1
|
my $str = ''; |
61
|
4
|
|
|
|
|
5
|
foreach my $tick ( @{$self->ticks} ) { |
|
4
|
|
|
|
|
102
|
|
62
|
15
|
100
|
|
|
|
24
|
if( ref $tick eq 'ARRAY' ) { |
|
|
50
|
|
|
|
|
|
63
|
12
|
|
|
|
|
53
|
$str .= sprintf("%0f %s\n", @$tick ); |
64
|
|
|
|
|
|
|
} elsif( ref $tick eq 'Mail::MtPolicyd::Profiler::Timer' ) { |
65
|
3
|
|
|
|
|
7
|
my $substr = $tick->to_string; |
66
|
3
|
|
|
|
|
16
|
$substr =~ s/^/ /msg; |
67
|
3
|
|
|
|
|
5
|
$str .= $substr; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
} |
70
|
4
|
|
|
|
|
6
|
return( $str ); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
1; |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
__END__ |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=pod |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=encoding UTF-8 |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head1 NAME |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
Mail::MtPolicyd::Profiler::Timer - a profiler for the mtpolicyd |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head1 VERSION |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
version 2.02 |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head1 AUTHOR |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
Markus Benning <ich@markusbenning.de> |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
This software is Copyright (c) 2014 by Markus Benning <ich@markusbenning.de>. |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
This is free software, licensed under: |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
The GNU General Public License, Version 2, June 1991 |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=cut |