| 1 | package Catalyst::Stats; | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 155 | ▶ | use Moose; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 155 | ▶ | use Time::HiRes qw/gettimeofday tv_interval/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 155 | ▶ | use Text::SimpleTable (); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 155 | ▶ | use Catalyst::Utils; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 155 | ▶ | use Tree::Simple qw/use_weak_refs/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 155 | ▶ | use Tree::Simple::Visitor::FindByUID; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 155 | ▶ | use namespace::clean -except => 'meta'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 940 | ▶ | has enable => (is => 'rw', required => 1, default => sub{ 1 }); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 13 | has tree => ( | ||||||||||||||||||||||||||||||||||||||||||||||
| 14 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||
| 15 | required => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 940 | ▶ | default => sub{ Tree::Simple->new({t => [gettimeofday]}) }, | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 155 | handles => [qw/ accept traverse /], | |||||||||||||||||||||||||||||||||||||||||||||
| 18 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 19 | has stack => ( | ||||||||||||||||||||||||||||||||||||||||||||||
| 20 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||
| 21 | required => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 22 | lazy => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 19 | ▶ | default => sub { [ shift->tree ] } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 155 | ); | |||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 76 | ▶ | sub profile { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
profile: called CC=16 SCAR=27.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 76 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 76 | ▶ | return unless $self->enable; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 75 | my %params; | |||||||||||||||||||||||||||||||||||||||||||||
| 32 | 75 | ▶ | if (@_ <= 1) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 4 | ▶ | $params{comment} = shift || ""; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
shift() || ''
MC/DC0%0/1
shift() || ''
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 35 | elsif (@_ % 2 != 0) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | die "profile() requires a single comment parameter or a list of name-value pairs; found " | |||||||||||||||||||||||||||||||||||||||||||||
| 37 | . (scalar @_) . " values: " . join(", ", @_); | ||||||||||||||||||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 39 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 71 | (%params) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 41 | 71 | ▶ | $params{comment} ||= ""; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$params{"comment"} ||= ""
MC/DC100%1/1
$params{"comment"} ||= ""
$params{"comment"}
Truth table100%2/2
A
A= $params{"comment"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 75 | my $parent; | |||||||||||||||||||||||||||||||||||||||||||||
| 45 | my $prev; | ||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 75 | my $t = [ gettimeofday ]; | |||||||||||||||||||||||||||||||||||||||||||||
| 47 | 75 | my $stack = $self->stack; | |||||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 75 | ▶ | if ($params{end}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 50 | # parent is on stack; search for matching block and splice out | ||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 33 | ▶ | for (my $i = $#{$stack}; $i > 0; $i--) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 37 | ▶ | if ($stack->[$i]->getNodeValue->{action} eq $params{end}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 33 | my ($node) = splice(@{$stack}, $i, 1); | |||||||||||||||||||||||||||||||||||||||||||||
| 54 | # Adjust elapsed on partner node | ||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 33 | my $v = $node->getNodeValue; | |||||||||||||||||||||||||||||||||||||||||||||
| 56 | 33 | $v->{elapsed} = tv_interval($v->{t}, $t); | |||||||||||||||||||||||||||||||||||||||||||||
| 57 | 33 | return $node->getUID; | |||||||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 60 | # if partner not found, fall through to treat as non-closing call | ||||||||||||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 42 | ▶ | if ($params{parent}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 63 | # parent is explicitly defined | ||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 5 | $prev = $parent = $self->_get_uid($params{parent}); | |||||||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 42 | ▶ | if (!$parent) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 67 | # Find previous node, which is either previous sibling or parent, for ref time. | ||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 37 | ▶ | $prev = $parent = $stack->[-1] or return undef; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 37 | my $n = $parent->getChildCount; | |||||||||||||||||||||||||||||||||||||||||||||
| 70 | 37 | ▶ | $prev = $parent->getChild($n - 1) if $n > 0; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||||||
| 73 | my $node = Tree::Simple->new({ | ||||||||||||||||||||||||||||||||||||||||||||||
| 74 | action => $params{begin} || "", | ||||||||||||||||||||||||||||||||||||||||||||||
| 75 | t => $t, | ||||||||||||||||||||||||||||||||||||||||||||||
| 76 | elapsed => tv_interval($prev->getNodeValue->{t}, $t), | ||||||||||||||||||||||||||||||||||||||||||||||
| 77 | comment => $params{comment}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 42 | ▶ | }); | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$params{'begin'} || ''
MC/DC100%1/1
$params{'begin'} || ''
$params{'begin'}
Truth table100%2/2
A
A= $params{'begin'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 42 | ▶ | $node->setUID($params{uid}) if $params{uid}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 42 | $parent->addChild($node); | |||||||||||||||||||||||||||||||||||||||||||||
| 82 | 42 | ▶ | push(@{$stack}, $node) if $params{begin}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 42 | return $node->getUID; | |||||||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 1 | ▶ | sub created { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
created: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 1 | return @{ shift->{tree}->getNodeValue->{t} }; | |||||||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 16 | ▶ | sub elapsed { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
elapsed: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 16 | return tv_interval(shift->{tree}->getNodeValue->{t}); | |||||||||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 16 | ▶ | sub report { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
report: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 16 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 16 | my $t; | |||||||||||||||||||||||||||||||||||||||||||||
| 99 | my @results; | ||||||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 16 | ▶ | if (!wantarray) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 15 | $t = Text::SimpleTable->new( | |||||||||||||||||||||||||||||||||||||||||||||
| 103 | [ Catalyst::Utils::term_width() - 9 - 13, 'Action' ], | ||||||||||||||||||||||||||||||||||||||||||||||
| 104 | [ 9, 'Time' ], | ||||||||||||||||||||||||||||||||||||||||||||||
| 105 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 39 | ▶ | $self->traverse(sub { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=8 SCAR=20.8
| |||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 39 | my $action = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 110 | 39 | my $stat = $action->getNodeValue; | |||||||||||||||||||||||||||||||||||||||||||||
| 111 | my @r = ( $action->getDepth, | ||||||||||||||||||||||||||||||||||||||||||||||
| 112 | ($stat->{action} || "") . | ||||||||||||||||||||||||||||||||||||||||||||||
| 113 | ($stat->{action} && $stat->{comment} ? " " : "") . ($stat->{comment} ? '- ' . $stat->{comment} : ""), | ||||||||||||||||||||||||||||||||||||||||||||||
| 114 | $stat->{elapsed}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 39 | ▶ | $stat->{action} ? 1 : 0, | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition100%5/5
$stat->{'action'} || ''
$stat->{"action"} and $stat->{"comment"}
MC/DC100%1/1
$stat->{'action'} || ''
$stat->{'action'}
MC/DC100%2/2
$stat->{"action"} and $stat->{"comment"}
$stat->{"action"}
$stat->{"comment"}
Truth table100%2/2
A
A= $stat->{'action'}
Truth table100%3/3
A and B
A= $stat->{"action"}B= $stat->{"comment"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 116 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 117 | # Trim down any times >= 10 to avoid ugly Text::Simple line wrapping | ||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 39 | my $elapsed = substr(sprintf("%f", $stat->{elapsed}), 0, 8) . "s"; | |||||||||||||||||||||||||||||||||||||||||||||
| 119 | 39 | ▶ | if ($t) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 28 | ▶ | $t->row( ( q{ } x $r[0] ) . $r[1], | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 121 | defined $r[2] ? $elapsed : '??'); | ||||||||||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 123 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 11 | push @results, \@r; | |||||||||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 16 | }); | |||||||||||||||||||||||||||||||||||||||||||||
| 127 | 16 | ▶ | return wantarray ? @results : $t->draw; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 5 | ▶ | sub _get_uid { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_uid: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 5 | my ($self, $uid) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 5 | my $visitor = Tree::Simple::Visitor::FindByUID->new; | |||||||||||||||||||||||||||||||||||||||||||||
| 134 | 5 | $visitor->searchForUID($uid); | |||||||||||||||||||||||||||||||||||||||||||||
| 135 | 5 | $self->accept($visitor); | |||||||||||||||||||||||||||||||||||||||||||||
| 136 | 5 | return $visitor->getResult; | |||||||||||||||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 1 | ▶ | sub addChild { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
addChild: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 141 | 1 | my $node = $_[ 0 ]; | |||||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 1 | my $stat = $node->getNodeValue; | |||||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||||||
| 145 | # do we need to fake $stat->{ t } ? | ||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 1 | ▶ | if( $stat->{ elapsed } ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 147 | # remove the "s" from elapsed time | ||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 1 | $stat->{ elapsed } =~ s{s$}{}; | |||||||||||||||||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 1 | $self->tree->addChild( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 1 | ▶ | sub setNodeValue { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
setNodeValue: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 156 | 1 | my $stat = $_[ 0 ]; | |||||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||||||
| 158 | # do we need to fake $stat->{ t } ? | ||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 1 | ▶ | if( $stat->{ elapsed } ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 160 | # remove the "s" from elapsed time | ||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 1 | $stat->{ elapsed } =~ s{s$}{}; | |||||||||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 1 | $self->tree->setNodeValue( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 1 | ▶ | sub getNodeValue { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
getNodeValue: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 169 | 1 | $self->tree->getNodeValue( @_ )->{ t }; | |||||||||||||||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 155 | __PACKAGE__->meta->make_immutable(); | |||||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 155 | 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||||||
| 176 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||