| 1 | package Spoon::Trace; | ||||||||||||||||||||
| 2 | 1 | ▶ | use Spiffy -Base; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 3 | 1 | ▶ | use Time::HiRes qw(gettimeofday); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | |||||||||||||||||||||
| 5 | 1 | my $global_self; | |||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | 1 | field data => []; | |||||||||||||||||||
| 8 | 1 | field show_num => 1; | |||||||||||||||||||
| 9 | 1 | field show_time => 1; | |||||||||||||||||||
| 10 | 1 | field auto_print => 0; | |||||||||||||||||||
| 11 | 1 | field auto_warn => 0; | |||||||||||||||||||
| 12 | 1 | field add_label => 0; | |||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | 0 | ▶ | sub mode1 { | ||||||||||||||||||
|
Subroutine
mode1: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 15 | 0 | $self->show_num(0); | |||||||||||||||||||
| 16 | 0 | $self->show_time(0); | |||||||||||||||||||
| 17 | 0 | $self->add_label(1); | |||||||||||||||||||
| 18 | 0 | return $self; | |||||||||||||||||||
| 19 | } | ||||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | 0 | ▶ | sub trace() { | ||||||||||||||||||
|
Subroutine
trace: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 22 | 0 | ▶ | $global_self = defined $global_self | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 23 | ? $global_self | ||||||||||||||||||||
| 24 | : Spoon::Trace->new; | ||||||||||||||||||||
| 25 | } | ||||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | 0 | ▶ | sub mark { | ||||||||||||||||||
|
Subroutine
mark: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||
| 28 | 0 | ▶ | my $label = @_ | ||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$self->add_label && "\t(" . $self->get_label . ')'
MC/DC0%0/1
$self->add_label && "\t(" . $self->get_label . ')'
$self->add_label
Truth table0%0/2
A
A= $self->add_label
| |||||||||||||||||||||
| 29 | ? join(' ', @_) . ($self->add_label && "\t(" . $self->get_label . ')') | ||||||||||||||||||||
| 30 | : $self->get_label; | ||||||||||||||||||||
| 31 | 0 | my $data = $self->data; | |||||||||||||||||||
| 32 | 0 | my ($seconds, $microseconds) = gettimeofday; | |||||||||||||||||||
| 33 | 0 | push @$data, +{ | |||||||||||||||||||
| 34 | label => $label, | ||||||||||||||||||||
| 35 | time => $seconds + $microseconds / 1000000, | ||||||||||||||||||||
| 36 | }; | ||||||||||||||||||||
| 37 | 0 | return $self; | |||||||||||||||||||
| 38 | } | ||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | 0 | ▶ | sub get_label { | ||||||||||||||||||
|
Subroutine
get_label: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 41 | 0 | ▶ | my $i = (caller(2))[3] eq 'Spoon::Base::t' ? 1 : 0; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 42 | 0 | my $line = (caller(1 + $i))[2]; | |||||||||||||||||||
| 43 | 0 | my $sub = (caller(2 + $i))[3]; | |||||||||||||||||||
| 44 | 0 | return "$sub,$line"; | |||||||||||||||||||
| 45 | } | ||||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | 0 | ▶ | sub clear { | ||||||||||||||||||
|
Subroutine
clear: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 48 | 0 | $global_self = undef; | |||||||||||||||||||
| 49 | 0 | $self->data([]); | |||||||||||||||||||
| 50 | 0 | return $self; | |||||||||||||||||||
| 51 | } | ||||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | 0 | ▶ | sub report { | ||||||||||||||||||
|
Subroutine
report: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||
| 54 | 0 | my $data = $self->data; | |||||||||||||||||||
| 55 | 0 | my $output = ''; | |||||||||||||||||||
| 56 | 0 | ▶ | return $output unless @$data; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 57 | 0 | my $base_time = $data->[0]{time}; | |||||||||||||||||||
| 58 | 0 | ▶ | for (my $i = 0; $i < @$data; $i++) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 59 | 0 | ▶ | if ($self->show_num) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 60 | 0 | $output .= sprintf "%03d) ", $i + 1; | |||||||||||||||||||
| 61 | } | ||||||||||||||||||||
| 62 | 0 | ▶ | if ($self->show_time) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 63 | $output .= sprintf "%2.4f %2.2f ", | ||||||||||||||||||||
| 64 | $i ? $data->[$i]{time} - $data->[$i - 1]{time} : 0, | ||||||||||||||||||||
| 65 | 0 | ▶ | $data->[$i]{time} - $base_time; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 66 | } | ||||||||||||||||||||
| 67 | 0 | $output .= $data->[$i]{label} . "\n"; | |||||||||||||||||||
| 68 | } | ||||||||||||||||||||
| 69 | 0 | return $output; | |||||||||||||||||||
| 70 | } | ||||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | 0 | ▶ | sub DESTROY { | ||||||||||||||||||
|
Subroutine
DESTROY: not called CC=3 SCAR=24.8
| |||||||||||||||||||||
| 73 | 0 | ▶ | print $self->report | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 74 | if $self->auto_print; | ||||||||||||||||||||
| 75 | 0 | ▶ | warn $self->report | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 76 | if $self->auto_warn; | ||||||||||||||||||||
| 77 | } | ||||||||||||||||||||