line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mail::MtPolicyd::Profiler::Timer; |
2
|
|
|
|
|
|
|
|
3
|
8
|
|
|
8
|
|
871
|
use Moose; |
|
8
|
|
|
|
|
288742
|
|
|
8
|
|
|
|
|
964
|
|
4
|
8
|
|
|
8
|
|
34728
|
use namespace::autoclean; |
|
8
|
|
|
|
|
5409
|
|
|
8
|
|
|
|
|
43
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '2.01'; # VERSION |
7
|
|
|
|
|
|
|
# ABSTRACT: a profiler for the mtpolicyd |
8
|
|
|
|
|
|
|
|
9
|
8
|
|
|
8
|
|
3475
|
use Time::HiRes 'gettimeofday', 'tv_interval'; |
|
8
|
|
|
|
|
6565
|
|
|
8
|
|
|
|
|
40
|
|
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
|
116
|
my ( $self, $msg ) = @_; |
36
|
19
|
|
|
|
|
43
|
my $now = [gettimeofday()]; |
37
|
19
|
|
|
|
|
515
|
my $delay = tv_interval($self->start_time, $now); |
38
|
19
|
|
|
|
|
142
|
push( @{$self->ticks}, [ $delay, $msg ] ); |
|
19
|
|
|
|
|
467
|
|
39
|
19
|
|
|
|
|
33
|
return; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub stop { |
43
|
7
|
|
|
7
|
0
|
78
|
my $self = shift; |
44
|
7
|
|
|
|
|
16
|
$self->tick('timer stopped'); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub new_child { |
48
|
6
|
|
|
6
|
0
|
750
|
my $self = shift; |
49
|
6
|
|
|
|
|
181
|
my $timer = __PACKAGE__->new( |
50
|
|
|
|
|
|
|
parent => $self, |
51
|
|
|
|
|
|
|
@_ |
52
|
|
|
|
|
|
|
); |
53
|
6
|
|
|
|
|
156
|
$self->tick('started timer '.$timer->name); |
54
|
6
|
|
|
|
|
6
|
push( @{$self->ticks}, $timer ); |
|
6
|
|
|
|
|
143
|
|
55
|
6
|
|
|
|
|
14
|
return( $timer ); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub to_string { |
59
|
4
|
|
|
4
|
0
|
25
|
my $self = shift; |
60
|
4
|
|
|
|
|
5
|
my $str = ''; |
61
|
4
|
|
|
|
|
3
|
foreach my $tick ( @{$self->ticks} ) { |
|
4
|
|
|
|
|
114
|
|
62
|
15
|
100
|
|
|
|
28
|
if( ref $tick eq 'ARRAY' ) { |
|
|
50
|
|
|
|
|
|
63
|
12
|
|
|
|
|
95
|
$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
|
|
|
|
|
18
|
$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 2.01 |
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 |