| 1 | package Devel::Agent::Util; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | =head1 NAME | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | Devel::Agent::Util - Agent utilities | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | use Devel::Agent; | ||||||||||||||||||||||||||||
| 10 | use Devel::Agent::Util qw(flush_row); | ||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | my $db=DB->new( | ||||||||||||||||||||||||||||
| 13 | on_frame_end=>\&flush_row, | ||||||||||||||||||||||||||||
| 14 | ); | ||||||||||||||||||||||||||||
| 15 | $db->start_trace; | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | END { | ||||||||||||||||||||||||||||
| 18 | $db->stop_trace; | ||||||||||||||||||||||||||||
| 19 | } | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | This module exports utility functions for Devel::Agent | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | =head2 Exported Methods | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | =cut | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 2 | ▶ | use Modern::Perl; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 30 | 2 | ▶ | use Devel::Agent; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 31 | 2 | our $VERSION=$Devel::Agent::VERSION; | |||||||||||||||||||||||||||
| 32 | 0 | ▶ | use Exporter 'import'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.4
| |||||||||||||||||||||||||||||
| 33 | 0 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.4
| |||||||||||||||||||||||||||||
| 34 | 2 | our @EXPORT_OK=qw(flush_row); | |||||||||||||||||||||||||||
| 35 | 2 | our @EXPORT=qw(flush_row); | |||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 2 | my $last=0; | |||||||||||||||||||||||||||
| 38 | 2 | my $self; | |||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | =head2 flush_row($agent,$frame,$fh) | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | Writes the a minimally useful set of frame information to STDERR if $fh is undef, othewise it writes to $fh. | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | =cut | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 0 | ▶ | sub flush_row { | ||||||||||||||||||||||||||
|
Subroutine
flush_row: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||
| 47 | 0 | my ($agent,$frame,$fh)=@_; | |||||||||||||||||||||||||||
| 48 | 0 | ▶ | $fh=\*STDERR unless defined $fh; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 0 | ▶ | $agent->{__pending__}=$agent->{__pending__} || {}; | ||||||||||||||||||||||||||
|
Condition0%0/2
$agent->{'__pending__'} || {}
MC/DC0%0/1
$agent->{'__pending__'} || {}
$agent->{'__pending__'}
Truth table0%0/2
A
A= $agent->{'__pending__'}
| |||||||||||||||||||||||||||||
| 51 | 0 | my $depth=$frame->{depth}; | |||||||||||||||||||||||||||
| 52 | 0 | ▶ | if($last==0 || $depth > $last +1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$last == 0 or $depth > $last + 1
MC/DC0%0/2
$last == 0 or $depth > $last + 1
$last == 0
$depth > $last + 1
Truth table0%0/3
A or B
A= $last == 0B= $depth > $last + 1
| |||||||||||||||||||||||||||||
| 53 | # we jumpped some frames. | ||||||||||||||||||||||||||||
| 54 | 0 | my $frames=$agent->grab_missing($last,$frame); | |||||||||||||||||||||||||||
| 55 | 0 | foreach my $frame ($frames->@*) { | |||||||||||||||||||||||||||
| 56 | 0 | _print_frame($fh,$agent,$frame,$last); | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 0 | _print_frame($fh,$agent,$frame,$last); | |||||||||||||||||||||||||||
| 61 | 0 | $last=$frame->{depth}; | |||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 0 | ▶ | sub _print_frame { | ||||||||||||||||||||||||||
|
Subroutine
_print_frame: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 65 | 0 | my $fh=shift; | |||||||||||||||||||||||||||
| 66 | 0 | my $agent=shift; | |||||||||||||||||||||||||||
| 67 | 0 | my $frame=shift; | |||||||||||||||||||||||||||
| 68 | 0 | my $last=shift; | |||||||||||||||||||||||||||
| 69 | 0 | my $depth=($frame->{depth} -1) *2; | |||||||||||||||||||||||||||
| 70 | 0 | my $pending=$agent->{__pending__}; | |||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 0 | ▶ | if(exists $frame->{duration}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 73 | 0 | ▶ | $fh->print(_frame_start($depth,$frame)) unless delete $pending->{$frame->{depth}}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 74 | 0 | $fh->print(_frame_end($depth,$frame)); | |||||||||||||||||||||||||||
| 75 | } else { | ||||||||||||||||||||||||||||
| 76 | 0 | $pending->{$frame->{depth}}=1; | |||||||||||||||||||||||||||
| 77 | 0 | $fh->print(_frame_start($depth,$frame)); | |||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 0 | ▶ | sub _frame_end { | ||||||||||||||||||||||||||
|
Subroutine
_frame_end: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 82 | 0 | my ($depth,$frame)=@_; | |||||||||||||||||||||||||||
| 83 | 0 | sprintf "\%${depth}s%s Depth: %i End Frame: \%i Line: File: \%s %i Duration: %f\n",'',@{$frame}{qw(class_method depth order_id source line duration)}; | |||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | 0 | ▶ | sub _frame_start{ | ||||||||||||||||||||||||||
|
Subroutine
_frame_start: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 86 | 0 | my ($depth,$frame)=@_; | |||||||||||||||||||||||||||
| 87 | 0 | sprintf "\%${depth}s\%s Depth: %i Start Frame: \%i File: \%s Line: \%i\n",'',@{$frame}{qw(class_method depth order_id source line)}; | |||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 2 | 1; | |||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | __END__ | ||||||||||||||||||||||||||||