line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mail::MtPolicyd::Profiler::Timer; |
2
|
|
|
|
|
|
|
|
3
|
8
|
|
|
8
|
|
1659
|
use Moose; |
|
8
|
|
|
|
|
474253
|
|
|
8
|
|
|
|
|
58
|
|
4
|
8
|
|
|
8
|
|
52563
|
use namespace::autoclean; |
|
8
|
|
|
|
|
8776
|
|
|
8
|
|
|
|
|
55
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '1.23'; # VERSION |
7
|
|
|
|
|
|
|
# ABSTRACT: a profiler for the mtpolicyd |
8
|
|
|
|
|
|
|
|
9
|
8
|
|
|
8
|
|
6102
|
use Time::HiRes 'gettimeofday', 'tv_interval'; |
|
8
|
|
|
|
|
9956
|
|
|
8
|
|
|
|
|
59
|
|
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
|
170
|
my ( $self, $msg ) = @_; |
36
|
19
|
|
|
|
|
66
|
my $now = [gettimeofday()]; |
37
|
19
|
|
|
|
|
771
|
my $delay = tv_interval($self->start_time, $now); |
38
|
19
|
|
|
|
|
180
|
push( @{$self->ticks}, [ $delay, $msg ] ); |
|
19
|
|
|
|
|
749
|
|
39
|
19
|
|
|
|
|
57
|
return; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub stop { |
43
|
7
|
|
|
7
|
0
|
151
|
my $self = shift; |
44
|
7
|
|
|
|
|
21
|
$self->tick('timer stopped'); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub new_child { |
48
|
6
|
|
|
6
|
0
|
1095
|
my $self = shift; |
49
|
6
|
|
|
|
|
246
|
my $timer = __PACKAGE__->new( |
50
|
|
|
|
|
|
|
parent => $self, |
51
|
|
|
|
|
|
|
@_ |
52
|
|
|
|
|
|
|
); |
53
|
6
|
|
|
|
|
238
|
$self->tick('started timer '.$timer->name); |
54
|
6
|
|
|
|
|
10
|
push( @{$self->ticks}, $timer ); |
|
6
|
|
|
|
|
227
|
|
55
|
6
|
|
|
|
|
20
|
return( $timer ); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub to_string { |
59
|
4
|
|
|
4
|
0
|
25
|
my $self = shift; |
60
|
4
|
|
|
|
|
5
|
my $str = ''; |
61
|
4
|
|
|
|
|
5
|
foreach my $tick ( @{$self->ticks} ) { |
|
4
|
|
|
|
|
153
|
|
62
|
15
|
100
|
|
|
|
43
|
if( ref $tick eq 'ARRAY' ) { |
|
|
50
|
|
|
|
|
|
63
|
12
|
|
|
|
|
75
|
$str .= sprintf("%0f %s\n", @$tick ); |
64
|
|
|
|
|
|
|
} elsif( ref $tick eq 'Mail::MtPolicyd::Profiler::Timer' ) { |
65
|
3
|
|
|
|
|
11
|
my $substr = $tick->to_string; |
66
|
3
|
|
|
|
|
21
|
$substr =~ s/^/ /msg; |
67
|
3
|
|
|
|
|
7
|
$str .= $substr; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
} |
70
|
4
|
|
|
|
|
11
|
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 1.23 |
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 |