Devel/Agent.pm

filter: Statementstmt 39.3% 134 / 341 Branchbran 15.2% 22 / 144 Conditioncond 0.0% 0 / 33 MC/DCmcdc 0.0% 0 / 18 Subroutinesub 64.8% 35 / 54 Podpod 5.0% 1 / 20 totaltotal 31.4% 192 / 610 CC 88 SCAR 41.3
CC
88
Cov
30%
sub
261.6
caller_to_ref
156.0
get_depth
72.0
CRAP 62.0
↑ Summary Devel/Agent/Util.pm »
1 package Devel::Agent;
2  
3 =head1 NAME
4  
5 Devel::Agent - Agent like debugger interface
6  
7 =head1 SYNOPSIS
8  
9 perl -d:Agent -MDevel::Agent::EveryThing myscript.pl
10  
11 =head1 DESCRIPTION
12  
13 For years people in the perl commnity have been asking for a way to do performance monitoring and tracing of runtime production code. This module attempts to fill this role by implementing a stripped down debugger that is intended to provide an agent or agent like interface for perl 5.34.0+ that is simlilar in nature to the agent interface in other langagues Such as python or java.
14  
15 This is accomplished by running the script or code in debug mode, "perl -d:Agent" and then turning the debugger on only as needed to record traching and performance metrics. That said this module just provides an agent interface, it does not act on code directly until something turns it on.
16  
17 =cut
18  
19 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 4 ▶use 5.34.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 4 our $VERSION=.007;
23  
24 0 our %VER_FIX;
25 4 ▶BEGIN {
Subroutine BEGIN: called CC=3 SCAR=11.2
26  
27 # the only option
28 # for details see perldoc perlvar
29 # and check the $PERLDB section
30 4 my @DEFAULT=(
31  
32 # -- this has to be enabled
33 # Do not debug
34 #0x01,
35  
36 # -- this has to be enabled
37 # Disable DB::DB
38 #0x02,
39  
40 # keep optimizations on
41 0x04,
42  
43 # do not save extra data
44 0x08,
45  
46 # don't save line settings
47 0x10,
48  
49 # -- this has to be enabled
50 # disable single step
51 #0x20,
52  
53 # do not use suroutine address
54 0x40,
55  
56 # disable goto reporting
57 0x80,
58  
59 # do not proivde informative file
60 0x100,
61  
62 # don't bother with informative names
63 0x200,
64  
65 # do not save source in @{"_<$filename"}
66 0x400,
67  
68 # do not save evals that generate no subs
69 0x800,
70  
71 # do not save uncompiled source code
72 0x1000,
73  
74 );
75  
76  
77 4 $VER_FIX{default}=\@DEFAULT;
78 4 $VER_FIX{'v5.34.0'}=\@DEFAULT;
79 4 my @DB_DISABLE;
80 4 ▶ if(exists $VER_FIX{$^V}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $Devel::Agent::VER_FIX{$^V}) { } 0 4 4
81 0 @DB_DISABLE=$VER_FIX{$^V}->@*;
82 } else {
83 4 @DB_DISABLE=$VER_FIX{default}->@*;
84 }
85  
86 4 foreach my $opt (@DB_DISABLE) {
87 40 $^P=$^P & ($^P ^ $opt);
88 }
89
90 }
91  
92 =head1 Agent interface
93  
94 The Agent interface is implemented via an on demand debugger that can be turned on/off on the fly. Also it is possible to run multiple different debugger instances with diffrent configurations on different blocks of code. This was done intentionally as perl is fairly complex in its nature and an agent interface isn't very useful unless it is flexible.
95  
96 The agent interface itself is activated by setting $DB::Agent to an instance of itself.
97  
98 To turn tracing on:
99  
100 Make sure you either start your perl script -d:Agent or set PERL5OPT="-d:Agent" before launching your script
101  
102 Inside you script you can issue the following
103  
104 use Data::Dumper;
105  
106 my $db=DB->new(
107 save_to_stack=>1
108 );
109  
110 $db->start_trace;
111  
112 # run some code
113 ...
114  
115 # and we are done wathcing
116 $db->stop_trace;
117  
118 # to dump a very human readable full trace
119 print Dumper($db->trace);
120  
121 But altering you code is far from ideal.
122  
123 Another option is to load the agent and a module that pre-configures it for use such as the L<Devel::Trace::EveryThing> module, wich provides a stack trace to STDERR in real time as frames begin and exit.
124  
125 Example using: Devel::Trace::EveryThing
126  
127 perl -Ilib -d:Agent -MDevel::Agent::EveryThing examples/everything.pl
128  
129 =head1 Classes that are Agent Aware
130  
131 Any class that implements the $instance->___db_stack_filter($agent,$frame,$args,$raw_caller) can filter its own current frame prior to execution, or even prevent the frame from being traced at all.
132  
133 The ___db_stack_filter method is expected to return true, if the call returns false, then the frame should not be traced. Since the frame passed in before it's runtime execution, the duration value will not be set.
134  
135 A basic implementation that exposes only the top level calls is defined in L<Devel::Agent::AwareRole>. Loading this role into your class will hide all calls made by your class, but not calls made directly to it, this includes child classes that make calls to other classes.
136  
137 Example:
138  
139 package My::Class::That::IS::Mostly::Hidden;
140  
141 use Role::Tiny::With; # you can also use Moo Moose or other role implementations
142 with 'Devel::Agent::AwareRole';
143  
144 1;
145  
146 If you want to force a class to not show its internals.. say a class like LWP::UserAgent.
147  
148 use LWP::UserAgent;
149 reuqire Devel::Agent::AwareRole;
150  
151 # now only the top level calls to LWP::UserAgent will show up
152 *LWP::UserAgent::___db_stack_filter=\&Devel::Agent::AwareRole::___db_stack_filter;
153  
154 Or if you need to disable filtering on a class that has filtering then you can do the opposite
155
156 *LWP::UserAgent::___db_stack_filter=sub { 1}
157  
158 To be fully ignored
159  
160 *LWP::UserAgent::___db_stack_filter=sub { 0}
161  
162 =head1 Frame information
163  
164 The following hash represents what is provided as a representation of a frame
165  
166 {
167 caller_class=>'main', # class that called this class
168 calls=>[], # child frames, empty unless $self->save_to_stack is true
169 class_method=>'main::test_a', # the resolved class::method
170 depth=>1, # stack depth, 1 is considered the root
171 duration=>undef|Float, # how long the frame took to execute, only defined when the frame has executed
172 end_id=>undef|Int, # frame final execution order where in the stack it ended
173 line=>2, # line number the frame was called from
174 no_frame=>0|1, # when true, this frame would have been filtered but was included for completeness
175 order_id=>1, # inital frame execution order, where in the stack it started
176 owner_id=>0, # which order_id frame triggered the execution of this frame
177 raw_method=>'main::test_a', # un-resolved method name
178 source=>'test.pl', # the source file
179 t0=>[0,0], # Frame Start timestamp in: epoch, microseconds
180 }
181  
182 =head1 DB Constructor options
183  
184 This section documents the %args the be passed to the new DB(%args) or DB->new(%args) call. For each option documented in this section, there is an accesor by that given name that can be called by $self->$name($new_value) or my $current_value=$self->$name.
185  
186 =cut
187  
188 # prevent indexing ( as ya this will be noticed in the indexing process for sure!!! )
189 package
190 DB;
191  
192 #use Modern::Perl;
193 0 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.4
194 0 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.4
195 4 require Scalar::Util;
196  
197 # as easy as Moo makes things.. its not welcome in a debugger ;(
198 0 ▶use Time::HiRes qw(gettimeofday tv_interval);
Subroutine BEGIN: called CC=1 SCAR=0.4
199 0 ▶use B qw(svref_2object);
Subroutine BEGIN: called CC=1 SCAR=0.4
200 0 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.4
201  
202 0 our $AGENT;
203 4 my $IN_METHOD=0;
204 4 my $internals=0;
205  
206 # ya no, only allow access to this class!!
207 4 my %BUILD_ARGS;
208  
209 # Genrate functions similar to moo and moose, but don't actually use Moo or Moose..
210 80 ▶sub has {
Subroutine has: called CC=3 SCAR=11.0
Pod undocumented
211 80 my ($method,%args)=@_;
212  
213 80 my $ref=ref $args{default};
214 80 $BUILD_ARGS{$method}=\%args;
215 80 ▶ unless($ref) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ref) 32 48 80
216 32 my $default=$args{default};
217 32 ▶ $args{default}=sub { $default };
Subroutine __ANON__: called CC=1 SCAR=0.0
218 }
219 80 ▶ if($args{clearer}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"clearer"}) 32 48 80
220 32 ▶ my $sub=sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
221 32 my $self=shift;
222 32 delete $self->{$method};
223 32 };
224 32 my $method="clear_$method";
225 32 my $method_name=__PACKAGE__."::$method";
226 0 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.4
227 0 *{$method_name}=$sub;
228 }
229  
230 41 ▶ my $sub=sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
231 41 my $self=shift;
232 41 ▶ if($#_==-1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#_ == -1) { } 40 1 41
233 40 ▶ if(exists $self->{$method}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{$method}) { } 7 33 40
234 0 return $self->{$method};
235 } else {
236 33 my $def=$args{default};
237 33 my $value=$self->{$method}=$self->$def();
238 33 return $value;
239 }
240 } else {
241 1 return $self->{$method}=$_[0];
242 }
243 80 };
244 0 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.4
245 80 my $method_name=__PACKAGE__."::$method";
246 0 *{$method_name}=$sub;
247 }
248  
249 3 ▶sub new {
Subroutine new: called CC=4 SCAR=13.9
Pod undocumented
250 3 my ($class,%args)=@_;
251 3 my $self=bless {},$class;
252 3 ▶ while(my ($key,$args)=each %BUILD_ARGS) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %BUILD_ARGS) 60 3 63
253 60 ▶ if(exists $args{$key}) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $args{$key}) { } 1 59 60
elsif (not $args->{'lazy'}) { } 35 24 59
254 0 $self->{$key}=$args{$key};
255 } elsif(!$args->{lazy}) {
256 35 my $cb=$args->{default};
257 35 $self->{$key}=$self->$cb();
258 }
259 }
260  
261 # force out what pid and tid we are from
262 3 $self->pid;
263 3 $self->tid;
264 3 return $self;
265 }
266  
267 #use constant DEFAULT_DEPTH=>4;
268 # use prototype to declare constant
269 sub DEFAULT_DEPTH () { 4 }
270  
271 4 our @EXCLUDE_DEFAULTS=(
272 __PACKAGE__,
273 qw(
274 Data::Dumper
275 Time::HiRes
276 Method::Generate::Accessor
277 MooX::Types::MooseLike
278 Method::Generate::Accessor::_Generated
279 Moo::HandleMoose::AuthorityHack
280 Method::Generate::Constructor
281 Sub::Quote
282 strict
283 warnings
284 Sub::Defer
285 B
286 )
287 );
288  
289 =over 4
290  
291 =item * level=>ArrayRef
292  
293 This is an auto generated array ref that is use by the internals to track current stack level state information.
294  
295 =cut
296  
297 has level=>(
298 is=>'rw',
299 #isa=>ArrayRef,
300 lazy=>1,
301 4 ▶ default=>sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
302 4 clearer=>1,
303 );
304  
305 =item * resolve_constructor=>Bool
306  
307 This option is used to turn on or off the resolution of a class name when being constructed and other situations. By default this option is set to true.
308  
309 =cut
310  
311 4 has resolve_constructor=>(
312 # isa=>Bool,
313 is=>'ro',
314 default=>1,
315 );
316  
317 =item * trace=>[]
318  
319 When the object instance is constructed with save_to_stack=>1 ( default is: 0 ) then the stack trace will be saved into a single multi tier data structrure represented by $self->trace.
320  
321 =cut
322  
323 has trace=>(
324 # isa=>ArrayRef,
325 is=>'rw',
326 4 ▶ default=>sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
327 4 return [];
328 },
329 4 lazy=>1,
330 clearer=>1,
331 );
332  
333 =item * ignore_calling_class_re=>ArrayRef[RegexpRef]
334  
335 This option allows a list of calling calsses to be ignored when they match the regular expression.
336  
337 Example ignore_calling_class_re being set to [qr{^Do::Not::Track::Me::}] will prevent the debugger for trying to trace or record calls made by any methods within "Do::Not::Track::Me::". This does not prevent this class from showing up fully ina stack trace. If this class calls a class that calls another class that calls a class unlisted in ignore_calling_class_re, then Do::Not::Track::Me::xxx will show up as the owner frame of the calls as a biproduct of correctness in stack tracing.
338  
339 =cut
340  
341 has ignore_calling_class_re=>(
342 # isa=>ArrayRef[RegexpRef],
343 is=>'ro',
344 3 ▶ default=>sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
345 3 return [];
346 },
347 4 );
348  
349 =item * excludes=>HashRef[Int]
350  
351 This is a collection of classes that should be ignored when they make calls. The defaults are defined in @DB::EXCLUDE_DEFAULTS and include classes like Data::Dumper and Time::HiRes to name a few. For a full list of the current defaults just perl -MDevel::Agent -MData::Dumper -e 'print Dumper(\@DB::EXCLUDE_DEFAULTS)'
352  
353 =cut
354  
355 has excludes=>(
356 # isa=>HashRef[Int],
357 is=>'ro',
358 3 ▶ default=>sub {
Subroutine __ANON__: called CC=1 SCAR=1.2
359 return {
360 0 map {($_,1)}
361 @EXCLUDE_DEFAULTS
362 }
363 },
364 4 );
365  
366 =item * last_depth=>Int
367  
368 This value is used at runtime to determine the previous point in the stack trace.
369  
370 =cut
371  
372 4 has last_depth=>(
373 default=>0,
374 lazy=>1,
375 is=>'rw',
376 clearer=>1,
377 # isa=>Int,
378 );
379  
380 =item * depths=>ArrayRef
381  
382 This is used at runtime to determin the current frame stack depth. Each currently executing frame is kept in order from top to the bottom of the stack.
383  
384 =cut
385  
386 has depths=>(
387 is=>'rw',
388 lazy=>1,
389 # isa=>ArrayRef,
390 clearer=>1,
391 4 ▶ default=>sub { return [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
392 4 );
393  
394 =item * order_id=>Int
395  
396 This option acts as the sequence or order of execution counter for frames. When a frame starts $self->order_id is incremented by 1 and set to the frame's oder_id when the frame has completed execution the current $self->order_id is incremented again and set to the frame's end_id.
397  
398 =cut
399  
400 4 has order_id=>(
401 # isa=>Int,
402 is=>'rw',
403 lazy=>1,
404 default=>0,
405 clearer=>1,
406 );
407  
408 =item * save_to_stack=>Bool
409  
410 This option is used to turn on or of the saving of frames details in to a layered structure inside of $self->trace. The default is 0 or false.
411  
412 =cut
413  
414 4 has save_to_stack=>(
415 # isa=>Bool,
416 is=>'rw',
417 default=>0,
418 );
419  
420 =item * on_frame_end=>CodeRef
421  
422 This code ref is called when a frame is closed. This should act as the default data streaming hook callback. All tracing operations are halted durriong this callback.
423  
424 Example:
425  
426 sub {
427 my ($self,$last)=@_;
428  
429 # $self: An instance of DB
430 # $last: The most currently closed frame
431 }
432  
433 =cut
434  
435 has on_frame_end=>(
436 # isa=>CodeRef,
437 is=>'rw',
438 2 ▶ default=>sub { sub {} },
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: not called CC=1 SCAR=0.0
439 4 );
440  
441 =item * trace_id=>Int
442  
443 This method provides the current agent tracing pass. This number is incremented at the start of each call to $self->start_trace.
444  
445 =cut
446  
447 4 has trace_id=>(
448 is=>'rw',
449 default=>0,
450 lazy=>1,
451 );
452  
453 =item * ignore_blocks=>HasRef[Int]
454  
455 This hashref reprents what perl phazed blocks to ignore, the defaults are.
456  
457 {
458 BEGIN=>1,
459 END=>1,
460 INIT=>1,
461 CHECK=>1,
462 UNITCHECK=>1,
463 }
464  
465 The default values used to generate the hashref contained in in @DB::@PHAZES
466  
467 =cut
468  
469 4 our @PHAZES=(qw(BEGIN END INIT CHECK UNITCHECK));
470  
471 has ignore_blocks=>(
472 #isa=>HashRef[Int],
473 is=>'ro',
474 3 ▶ default=>sub {
Subroutine __ANON__: called CC=1 SCAR=1.2
475 0 return { map { ($_,1) } @PHAZES}
476 },
477 4 );
478  
479 =item * constructor_methods=>HashRef[Int]
480  
481 This is a hash of method names we consider object constructors
482  
483 Default:
484  
485 {
486 # we assume new is an object constructor
487 new=>1
488 }
489  
490 =cut
491  
492 has constructor_methods=>(
493 is=>'ro',
494 #isa=>HashRef,
495 3 ▶ default=>sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
496 return {
497 3 new=>1,
498 };
499 }
500 4 );
501  
502 =item * max_depth=>Int
503  
504 When the value is set to something other than -1, the number represents the maxium stack depth to trace too. Once the frame of max_depth exits, then max_depth will again be set to -1.
505  
506 =cut
507  
508 4 has max_depth=>(
509 is=>'rw',
510 lazy=>1,
511 clearer=>1,
512 default=>-1,
513 );
514  
515 =item * tid=>Int
516  
517 This is mostly here for completeness, retuns the tid id this debugger was created in.
518  
519 Note Note Note:
520  
521 The code was not orginally develpoed without threading in mind, if you wish to trace elemetns within a thread make sure you start an instance of the debugger within that thread.
522  
523 =cut
524  
525 has tid=>(
526 is=>'rw',
527 clearer=>1,
528 7 ▶ default=>sub {
Subroutine __ANON__: called CC=2 SCAR=7.4
529 7 my $tid=1;
530 7 eval {
531 7 ▶ if(my $cb=threads->can('tid')) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $cb = "threads"->can("tid")) 0 7 7
532 0 $tid=threads->$cb();
533 }
534 };
535 7 return $tid;
536 },
537 4 );
538  
539 =item * agent_aware=>Bool
540  
541 This enables or disables the use of $self->_agent_aware(...) method. See: $self->_agent_aware. Default is true.
542  
543 =cut
544  
545 4 has agent_aware=>(
546 is=>'ro',
547 default=>1,
548 #isa=>Bool,
549 );
550  
551 =item * existing_trace=>Maybe[InstanceOf['DB']]
552  
553 This acts as a save point for another existing trace to be exected.
554  
555 =cut
556  
557 has existing_trace=>(
558 is=>'rw',
559 #isa=>Maybe[InstanceOf['DB']],
560 lazy=>1,
561 clearer=>1,
562 4 ▶ default=>sub { undef },
Subroutine __ANON__: called CC=1 SCAR=0.0
563 4 );
564  
565 =item * process_result=>CodeRef
566  
567 This callback can be used to evaluate/modify the results of a traced method in this callback.
568  
569 Example callback
570  
571 sub {
572 my ($self,$type,$frame)=@_;
573 # $self: Instance of Devel::Agent
574 # $type: -1,0,1
575 # $frame: The current frame
576 }
577  
578 Notes on $type and where the current return values are stored
579  
580 When $type is:
581 -1 This is in a call to DESTROY( the envy of the programming world! )
582 Return value is in $DB::ret
583  
584 0 This method was called in a scalar context
585 Return value is in $DB::ret
586  
587 1 This method was called in a list context
588 Return value is in @DB::ret
589  
590 =cut
591  
592 has process_result=>(
593 is=>'ro',
594 #isa=>CodeRef,
595 3 ▶ default=>sub { sub {} },
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: not called CC=1 SCAR=0.0
596 4 );
597  
598 =item * filter_on_args=>CodeRef
599  
600 This allows a code ref to be passed in to filter arguments passed into a method. If the method returns false, the frame is ignored.
601  
602 Default always returns true
603  
604 sub {
605 my ($self,$frame,$args,$caller)=@_;
606 # $self: Instance of Devel::Agent
607 # $frame: Current frame hashref
608 # $args: The @_ contents
609 # $caller: The contents of caller($depth)
610 return 1;
611 }
612  
613 This is more or less a global frame filter, see: Classes that are Agent Aware
614  
615 =cut
616  
617 has filter_on_args=>(
618 is=>'ro',
619 #isa=>CodeRef,
620 0 ▶ default=>sub { sub {1} },
Subroutine __ANON__: called CC=1 SCAR=1.2
Subroutine __ANON__: not called CC=1 SCAR=1.2
621 4 );
622  
623  
624 =item * pid=>Int
625  
626 By default this is set to $$
627  
628 =cut
629  
630 4 has pid=>(
631 is=>'ro',
632 default=>$$,
633 #isa=>Int,
634 );
635  
636 =back
637  
638 =head1 API Methods
639  
640 This section documents general api methods.
641  
642 =head2 Bool=$self->_filter($caller,$args)
643  
644 This method is the core interface used to decide if a method should show up in the debug/stack trace.
645  
646 This is where the following constructor options are applied:
647  
648 =over 2
649  
650 =item * ignore_calling_class_re
651  
652 The $self->ignore_calling_class_re is applied to each calling or caller->[0], if it matches the frame is ignored.
653  
654 =item * excludes
655  
656 If $caller->[0] matches an element of excludes, then this frame is ignored.
657  
658 =item * resolve_constructor
659  
660 This converts the "class" portion of the frame value class_method to the first argument of a method that matches anything found in resolve_constructor.
661  
662 =item * excludes
663  
664 The updated class value is applied to excludes again, if it matches, then the frame is not traced.
665  
666 =back
667  
668 =cut
669  
670 0 ▶sub _filter {
Subroutine _filter: not called CC=7 SCAR=40.3
671 0 my ($self,$caller,$args)=@_;
672
673 0 ▶ return 0 unless defined($caller->[0]);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $caller->[0] 0 0 0
674 0 foreach my $re ($self->{ignore_calling_class_re}->@*) {
675 0 ▶ if($caller->[0]=~ $re) {
Branch: 1 branch
BranchTrueFalseTotal
if ($caller->[0] =~ /$re/u) 0 0 0
676 0 return 0;
677 }
678 }
679 0 ▶ return 0 if exists $self->{excludes}->{$caller->[0]};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"excludes"}{$caller->[0]} 0 0 0
680 0 my $caller_class=$caller->[3];
681 0 ▶ return 0 unless defined $caller_class;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $caller_class 0 0 0
682  
683 0 my ($class,$method)=$caller_class=~ m/^(.*)::(.*)$/;
684  
685 0 $self->resolve_class($class,$method,$caller,$args);
686  
687 0 ▶ return 0 if exists $self->{excludes}->{$class};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"excludes"}{$class} 0 0 0
688 0 return 1;
689 }
690  
691 =head2 $self->resolve_class($class,$method,$caller,$args)
692  
693 Changes $class to the constructor class if $self->resolve_constructor && exists $self->constructor_methods->{$method}
694  
695 =cut
696  
697 0 ▶sub resolve_class {
Subroutine resolve_class: not called CC=6 SCAR=37.4
Pod undocumented
698 0 my ($self,$class,$method,$caller,$args)=@_;
699 0 ▶ return unless $#{$args}!=-1 && defined($args->[0]);
Branch: 1 branch
BranchTrueFalseTotal
unless $#{$args;} != -1 and defined $args->[0] 0 0 0
Condition0%0/3
$#{$args;} != -1 and defined $args->[0]
!ll&&!rl&&r
000
MC/DC0%0/2
$#{$args;} != -1 and defined $args->[0]
$#{$args;} != -1 defined $args->[0]
Truth table0%0/3
A and B
A= $#{$args;} != -1B= defined $args->[0]
ABresult
0X0
100
111
700  
701 0 ▶ if($self->{resolve_constructor} && exists $self->{constructor_methods}->{$method} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"resolve_constructor"} and exists $self->{"constructor_methods"}{$method}) 0 0 0
Condition0%0/3
$self->{"resolve_constructor"} and exists $self->{"constructor_methods"}{$method}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"resolve_constructor"} and exists $self->{"constructor_methods"}{$method}
$self->{"resolve_constructor"} exists $self->{"constructor_methods"}{$method}
Truth table0%0/3
A and B
A= $self->{"resolve_constructor"}B= exists $self->{"constructor_methods"}{$method}
ABresult
0X0
100
111
702 0 my $new_class=$args->[0];
703 0 ▶ if($new_class->DOES($class)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($new_class->DOES($class)) 0 0 0
704 0 $caller->[3]=$class.'::'.$method;
705 0 $_[1]=$new_class;
706 }
707 }
708 }
709  
710 =head2 $self->close_depth($depth)
711  
712 After a frame ahs finished execution, this method is called. This removes the frame from $self->depths
713  
714 Sets the following frame option:
715  
716 error the $@ state
717 end_id the order_id this frame ended on
718 duration Execution time in micro seconds
719  
720 =cut
721  
722 0 ▶sub close_depth {
Subroutine close_depth: not called CC=2 SCAR=17.9
Pod undocumented
723 0 my ($self,$depth)=@_;
724  
725 0 my $last=pop $self->{depths}->@*;
726 0 my $t0=$last->{t0};
727 0 my $d=tv_interval($t0);
728 0 ▶ $d=0 if index($d,'e')!=-1; # how is this slower than a regex? wow!!!
Branch: 1 branch
BranchTrueFalseTotal
if index($d, "e") != -1 0 0 0
729 #$d=0 if $d=~ /e/s;
730 0 $last->{duration}=$d;
731 0 $last->{end_id}=$self->next_order_id,
732 my $tmp=$internals;
733 0 $internals=1;
734 0 $self->{on_frame_end}->($self,$last);
735 0 $internals=$tmp;
736 }
737  
738 =head2 my $id=$self->next_order_id
739  
740 Returns the next order_id.
741  
742 =cut
743  
744 0 ▶sub next_order_id {
Subroutine next_order_id: not called CC=1 SCAR=6.9
Pod undocumented
745 0 my ($self)=@_;
746 0 return $self->{order_id}=1+$self->{order_id};
747 }
748  
749 =head2 $self->close_to($depth,$frame|undef)
750  
751 Closes down the stack trace to $depth, performs addtional actions if $frame is defiend.
752  
753 =cut
754  
755 1 ▶sub close_to {
Subroutine close_to: called CC=8 SCAR=32.3
Pod undocumented
756 1 my ($self,$to,$last)=@_;
757  
758 1 ▶ if($to<=$self->{max_depth}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($to <= $self->{"max_depth"}) 0 1 1
759 # reset our max depth to -1;
760 0 $self->{max_depth}=-1;
761 }
762  
763 1 my $target;
764 1 my $size=$self->{depths}->$#*;
765 1 ▶ for(my $depth=$size;$depth>0;--$depth) {
Branch: 1 branch
BranchTrueFalseTotal
if ($depth > 0) 0 1 1
766 0 ▶ if($depth==$to) {
Branch: 2 branches
BranchTrueFalseTotal
if ($depth == $to) { } 0 0 0
elsif ($depth < $to) { } 0 0 0
767 0 $self->close_depth($depth);
768 0 $target=$to;
769 0 last;
770 } elsif($depth < $to) {
771 0 $target=$depth;
772 0 last;
773 } else {
774 0 $self->close_depth($depth);
775 }
776 }
777 1 ▶ if(defined($target)) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $target) { } 0 1 1
elsif (defined $last) { } 0 1 1
778 0 ▶ $self->save_to($last) if defined($last);
Branch: 1 branch
BranchTrueFalseTotal
if defined $last 0 0 0
779 } elsif(defined($last)) {
780 0 $self->save_to($last);
781 }
782 1 $self->{last_depth}=$to;
783 }
784  
785 =head2 $self->filter($caller,$args)
786  
787 This method is called by the DB method after the sub method and is used to place a frame on the stack for tracing.
788  
789 =cut
790  
791 0 ▶sub filter{
Subroutine filter: not called CC=6 SCAR=37.4
Pod undocumented
792 0 my ($self,$caller,$args)=@_;
793  
794 0 $self->pause_trace;
795 0 my $raw_caller=[@$args];
796 0 ▶ return $self->restore_trace unless $self->_filter($caller,$args);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_filter($caller, $args) 0 0 0
797 0 my $last=$self->caller_to_ref($caller,undef,$DB::sub,0);
798 0 ▶ return $self->restore_trace unless defined($last);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $last 0 0 0
799  
800 0 ▶ unless($self->{filter_on_args}->($self,$last,$args,$raw_caller)){
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"filter_on_args"}->($self, $last, $args, $raw_caller)) 0 0 0
801 0 $self->restore_trace;
802 0 return;
803 }
804  
805 0 ▶ if($self->{agent_aware}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"agent_aware"}) 0 0 0
806 0 ▶ unless($self->_agent_aware($last,$args,$raw_caller)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_agent_aware($last, $args, $raw_caller)) 0 0 0
807 0 $self->restore_trace;
808 0 return;
809 }
810 }
811  
812 0 $self->push_to_stack($last);
813 0 my $level=$self->{level};
814 0 push $level->[$level->$#*]->@*,$self->{last_depth};
815 0 $self->restore_trace;
816 }
817  
818 =head2 $self->_agent_aware($frame,$args,$raw_caller)
819  
820 This method is called before a frame is traced if $self->agent_aware is set to true( the default ). The objective of this method is see of the first argument being passed to this method is a blessed instance of that class. When the first argument passed to the class is a blessed object that DOES this class then a call to $args->[0]->___db_stack_filter($agent,$frame,$args,$raw_caller) is made. This allows classes to modify or inspect the frame that will be used in the reace. If the call to $args->[0]->___db_stack_filter($agent,$frame,$args,$raw_caller) returns false, the frame is skipped durring the trace period.
821  
822 Note note Note:
823  
824 The call to $args->[0]->___db_stack_filter($agent,$frame,$args,$raw_caller) is never wrapped in a eval and should never do anything heavy or it will impact the metrics provided by the debugger.
825  
826 =cut
827  
828 0 ▶sub _agent_aware {
Subroutine _agent_aware: not called CC=7 SCAR=40.3
829 0 my ($self,$frame,$args,$raw_caller)=@_;
830
831 0 ▶ return 1 unless $args->$#*>-1 && defined($args->[0]);
Branch: 1 branch
BranchTrueFalseTotal
unless $args->$#* > -1 and defined $args->[0] 0 0 0
Condition0%0/3
$args->$#* > -1 and defined $args->[0]
!ll&&!rl&&r
000
MC/DC0%0/2
$args->$#* > -1 and defined $args->[0]
$args->$#* > -1 defined $args->[0]
Truth table0%0/3
A and B
A= $args->$#* > -1B= defined $args->[0]
ABresult
0X0
100
111
832 0 my $class=&Scalar::Util::blessed($args->[0]);
833 0 ▶ return 1 unless $class;
Branch: 1 branch
BranchTrueFalseTotal
unless $class 0 0 0
834 0 my $cb=$class->can('___db_stack_filter');
835 0 ▶ return 1 unless $cb;
Branch: 1 branch
BranchTrueFalseTotal
unless $cb 0 0 0
836  
837 0 ▶ if($frame->{class_method}=~ /^(.*)::/s) {
Branch: 1 branch
BranchTrueFalseTotal
if ($frame->{"class_method"} =~ /^(.*)::/su) 0 0 0
838 0 ▶ return 1 unless $args->[0]->DOES($1);
Branch: 1 branch
BranchTrueFalseTotal
unless $args->[0]->DOES($1) 0 0 0
839 0 return $args->[0]->$cb(@_);
840 }
841  
842 0 return 1;
843 }
844  
845 =head2 Self->save_to($frame)
846  
847 Saves the frame to the stack trace at the proper depth.
848  
849 =cut
850  
851 0 ▶sub save_to {
Subroutine save_to: not called CC=3 SCAR=24.8
Pod undocumented
852 0 my ($self,$last)=@_;
853
854 0 my $depth=$last->{depth};
855 0 $self->{depths}->[$depth]=$last;
856  
857 0 $self->{last_depth}=$depth;
858 # stop here unless someone wants the frames saved in memory
859 0 ▶ return unless $self->save_to_stack;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->save_to_stack 0 0 0
860 0 ▶ if($depth==1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($depth == 1) { } 0 0 0
861 0 push $self->trace->@*,$self->{depths}->[$depth]=$last;
862 } else {
863 0 my $root=$depth -1;
864 0 push $self->{depths}->[$root]->{calls}->@*,$self->{depths}->[$depth]=$last;
865 }
866 }
867  
868 =head2 $self->push_to_stack($frame)
869  
870 This method handles the saving, closing and backfilling logic for a given frame.
871  
872 =cut
873  
874 0 ▶sub push_to_stack {
Subroutine push_to_stack: not called CC=3 SCAR=24.8
Pod undocumented
875 0 my ($self,$last)=@_;
876  
877 0 my $depth=$last->{depth};
878 0 my $last_depth=$self->{last_depth};
879 0 ▶ if($last_depth==0) {
Branch: 2 branches
BranchTrueFalseTotal
if ($last_depth == 0) { } 0 0 0
elsif ($depth <= $last_depth) { } 0 0 0
880 0 $self->save_to($last);
881 } elsif($depth<= $last_depth) {
882 0 $self->close_to($depth,$last);
883 } else {
884 0 $self->save_to($last);
885 }
886 }
887  
888 =head2 my $depth=$self->get_depth
889  
890 Returns undef or a number representing the stack depth. When the value is undef, the trace would exceed $self->max_depth;
891  
892 =cut
893  
894 0 ▶sub get_depth {
Subroutine get_depth: not called CC=8 SCAR=42.8
Pod undocumented
895 0 my ($self)=@_;
896 0 my $start = DEFAULT_DEPTH;
897 # skip un-needed depth checking
898 0 ▶ $start +=$self->{depths}->$#* if $self->{depths}->$#* >0;
Branch: 1 branch
BranchTrueFalseTotal
if $#{$self->{"depths"}} > 0 0 0 0
899 0 my $depth=$start - DEFAULT_DEPTH;
900  
901 0 my $caller=[caller($start)];
902 0 my $no_frame=[];
903 0 my $max=$self->{max_depth};
904 0 ▶ while($caller->$#*!=-1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($caller->$#* != -1) 0 0 0
905 0 ▶ if($max!=-1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($max != -1) 0 0 0
906 0 my $pos=$depth +1;
907 0 ▶ if($pos>$max) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pos > $max) 0 0 0
908 0 return undef;
909 }
910 }
911  
912 0 ▶ if($start !=DEFAULT_DEPTH) {
Branch: 1 branch
BranchTrueFalseTotal
if ($start != 4) 0 0 0
913 0 ▶ unless(defined $self->{depths}->[$depth]) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"depths"}[$depth]) 0 0 0
914 0 push $caller->@*,$depth;
915 0 push $no_frame->@*,$caller;
916 }
917 }
918 0 ++$start;
919 0 $caller=[caller($start)];
920 0 $depth=$start - DEFAULT_DEPTH;
921 }
922 0 foreach my $caller ($no_frame->@*) {
923 0 my $depth=pop $caller->@*;
924 0 my $last=$self->caller_to_ref($caller,$depth,$caller->[3],1);
925 0 $self->push_to_stack($last);
926 }
927 0 return $start - DEFAULT_DEPTH;
928 }
929  
930 =head2 my $frame=$self->caller_to_ref($caller,$depth|undef,$raw_method,$no_frame)
931  
932 Returns a frame hashref. If $depth is not defined a call to $depth is made, if it exceeds a set value of $self->max_depth undef is returned.
933  
934 =cut
935  
936 0 ▶sub caller_to_ref {
Subroutine caller_to_ref: not called CC=12 SCAR=50.5
Pod undocumented
937 0 my ($self,$caller,$depth,$raw_method,$no_frame)=@_;
938 0 ▶ $no_frame=0 unless defined($no_frame);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $no_frame 0 0 0
939 0 my ($p,$f,$l,$s,$h,$w,$e,$r)=@$caller;
940 0 ▶ if(defined($e)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $e) 0 0 0
941 0 $e='...';
942 }
943 0 ▶ if ($r) {
Branch: 3 branches
BranchTrueFalseTotal
if ($r) { } 0 0 0
elsif (defined $r) { } 0 0 0
elsif ($s eq '(eval)') { } 0 0 0
944 0 $s = "require '$e'";
945 } elsif (defined $r) {
946 0 $s = "eval '$e'";
947 } elsif ($s eq '(eval)') {
948 0 $s = "eval {...}";
949 }
950 0 ▶ $f = "$f" unless $f eq '-e';
Branch: 1 branch
BranchTrueFalseTotal
unless $f eq "-e" 0 0 0
951  
952 0 ▶ $depth=$self->get_depth unless defined($depth);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $depth 0 0 0
953 0 ▶ unless(defined($depth)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $depth) 0 0 0
954 0 return undef;
955 }
956  
957 0 my $root=$depth -1;
958 0 my $owner_id=0;
959 0 ▶ if($root!=0 && defined $self->{depths}->[$root]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($root != 0 and defined $self->{"depths"}[$root]) 0 0 0
Condition0%0/3
$root != 0 and defined $self->{"depths"}[$root]
!ll&&!rl&&r
000
MC/DC0%0/2
$root != 0 and defined $self->{"depths"}[$root]
$root != 0 defined $self->{"depths"}[$root]
Truth table0%0/3
A and B
A= $root != 0B= defined $self->{"depths"}[$root]
ABresult
0X0
100
111
960 0 $owner_id=$self->{depths}->[$root]->{order_id};
961 }
962
963 0 ▶ my $ref={
Branch: 1 branch
BranchTrueFalseTotal
ref $raw_method ? : 0 0 0
964 raw_method=>(ref($raw_method) ? 'sub { ... }' : $raw_method ),
965 owner_id=>$owner_id,
966 depth=>$depth,
967 order_id=>$self->next_order_id,
968 calls=>[],
969 t0=>[gettimeofday],
970 #t0=>[time,0],
971 class_method=>$s,
972 source=>$f,
973 line=>$l,
974 caller_class=>$p,
975 no_frame=>$no_frame,
976 meta=>{},
977 end_id=>0,
978 };
979  
980 0 return $ref;
981 }
982  
983 =head2 $self->reset
984  
985 Rsets the internals of the object for starting a new stack trace.
986  
987 =cut
988  
989 4 ▶sub reset {
Subroutine reset: called CC=2 SCAR=6.9
Pod undocumented
990 4 my ($self)=@_;
991 4 foreach my $key (
992 qw(
993 trace
994 last_depth
995 depths
996 order_id
997 level
998 tid
999 max_depth
1000 existing_trace
1001 )) {
1002 32 my $method="clear_$key";
1003 32 $self->$method();
1004 32 $self->$key();
1005 }
1006 }
1007  
1008 =head2 $self->start_trace
1009  
1010 Begins the stack trace process.
1011  
1012 =cut
1013  
1014 1 ▶sub start_trace {
Subroutine start_trace: called CC=2 SCAR=7.6
Pod undocumented
1015 1 my ($self)=@_;
1016 1 $self->reset;
1017 1 ▶ if(defined($AGENT)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $AGENT) 0 1 1
1018 0 $self->existing_trace($AGENT);
1019 0 $AGENT->pause_trace;
1020 }
1021 1 $self->trace_id($self->trace_id +1);
1022 1 $AGENT=$self;
1023 }
1024  
1025  
1026 =head2 $self->stop_trace
1027  
1028 Ends the current stack trace process.
1029  
1030 =cut
1031  
1032 1 ▶sub stop_trace {
Subroutine stop_trace: called CC=2 SCAR=7.2
Pod undocumented
1033 1 my ($self)=@_;
1034 1 $self->close_to(1);
1035 1 $AGENT=undef;
1036 1 $AGENT=$self->existing_trace();
1037 1 ▶ if(defined($AGENT)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $AGENT) 0 1 1
1038 0 $AGENT->resume_trace;
1039 }
1040 }
1041  
1042 =head2 $self->pause_trace
1043  
1044 Turns tracing off until a call to $self->restore_trace is made
1045  
1046 =cut
1047  
1048 0 ▶sub pause_trace {
Subroutine pause_trace: not called CC=1 SCAR=6.9
Pod undocumented
1049 0 my ($self)=@_;
1050 0 $AGENT=undef;
1051 0 $IN_METHOD=0;
1052 }
1053  
1054 =head2 $self->restore_trace
1055  
1056 Turns tracking back on.
1057  
1058 =cut
1059  
1060 0 ▶sub restore_trace {
Subroutine restore_trace: not called CC=1 SCAR=6.9
Pod undocumented
1061 0 my ($self)=@_;
1062 0 $AGENT=$self;
1063 }
1064  
1065 =head2 $self->close_sub($res)
1066  
1067 This method is called by the sub method. It is used to send notice that a frame has finished execution.
1068  
1069 =cut
1070  
1071 0 ▶sub close_sub {
Subroutine close_sub: not called CC=2 SCAR=17.9
Pod undocumented
1072 0 my ($self,$res)=@_;
1073 0 $self->pause_trace;
1074 0 my $level=pop $self->{level}->@*;
1075  
1076 0 ▶ if($level->$#*==0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($level->$#* == 0) 0 0 0
1077 0 $self->restore_trace;
1078 0 return;
1079 }
1080 0 my $depth=$level->[1];
1081 0 my $last=$self->{depths}->[$depth];
1082 0 $self->close_to($depth);
1083 0 $self->{process_result}->($self,$res,$last);
1084 0 $self->restore_trace;
1085 }
1086  
1087 =head2 my $frames=$self->grab_missing($depth,$frame);
1088  
1089 Returns any skiped frames between $depth and $frame.
1090  
1091 $depth is expected to be a number and $frame expected to be a frame hash.
1092  
1093 =cut
1094  
1095 0 ▶sub grab_missing {
Subroutine grab_missing: not called CC=5 SCAR=34.0
Pod undocumented
1096 0 my ($self,$depth,$frame)=@_;
1097 0 my $missing=[];
1098  
1099 0 ▶ $depth=1 if $depth <1;
Branch: 1 branch
BranchTrueFalseTotal
if $depth < 1 0 0 0
1100  
1101 0 ▶ return $missing if $depth > $frame->{depth};
Branch: 1 branch
BranchTrueFalseTotal
if $depth > $frame->{"depth"} 0 0 0
1102 # stop here if these are both the same depth
1103 0 ▶ return $missing if($depth==$frame->{depth});
Branch: 1 branch
BranchTrueFalseTotal
if $depth == $frame->{"depth"} 0 0 0
1104  
1105 0 ▶ for(;$depth<$frame->{depth};++$depth) {
Branch: 1 branch
BranchTrueFalseTotal
if ($depth < $frame->{"depth"}) 0 0 0
1106 0 push $missing->@*,$self->{depths}->[$depth];
1107 }
1108 0 return $missing;
1109 }
1110  
1111 =head2 DB(@_)
1112  
1113 This method is manditory for the implemntation of a debugger. With the current perl internals it is called every time a breakable point of code is reached. Unfortunatly this overhead is unavoidable.
1114  
1115 Example:
1116  
1117 foreach(1,3,4) { # Debugger would normally stop here
1118 someMethod($_) # agent tracing only happens when your function is called
1119 }
1120  
1121 # total calls would be 4 + 3 * 2
1122 # 1 call when foreach is reached
1123 # 1 call for each element in the loop
1124 # 2 times for every method
1125  
1126 The as an optimization the agent ensures that tracing only happens on user defined functions. All other operations should be ignored.
1127  
1128 The optimization reduces the number of calls to 3 or just once per method.
1129  
1130 =cut
1131  
1132 0 ▶sub DB {
Subroutine DB: not called CC=2 SCAR=17.9
Pod undocumented
1133 0 ▶ return unless $IN_METHOD;
Branch: 1 branch
BranchTrueFalseTotal
unless $IN_METHOD 0 0 0
1134 0 $IN_METHOD=0;
1135 0 $AGENT->filter([caller 1],\@_);
1136 }
1137  
1138 =head2 sub(@_)
1139  
1140 THis is a manditory for implementation, this method is called twice per user defined method. Once before the execution once to actually run the function.
1141  
1142 Example:
1143  
1144 foreach(1,3,4) {
1145 someMethod($_) # sub is called 2 times per function
1146 }
1147  
1148 # calls to sub 6
1149  
1150 If $AGENT is undef, this method does nothing.
1151  
1152 =cut
1153  
1154 0 ▶sub sub {
Subroutine sub: not called CC=17 SCAR=55.7
Pod documented
1155 0 ▶ if($IN_METHOD
Branch: 1 branch
BranchTrueFalseTotal
if ($IN_METHOD or not defined $AGENT or $internals or substr($DB::sub, 0, 4) eq "DB::" or ${^GLOBAL_PHASE} ne "RUN") 0 0 0
Condition0%0/12
$IN_METHOD or not defined $AGENT or $internals or substr($DB::sub, 0, 4) eq "DB::" or ${^GLOBAL_PHASE} ne "RUN"
l!l&&r!l&&!r
000
$IN_METHOD or not defined $AGENT or $internals or substr($DB::sub, 0, 4) eq "DB::"
l!l&&r!l&&!r
000
$IN_METHOD or not defined $AGENT or $internals
l!l&&r!l&&!r
000
$IN_METHOD or not defined $AGENT
l!l&&r!l&&!r
000
MC/DC0%0/5
$IN_METHOD or not defined $AGENT or $internals or substr($DB::sub, 0, 4) eq "DB::" or ${^GLOBAL_PHASE} ne "RUN"
$IN_METHOD not defined $AGENT $internals substr($DB::sub, 0, 4) eq "DB::" ${^GLOBAL_PHASE} ne "RUN"
Truth table0%0/6
A or not(B) or C or D or E
A= $IN_METHODB= not defined $AGENTC= $internalsD= substr($DB::sub, 0, 4) eq "DB::"E= ${^GLOBAL_PHASE} ne "RUN"
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
1156 || !defined($AGENT)
1157 || $internals
1158 || substr($DB::sub,0,4) eq 'DB::'
1159 || ${^GLOBAL_PHASE} ne 'RUN'
1160 ) {
1161 0 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.4
1162 0 return &$DB::sub
1163 }
1164
1165
1166 0 ▶ if(ref($DB::sub)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $DB::sub) 0 0 0
1167 0 my $name=svref_2object($DB::sub)->GV->NAME;
1168 0 ▶ if(defined($name) && exists $AGENT->{ignore_blocks}->{$name}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $name and exists $DB::AGENT->{"ignore_blocks"}{$name}) 0 0 0
Condition0%0/3
defined $name and exists $DB::AGENT->{"ignore_blocks"}{$name}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $name and exists $DB::AGENT->{"ignore_blocks"}{$name}
defined $name exists $DB::AGENT->{"ignore_blocks"}{$name}
Truth table0%0/3
A and B
A= defined $nameB= exists $DB::AGENT->{"ignore_blocks"}{$name}
ABresult
0X0
100
111
1169 0 my $agent=$AGENT;
1170 0 $IN_METHOD=0;
1171 0 $AGENT=undef;
1172 0 ▶ if(wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 0 0 0
1173 0 @DB::ret = &$DB::sub;
1174 0 $AGENT=$agent;
1175 0 my @list=@DB::ret;
1176 0 @DB::ret=();
1177 0 return @list;
1178 } else {
1179 0 $DB::ret = &$DB::sub;
1180 0 $AGENT=$agent;
1181 0 return $DB::ret;
1182 }
1183 }
1184 }
1185 0 push $AGENT->{level}->@*,[$DB::sub];
1186  
1187 0 $IN_METHOD=1;
1188
1189 0 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.4
1190 0 ▶ if ($DB::sub eq 'DESTROY' or substr($DB::sub, -9) eq '::DESTROY' or not defined wantarray) {
Branch: 2 branches
BranchTrueFalseTotal
if ($DB::sub eq 'DESTROY' or substr($DB::sub, -9) eq '::DESTROY' or not defined wantarray) { } 0 0 0
elsif (wantarray) { } 0 0 0
Condition0%0/6
$DB::sub eq "DESTROY" or substr($DB::sub, -9) eq "::DESTROY" or not defined wantarray
l!l&&r!l&&!r
000
$DB::sub eq "DESTROY" or substr($DB::sub, -9) eq "::DESTROY"
l!l&&r!l&&!r
000
MC/DC0%0/3
$DB::sub eq "DESTROY" or substr($DB::sub, -9) eq "::DESTROY" or not defined wantarray
$DB::sub eq "DESTROY" substr($DB::sub, -9) eq "::DESTROY" not defined wantarray
Truth table0%0/4
A or B or not(C)
A= $DB::sub eq "DESTROY"B= substr($DB::sub, -9) eq "::DESTROY"C= not defined wantarray
ABCresult
1XX1
01X1
0011
0000
1191 0 $DB::ret=&$DB::sub;
1192 0 ▶ $AGENT->close_sub(-1) if defined $AGENT;
Branch: 1 branch
BranchTrueFalseTotal
if defined $AGENT 0 0 0
1193 0 $DB::ret = undef;
1194 } elsif (wantarray) {
1195 0 @DB::ret = &$DB::sub;
1196 0 ▶ $AGENT->close_sub(1) if defined $AGENT;
Branch: 1 branch
BranchTrueFalseTotal
if defined $AGENT 0 0 0
1197 0 @DB::ret;
1198 } else {
1199 0 $DB::ret = &$DB::sub;
1200 0 ▶ $AGENT->close_sub(0) if defined $AGENT;
Branch: 1 branch
BranchTrueFalseTotal
if defined $AGENT 0 0 0
1201 0 $DB::ret;
1202 }
1203 }
1204  
1205 3 ▶sub DESTROY {
Subroutine DESTROY: called CC=1 SCAR=0.0
1206 3 my ($self)=@_;
1207 3 $self->reset;
1208 }
1209  
1210 4 1;
1211  
1212 __END__
↑ Summary Devel/Agent/Util.pm »