line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Telemetry::Any; |
2
|
2
|
|
|
2
|
|
2137
|
use 5.008001; |
|
2
|
|
|
|
|
7
|
|
3
|
2
|
|
|
2
|
|
10
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
38
|
|
4
|
2
|
|
|
2
|
|
9
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
45
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
8
|
use Carp; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
141
|
|
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
12
|
use base 'Devel::Timer'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
957
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = "0.05"; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
my $telemetry = __PACKAGE__->new(); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub import { |
15
|
2
|
|
|
2
|
|
15
|
my ( $class, $var ) = @_; |
16
|
|
|
|
|
|
|
|
17
|
2
|
50
|
|
|
|
25
|
return if !defined $var; |
18
|
|
|
|
|
|
|
|
19
|
0
|
|
|
|
|
0
|
my $saw_var; |
20
|
0
|
0
|
|
|
|
0
|
if ( $var =~ /^\$(\w+)/x ) { |
21
|
0
|
|
|
|
|
0
|
$saw_var = $1; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
else { |
24
|
0
|
|
|
|
|
0
|
croak('Ðrgument must be a variable'); |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
0
|
|
|
|
|
0
|
my $caller = caller(); |
28
|
|
|
|
|
|
|
|
29
|
2
|
|
|
2
|
|
4231
|
no strict 'refs'; ## no critic (TestingAndDebugging::ProhibitNoStrict) |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
1352
|
|
30
|
0
|
|
|
|
|
0
|
my $varname = "${caller}::${saw_var}"; |
31
|
0
|
|
|
|
|
0
|
*$varname = \$telemetry; |
32
|
|
|
|
|
|
|
|
33
|
0
|
|
|
|
|
0
|
return; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
## calculate total time (start time vs last time) |
37
|
|
|
|
|
|
|
sub total_time { |
38
|
30
|
|
|
30
|
0
|
53
|
my ($self) = @_; |
39
|
|
|
|
|
|
|
|
40
|
30
|
|
|
|
|
90
|
return Time::HiRes::tv_interval( $self->{times}->[0], $self->{times}->[ $self->{count} - 1 ] ); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub report { |
44
|
5
|
|
|
5
|
1
|
5293599
|
my ( $self, %args ) = @_; |
45
|
|
|
|
|
|
|
|
46
|
5
|
100
|
|
|
|
54
|
my @records = $args{collapse} ? $self->collapsed(%args) : $self->detailed(%args); |
47
|
|
|
|
|
|
|
|
48
|
5
|
|
|
|
|
15
|
my $report; |
49
|
|
|
|
|
|
|
|
50
|
5
|
100
|
66
|
|
|
31
|
if ( defined $args{format} && $args{format} eq 'table' ) { |
51
|
2
|
|
|
|
|
10
|
$report .= ref($self) . ' Report -- Total time: ' . sprintf( '%.4f', $self->total_time() ) . " secs\n"; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
5
|
100
|
|
|
|
40
|
if ( $args{collapse} ) { |
55
|
2
|
100
|
66
|
|
|
14
|
if ( defined $args{format} && $args{format} eq 'table' ) { |
56
|
1
|
|
|
|
|
4
|
$report .= "Count Time Percent\n"; |
57
|
1
|
|
|
|
|
2
|
$report .= "----------------------------------------------\n"; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
else { |
61
|
3
|
100
|
66
|
|
|
16
|
if ( defined $args{format} && $args{format} eq 'table' ) { |
62
|
1
|
|
|
|
|
10
|
$report .= "Interval Time Percent\n"; |
63
|
1
|
|
|
|
|
3
|
$report .= "----------------------------------------------\n"; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
5
|
|
|
|
|
30
|
$report .= join "\n", @records; |
68
|
|
|
|
|
|
|
|
69
|
5
|
|
|
|
|
38
|
$self->print($report); |
70
|
|
|
|
|
|
|
|
71
|
5
|
|
|
|
|
563
|
return 1; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub detailed { |
75
|
3
|
|
|
3
|
0
|
10
|
my ( $self, %args ) = @_; |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
## sort interval structure based on value |
78
|
|
|
|
|
|
|
|
79
|
3
|
|
|
|
|
10
|
@{ $self->{intervals} } = sort { $b->{value} <=> $a->{value} } @{ $self->{intervals} }; |
|
3
|
|
|
|
|
16
|
|
|
45
|
|
|
|
|
84
|
|
|
3
|
|
|
|
|
31
|
|
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
## |
82
|
|
|
|
|
|
|
## report of each time space between marks |
83
|
|
|
|
|
|
|
## |
84
|
|
|
|
|
|
|
|
85
|
3
|
|
|
|
|
8
|
my @records; |
86
|
|
|
|
|
|
|
|
87
|
3
|
|
|
|
|
7
|
for my $i ( @{ $self->{intervals} } ) { |
|
3
|
|
|
|
|
35
|
|
88
|
|
|
|
|
|
|
## skip first time (to make an interval, |
89
|
|
|
|
|
|
|
## compare the current time with the previous one) |
90
|
|
|
|
|
|
|
|
91
|
23
|
100
|
|
|
|
70
|
next if ( $i->{index} == 0 ); |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
my $msg = sprintf( |
94
|
|
|
|
|
|
|
'%02d -> %02d %.4f %5.2f%% %s -> %s', |
95
|
|
|
|
|
|
|
$i->{index} - 1, |
96
|
|
|
|
|
|
|
$i->{index}, $i->{value}, |
97
|
|
|
|
|
|
|
$i->{value} / $self->total_time() * 100, |
98
|
|
|
|
|
|
|
$self->{label}->{ $i->{index} - 1 }, |
99
|
|
|
|
|
|
|
$self->{label}->{ $i->{index} }, |
100
|
20
|
|
|
|
|
59
|
); |
101
|
|
|
|
|
|
|
|
102
|
20
|
|
|
|
|
492
|
push @records, $msg; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
3
|
|
|
|
|
19
|
return @records; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub collapsed { |
109
|
2
|
|
|
2
|
0
|
10
|
my ( $self, %args ) = @_; |
110
|
|
|
|
|
|
|
|
111
|
2
|
|
|
|
|
28
|
$self->_calculate_collapsed; |
112
|
|
|
|
|
|
|
|
113
|
2
|
|
|
|
|
266
|
my $c = $self->{collapsed}; |
114
|
2
|
|
50
|
|
|
23
|
my $sort_by = $args{sort_by} || 'time'; |
115
|
|
|
|
|
|
|
|
116
|
2
|
|
|
|
|
23
|
my @labels = sort { $c->{$b}->{$sort_by} <=> $c->{$a}->{$sort_by} } keys %$c; |
|
9
|
|
|
|
|
29
|
|
117
|
|
|
|
|
|
|
|
118
|
2
|
|
|
|
|
7
|
my @records; |
119
|
|
|
|
|
|
|
|
120
|
2
|
|
|
|
|
9
|
foreach my $label (@labels) { |
121
|
|
|
|
|
|
|
my $msg = sprintf( |
122
|
|
|
|
|
|
|
'%8s %.4f %5.2f%% %s', |
123
|
|
|
|
|
|
|
$c->{$label}->{count}, |
124
|
|
|
|
|
|
|
$c->{$label}->{time}, |
125
|
8
|
|
|
|
|
25
|
$c->{$label}->{time} / $self->total_time() * 100, $label, |
126
|
|
|
|
|
|
|
); |
127
|
|
|
|
|
|
|
|
128
|
8
|
|
|
|
|
165
|
push @records, $msg; |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
2
|
|
|
|
|
11
|
return @records; |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
sub reset { ## no critic (Subroutines::ProhibitBuiltinHomonyms) |
135
|
1
|
|
|
1
|
0
|
1062313
|
my ($self) = @_; |
136
|
|
|
|
|
|
|
|
137
|
1
|
|
|
|
|
5
|
%{$self} = ( |
|
1
|
|
|
|
|
23
|
|
138
|
|
|
|
|
|
|
times => [], |
139
|
|
|
|
|
|
|
count => 0, |
140
|
|
|
|
|
|
|
label => {}, |
141
|
|
|
|
|
|
|
); |
142
|
|
|
|
|
|
|
|
143
|
1
|
|
|
|
|
3
|
return $self; |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
1; |
147
|
|
|
|
|
|
|
__END__ |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=encoding utf-8 |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=head1 NAME |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
Telemetry::Any - It's new $module |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=head1 SYNOPSIS |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
use Telemetry::Any; |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=head1 DESCRIPTION |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
Telemetry::Any is ... |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=head1 LICENSE |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
Copyright (C) Mikhail Ivanov. |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
168
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=head1 AUTHOR |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
Mikhail Ivanov E<lt>m.ivanych@gmail.comE<gt> |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=cut |
175
|
|
|
|
|
|
|
|