| 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
MC/DC0%0/2
ref $that || $that
ref $that
$that
Truth table33%1/3
A || B
A= ref $thatB= $that
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
Condition0%0/3
not $max or $max < $entry->{"duration"}
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"}
| |||||||||||||||||||||||||||||
| 59 | 0 | $max = $entry->{duration}; | |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 0 | ▶ | if ( !$min || $min > $entry->{duration} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $min or $min > $entry->{"duration"}
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"}
| |||||||||||||||||||||||||||||
| 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 | |||||||||||||||||||||||||||||
| 79 | 0 | "--------------------------------------------------------------------------------\n"; | |||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 105 | 1; | |||||||||||||||||||||||||||