lib/Rex/Profiler.pm

filter: Statementstmt 53.1% 25 / 47 Branchbran 33.3% 2 / 6 Conditioncond 11.1% 1 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 85.7% 6 / 7 Podpod 0.0% 0 / 4 totaltotal 43.0% 34 / 79 CC 10 SCAR 36.0
CC
10
Cov
45%
report
72.0
new
2.0
end
2.0
CRAP 36.8
« lib/Rex/Commands/Sysctl.pm ↑ Summary lib/Rex/Pkg/Debian.pm »
1 #
2 # (c) Jan Gehring <jan.gehring@gmail.com>
3 #
4  
5 package Rex::Profiler;
6  
7 105 ▶use v5.14.4;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 105 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 105 our $VERSION = '1.16.1'; # VERSION
11  
12 105 ▶use Time::HiRes qw(gettimeofday tv_interval);
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 65 ▶sub new {
Subroutine new: called CC=2 SCAR=7.1
Pod undocumented
15 65 my $that = shift;
16 65 ▶ my $proto = ref($that) || $that;
Condition33%1/3
ref $that || $that
l!l&&r!l&&!r
0650
MC/DC0%0/2
ref $that || $that
ref $that $that
Truth table33%1/3
A || B
A= ref $thatB= $that
ABresult
1X1
011
000
17 65 my $self = {@_};
18  
19 65 bless( $self, $proto );
20  
21 65 $self->{__data} = {};
22  
23 65 return $self;
24 }
25  
26 1344 ▶sub start {
Subroutine start: called CC=1 SCAR=0.0
Pod undocumented
27 1344 my ( $self, $info ) = @_;
28  
29 push(
30 1344 @{ $self->{__data}->{$info} },
31 {
32 start => [gettimeofday]
33 }
34 );
35 }
36  
37 1342 ▶sub end {
Subroutine end: called CC=2 SCAR=6.9
Pod undocumented
38 1342 my ( $self, $info ) = @_;
39  
40 1342 ▶ return unless ( $self->{__data}->{$info}->[-1] );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"__data"}{$info}[-1] 1221 121 1342
41  
42 121 my $data = $self->{__data}->{$info}->[-1];
43 121 $data->{end} = [gettimeofday];
44 121 $data->{duration} = tv_interval( $data->{start}, $data->{end} );
45  
46 121 $self->{__data}->{$info}->[-1] = $data;
47 }
48  
49 0 ▶sub report {
Subroutine report: not called CC=8 SCAR=42.8
Pod undocumented
50 0 my ($self) = @_;
51  
52 0 for my $info ( keys %{ $self->{__data} } ) {
53 0 print "# $info (count: " . scalar( @{ $self->{__data}->{$info} } ) . ")\n";
54 0 print " Timings:\n";
55  
56 0 my ( $max, $min, $avg, $all );
57 0 for my $entry ( @{ $self->{__data}->{$info} } ) {
58 0 ▶ if ( !$max || $max < $entry->{duration} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $max or $max < $entry->{"duration"}) 0 0 0
Condition0%0/3
not $max or $max < $entry->{"duration"}
l!l&&r!l&&!r
000
MC/DC0%0/2
not $max or $max < $entry->{"duration"}
not $max $max < $entry->{"duration"}
Truth table0%0/3
not(A) or B
A= not $maxB= $max < $entry->{"duration"}
ABresult
1X1
011
000
59 0 $max = $entry->{duration};
60 }
61  
62 0 ▶ if ( !$min || $min > $entry->{duration} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $min or $min > $entry->{"duration"}) 0 0 0
Condition0%0/3
not $min or $min > $entry->{"duration"}
l!l&&r!l&&!r
000
MC/DC0%0/2
not $min or $min > $entry->{"duration"}
not $min $min > $entry->{"duration"}
Truth table0%0/3
not(A) or B
A= not $minB= $min > $entry->{"duration"}
ABresult
1X1
011
000
63 0 $min = $entry->{duration};
64 }
65  
66 0 $all += $entry->{duration};
67 }
68  
69 0 $avg = $all / scalar( @{ $self->{__data}->{$info} } );
70  
71 0 print " min: $min / max: $max / avg: $avg / all: $all\n";
72 0 print " Overview:\n";
73  
74 0 for my $entry ( @{ $self->{__data}->{$info} } ) {
75 0 print " " . $entry->{duration} . "\n";
76 }
77  
78 print
79 0 "--------------------------------------------------------------------------------\n";
80 }
81 }
82  
83 105 1;
« lib/Rex/Commands/Sysctl.pm ↑ Summary lib/Rex/Pkg/Debian.pm »