| 1 | package Aspect::Library::ZoneTimer; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use 5.008002; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use Carp (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use Params::Util 1.00 (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use Aspect::Modular 1.00 (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 3 | ▶ | use Aspect::Advice::Around (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 3 | ▶ | use Time::HiRes 1.9718 (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 3 | ▶ | use vars qw{$VERSION @ISA}; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 3 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 3 | $VERSION = '1.10'; | |||||||||||||||||||||||||||||||||||||||||
| 15 | 3 | @ISA = 'Aspect::Modular'; | |||||||||||||||||||||||||||||||||||||||||
| 16 | } | ||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | 2 | ▶ | sub get_advice { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_advice: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 20 | 2 | my %params = @_; | |||||||||||||||||||||||||||||||||||||||||
| 21 | 2 | my $zones = $params{zones}; | |||||||||||||||||||||||||||||||||||||||||
| 22 | 2 | my $handler = $params{handler}; | |||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | # Check params | ||||||||||||||||||||||||||||||||||||||||||
| 25 | 2 | ▶ | unless ( Params::Util::_HASH($zones) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | 0 | Carp::croak("Did not provide a set of zones"); | |||||||||||||||||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||||||||||||||||
| 28 | 2 | ▶ | unless ( Params::Util::_CODELIKE($handler) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | 0 | Carp::croak("Did not provide a handler function"); | |||||||||||||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | # Variables to be shared between all advice closures | ||||||||||||||||||||||||||||||||||||||||||
| 33 | 2 | my @STACK = (); # Storage for timing data | |||||||||||||||||||||||||||||||||||||||||
| 34 | 2 | my $DISABLE = 0; # Prevent recursion in the report handler | |||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | # Create one advice for each zone | ||||||||||||||||||||||||||||||||||||||||||
| 37 | 2 | my @advice = (); | |||||||||||||||||||||||||||||||||||||||||
| 38 | 2 | foreach ( sort keys %$zones ) { | |||||||||||||||||||||||||||||||||||||||||
| 39 | 4 | my $zone = $_; | |||||||||||||||||||||||||||||||||||||||||
| 40 | 4 | my $pointcut = $zones->{$zone}; | |||||||||||||||||||||||||||||||||||||||||
| 41 | push @advice, Aspect::Advice::Around->new( | ||||||||||||||||||||||||||||||||||||||||||
| 42 | lexical => $self->lexical, | ||||||||||||||||||||||||||||||||||||||||||
| 43 | pointcut => $pointcut, | ||||||||||||||||||||||||||||||||||||||||||
| 44 | 12 | ▶ | code => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=8 SCAR=20.8
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | # Shortcut if we are inside the same zone | ||||||||||||||||||||||||||||||||||||||||||
| 46 | # or inside the handler. | ||||||||||||||||||||||||||||||||||||||||||
| 47 | 12 | ▶ | if ( $DISABLE or @STACK and $STACK[-1]->[0] eq $zone ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
$DISABLE or @STACK and $STACK[-1][0] eq $zone
@STACK and $STACK[-1][0] eq $zone
MC/DC33%1/3
$DISABLE or @STACK and $STACK[-1][0] eq $zone
$DISABLE
@STACK
$STACK[-1][0] eq $zone
Truth table75%3/4
A or B and C
A= $DISABLEB= @STACKC= $STACK[-1][0] eq $zone
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 3 | $_->proceed; | |||||||||||||||||||||||||||||||||||||||||
| 49 | 3 | return; | |||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | # Execute the function and capture timing | ||||||||||||||||||||||||||||||||||||||||||
| 53 | 9 | my $error = ''; | |||||||||||||||||||||||||||||||||||||||||
| 54 | SCOPE: { | ||||||||||||||||||||||||||||||||||||||||||
| 55 | 9 | local $@; | |||||||||||||||||||||||||||||||||||||||||
| 56 | 9 | push @STACK, [ $zone, { } ]; | |||||||||||||||||||||||||||||||||||||||||
| 57 | 9 | my @start = Time::HiRes::gettimeofday(); | |||||||||||||||||||||||||||||||||||||||||
| 58 | 9 | eval { | |||||||||||||||||||||||||||||||||||||||||
| 59 | 9 | $_->proceed; | |||||||||||||||||||||||||||||||||||||||||
| 60 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 61 | 9 | $error = $@; | |||||||||||||||||||||||||||||||||||||||||
| 62 | 9 | my @stop = Time::HiRes::gettimeofday(); | |||||||||||||||||||||||||||||||||||||||||
| 63 | 9 | my $frame = pop @STACK; | |||||||||||||||||||||||||||||||||||||||||
| 64 | 9 | my $total = $frame->[1]; | |||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||
| 66 | # Use our own interval math, generating a value | ||||||||||||||||||||||||||||||||||||||||||
| 67 | # in integer microseconds, to avoid potential | ||||||||||||||||||||||||||||||||||||||||||
| 68 | # floating point bugs in Time::HiRes::tv_interval. | ||||||||||||||||||||||||||||||||||||||||||
| 69 | 9 | my $interval = ( $stop[0] * 1000000 + $stop[1] ) | |||||||||||||||||||||||||||||||||||||||||
| 70 | - ( $start[0] * 1000000 + $start[1] ); | ||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | 9 | ▶ | if ( @STACK ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | # Calculate the exclusive time for the | ||||||||||||||||||||||||||||||||||||||||||
| 74 | # current stack frame and merge up to | ||||||||||||||||||||||||||||||||||||||||||
| 75 | # the totals already in our parent. | ||||||||||||||||||||||||||||||||||||||||||
| 76 | 5 | my $parent = $STACK[-1]->[1]; | |||||||||||||||||||||||||||||||||||||||||
| 77 | 5 | foreach my $z ( keys %$total ) { | |||||||||||||||||||||||||||||||||||||||||
| 78 | 2 | $interval -= $total->{$z}; | |||||||||||||||||||||||||||||||||||||||||
| 79 | 2 | $parent->{$z} += $total->{$z}; | |||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||
| 81 | 5 | $parent->{$zone} += $interval; | |||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 84 | # Calculate the exclusive time for the current | ||||||||||||||||||||||||||||||||||||||||||
| 85 | # zone and add it to any reentered zone | ||||||||||||||||||||||||||||||||||||||||||
| 86 | # beneath us. | ||||||||||||||||||||||||||||||||||||||||||
| 87 | 4 | foreach my $z ( keys %$total ) { | |||||||||||||||||||||||||||||||||||||||||
| 88 | 5 | $interval -= $total->{$z}; | |||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||
| 90 | 4 | $total->{$zone} += $interval; | |||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||
| 92 | # Send the report to the handler, including | ||||||||||||||||||||||||||||||||||||||||||
| 93 | # our start and stop times in case they are | ||||||||||||||||||||||||||||||||||||||||||
| 94 | # handy for the report. | ||||||||||||||||||||||||||||||||||||||||||
| 95 | 4 | $DISABLE++; | |||||||||||||||||||||||||||||||||||||||||
| 96 | 4 | eval { | |||||||||||||||||||||||||||||||||||||||||
| 97 | 4 | $handler->( | |||||||||||||||||||||||||||||||||||||||||
| 98 | $zone, | ||||||||||||||||||||||||||||||||||||||||||
| 99 | \@start, | ||||||||||||||||||||||||||||||||||||||||||
| 100 | \@stop, | ||||||||||||||||||||||||||||||||||||||||||
| 101 | $total, | ||||||||||||||||||||||||||||||||||||||||||
| 102 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 103 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 104 | 4 | $DISABLE--; | |||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||
| 108 | # Pass through any exceptions | ||||||||||||||||||||||||||||||||||||||||||
| 109 | 9 | ▶ | die $error if $error; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 110 | 6 | return; | |||||||||||||||||||||||||||||||||||||||||
| 111 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 112 | 4 | ); | |||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||
| 115 | 2 | return @advice; | |||||||||||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||
| 118 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||
| 120 | __END__ | ||||||||||||||||||||||||||||||||||||||||||