blib/lib/Telemetry/Any.pm

filter: Statementstmt 89.1% 66 / 74 Branchbran 81.2% 13 / 16 Conditioncond 63.6% 7 / 11 MC/DCmcdc 42.8% 3 / 7 Subroutinesub 100% 12 / 12 Podpod 40.0% 2 / 5 totaltotal 82.4% 103 / 125 SCAR 27.6
CC
15
Cov
85%
report
9.1
import
5.4
collapsed
3.0
CRAP 15.7
↑ Summary Build »
1 package Telemetry::Any;
2 2 ▶use 5.008001;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 ▶use base 'Devel::Timer';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 our $VERSION = "0.05";
11  
12 2 my $telemetry = __PACKAGE__->new();
13  
14 sub import {
15 2 ▶ my ( $class, $var ) = @_;
Subroutine import: called CC=3 SCAR=16.9
16  
17 2 ▶ return if !defined $var;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $var 2 0 2
18  
19 0 my $saw_var;
20 0 ▶ if ( $var =~ /^\$(\w+)/x ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($var =~ /^\$(\w+)/x) { } 0 0 0
21 0 $saw_var = $1;
22 }
23 else {
24 0 croak('Аrgument must be a variable');
25 }
26  
27 0 my $caller = caller();
28  
29 2 ▶ no strict 'refs'; ## no critic (TestingAndDebugging::ProhibitNoStrict)
Subroutine BEGIN: called CC=1 SCAR=0.0
30 0 my $varname = "${caller}::${saw_var}";
31 0 *$varname = \$telemetry;
32  
33 0 return;
34 }
35  
36 ## calculate total time (start time vs last time)
37 sub total_time {
38 30 ▶ my ($self) = @_;
Subroutine total_time: called CC=1 SCAR=0.0
Pod undocumented
39  
40 30 return Time::HiRes::tv_interval( $self->{times}->[0], $self->{times}->[ $self->{count} - 1 ] );
41 }
42  
43 sub report {
44 5 ▶ my ( $self, %args ) = @_;
Subroutine report: called CC=9 SCAR=22.0
Pod documented
45  
46 5 ▶ my @records = $args{collapse} ? $self->collapsed(%args) : $self->detailed(%args);
Branch: 1 branch
BranchTrueFalseTotal
$args{'collapse'} ? : 2 3 5
47  
48 5 my $report;
49  
50 5 ▶ if ( defined $args{format} && $args{format} eq 'table' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"format"} and $args{"format"} eq "table") 2 3 5
Condition66%2/3
defined $args{"format"} and $args{"format"} eq "table"
!ll&&!rl&&r
302
MC/DC50%1/2
defined $args{"format"} and $args{"format"} eq "table"
defined $args{"format"} $args{"format"} eq "table"
Truth table66%2/3
A and B
A= defined $args{"format"}B= $args{"format"} eq "table"
ABresult
0X0
100
111
51 2 $report .= ref($self) . ' Report -- Total time: ' . sprintf( '%.4f', $self->total_time() ) . " secs\n";
52 }
53  
54 5 ▶ if ( $args{collapse} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{'collapse'}) { } 2 3 5
55 2 ▶ if ( defined $args{format} && $args{format} eq 'table' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"format"} and $args{"format"} eq "table") 1 1 2
Condition66%2/3
defined $args{"format"} and $args{"format"} eq "table"
!ll&&!rl&&r
101
MC/DC50%1/2
defined $args{"format"} and $args{"format"} eq "table"
defined $args{"format"} $args{"format"} eq "table"
Truth table66%2/3
A and B
A= defined $args{"format"}B= $args{"format"} eq "table"
ABresult
0X0
100
111
56 1 $report .= "Count Time Percent\n";
57 1 $report .= "----------------------------------------------\n";
58 }
59 }
60 else {
61 3 ▶ if ( defined $args{format} && $args{format} eq 'table' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"format"} and $args{"format"} eq "table") 1 2 3
Condition66%2/3
defined $args{"format"} and $args{"format"} eq "table"
!ll&&!rl&&r
201
MC/DC50%1/2
defined $args{"format"} and $args{"format"} eq "table"
defined $args{"format"} $args{"format"} eq "table"
Truth table66%2/3
A and B
A= defined $args{"format"}B= $args{"format"} eq "table"
ABresult
0X0
100
111
62 1 $report .= "Interval Time Percent\n";
63 1 $report .= "----------------------------------------------\n";
64 }
65 }
66  
67 5 $report .= join "\n", @records;
68  
69 5 $self->print($report);
70  
71 5 return 1;
72 }
73  
74 sub detailed {
75 3 ▶ my ( $self, %args ) = @_;
Subroutine detailed: called CC=3 SCAR=11.0
Pod undocumented
76  
77 ## sort interval structure based on value
78  
79 3 @{ $self->{intervals} } = sort { $b->{value} <=> $a->{value} } @{ $self->{intervals} };
80  
81 ##
82 ## report of each time space between marks
83 ##
84  
85 3 my @records;
86  
87 3 for my $i ( @{ $self->{intervals} } ) {
88 ## skip first time (to make an interval,
89 ## compare the current time with the previous one)
90  
91 23 ▶ next if ( $i->{index} == 0 );
Branch: 1 branch
BranchTrueFalseTotal
if $i->{"index"} == 0 3 20 23
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 );
101  
102 20 push @records, $msg;
103 }
104  
105 3 return @records;
106 }
107  
108 sub collapsed {
109 2 ▶ my ( $self, %args ) = @_;
Subroutine collapsed: called CC=3 SCAR=11.0
Pod undocumented
110  
111 2 $self->_calculate_collapsed;
112  
113 2 my $c = $self->{collapsed};
114 2 ▶ my $sort_by = $args{sort_by} || 'time';
Condition50%1/2
$args{'sort_by'} || 'time'
l!l
02
MC/DC0%0/1
$args{'sort_by'} || 'time'
$args{'sort_by'}
Truth table50%1/2
A
A= $args{'sort_by'}
Aresult
11
00
115  
116 2 my @labels = sort { $c->{$b}->{$sort_by} <=> $c->{$a}->{$sort_by} } keys %$c;
117  
118 2 my @records;
119  
120 2 foreach my $label (@labels) {
121 my $msg = sprintf(
122 '%8s %.4f %5.2f%% %s',
123 $c->{$label}->{count},
124 $c->{$label}->{time},
125 8 $c->{$label}->{time} / $self->total_time() * 100, $label,
126 );
127  
128 8 push @records, $msg;
129 }
130  
131 2 return @records;
132 }
133  
134 sub reset { ## no critic (Subroutines::ProhibitBuiltinHomonyms)
135 1 ▶ my ($self) = @_;
Subroutine reset: called CC=1 SCAR=0.0
Pod documented
136  
137 1 %{$self} = (
138 times => [],
139 count => 0,
140 label => {},
141 );
142  
143 1 return $self;
144 }
145  
146 2 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  
↑ Summary Build »