| 1 | package Devel::CallSequence; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | =head1 NAME | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | CallSeq - produces call sequence outlines (like dprofpp -T) | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | perl -d:CallSeq script | ||||||||||||||||||||||||||||
| 10 | cat tmon.out | ||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | This profiler is designed to aid UML::Sequence in producing diagrams. | ||||||||||||||||||||||||||||
| 15 | See UML::Sequence::PerlSeq for instructions in its use. | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | The key difference between the output of this program and dprofpp -T is: | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | subroutine names show up correctly (DiePair::new not DiePair::BEGIN) | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | The output goes to tmon.out and looks like this: | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | main | ||||||||||||||||||||||||||||
| 24 | DiePair::new | ||||||||||||||||||||||||||||
| 25 | Die::new | ||||||||||||||||||||||||||||
| 26 | Die::new | ||||||||||||||||||||||||||||
| 27 | DiePair::roll | ||||||||||||||||||||||||||||
| 28 | Die::roll | ||||||||||||||||||||||||||||
| 29 | Die::roll | ||||||||||||||||||||||||||||
| 30 | DiePair::total | ||||||||||||||||||||||||||||
| 31 | DiePair::doubles | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | =cut | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | package DB; | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | use strict; | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | BEGIN { | ||||||||||||||||||||||||||||
| 40 | open TMON, ">tmon.out" or die "Couldn't open tmon.out\n"; | ||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | END { | ||||||||||||||||||||||||||||
| 43 | 0 | ▶ | close TMON; | ||||||||||||||||||||||||||
|
Subroutine
END: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | my $previous_frame; | ||||||||||||||||||||||||||||
| 47 | my $depth; | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | sub DB { | ||||||||||||||||||||||||||||
| 50 | 0 | ▶ | my ($pack) = caller(0); | ||||||||||||||||||||||||||
|
Subroutine
DB: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 51 | 0 | ▶ | return if ($pack =~ /Dumper/); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | 0 | my $frame = DB->new(); | |||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 0 | ▶ | unless ($frame->compare($previous_frame)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | 0 | ▶ | my $old_depth = $previous_frame->depth() if ref $previous_frame; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | 0 | my $new_depth = $frame ->depth(); | |||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 0 | ▶ | if (not defined $old_depth or $new_depth > $old_depth) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not defined $old_depth or $new_depth > $old_depth
MC/DC0%0/2
not defined $old_depth or $new_depth > $old_depth
not defined $old_depth
$new_depth > $old_depth
Truth table0%0/3
not(A) or B
A= not defined $old_depthB= $new_depth > $old_depth
| |||||||||||||||||||||||||||||
| 59 | 0 | print TMON " " x ($new_depth - 1); | |||||||||||||||||||||||||||
| 60 | 0 | ▶ | if (defined $frame->element(1)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | 0 | print TMON $frame->subname(1); | |||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | else { | ||||||||||||||||||||||||||||
| 64 | 0 | print TMON $frame->package(0); | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | 0 | print TMON "\n"; | |||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 0 | $previous_frame = $frame; | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | # I can't use the following package statement, caller doesn't set DB::args | ||||||||||||||||||||||||||||
| 74 | # unless it's called from the DB package. | ||||||||||||||||||||||||||||
| 75 | # package StackFrame; | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | sub new { | ||||||||||||||||||||||||||||
| 78 | 0 | ▶ | my $class = shift; | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 79 | 0 | my $i = 1; | |||||||||||||||||||||||||||
| 80 | 0 | my $frame = []; | |||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 0 | ▶ | while (my ($package, $file, $line, $subname) = caller($i++)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 83 | 0 | my $arg = $DB::args[0]; | |||||||||||||||||||||||||||
| 84 | 0 | push @$frame, { pack => $package, | |||||||||||||||||||||||||||
| 85 | file => $file, | ||||||||||||||||||||||||||||
| 86 | subname => $subname, | ||||||||||||||||||||||||||||
| 87 | arg => $arg, | ||||||||||||||||||||||||||||
| 88 | }; | ||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | 0 | return bless $frame, $class; | |||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | sub compare { | ||||||||||||||||||||||||||||
| 94 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
compare: not called CC=8 SCAR=42.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 95 | 0 | my $other = shift; | |||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 0 | ▶ | return 0 unless (ref $self and ref $other); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $self and ref $other
MC/DC0%0/2
ref $self and ref $other
ref $self
ref $other
Truth table0%0/3
A and B
A= ref $selfB= ref $other
| |||||||||||||||||||||||||||||
| 98 | 0 | ▶ | return 0 if (@$self != @$other); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 99 | 0 | foreach my $element (1 .. @$self) { | |||||||||||||||||||||||||||
| 100 | 0 | my $self_element = $self ->[$element]; | |||||||||||||||||||||||||||
| 101 | 0 | my $other_element = $other->[$element]; | |||||||||||||||||||||||||||
| 102 | no warnings; | ||||||||||||||||||||||||||||
| 103 | 0 | ▶ | return 0 if ($self_element->{pack} ne $other_element->{pack}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 104 | 0 | ▶ | return 0 if ($self_element->{file} ne $other_element->{file}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 105 | 0 | ▶ | return 0 if ($self_element->{subname} ne $other_element->{subname}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | 0 | return 1; | |||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | sub depth { | ||||||||||||||||||||||||||||
| 111 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
depth: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | 0 | ▶ | return 0 unless ref $self; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 114 | 0 | return @$self; | |||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | sub element { | ||||||||||||||||||||||||||||
| 118 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
element: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 119 | 0 | my $number = shift; | |||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | 0 | ▶ | return undef unless ref $self; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 122 | 0 | ▶ | if (defined $self->[$number]) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 123 | 0 | return $self->[$number]; | |||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||
| 125 | else { | ||||||||||||||||||||||||||||
| 126 | 0 | return undef; | |||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | sub package { | ||||||||||||||||||||||||||||
| 131 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
package: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 132 | 0 | my $element = shift; | |||||||||||||||||||||||||||
| 133 | 0 | ▶ | return undef unless ref $self; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | 0 | return $self->[$element]{pack}; | |||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | sub subname { | ||||||||||||||||||||||||||||
| 139 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
subname: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 140 | 0 | my $element = shift; | |||||||||||||||||||||||||||
| 141 | 0 | ▶ | return undef unless ref $self; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | 0 | return $self->[$element]{subname}; | |||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | sub arg { | ||||||||||||||||||||||||||||
| 147 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
arg: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 148 | 0 | my $element = shift; | |||||||||||||||||||||||||||
| 149 | 0 | ▶ | return undef unless ref $self; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | 0 | return $self->[$element]{arg}; | |||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | 1; | ||||||||||||||||||||||||||||