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