blib/lib/Devel/NYTProf/SubInfo.pm

filter: Statementstmt 92.5% 200 / 216 Branchbran 64.8% 61 / 94 Conditioncond 66.6% 32 / 48 MC/DCmcdc 46.1% 12 / 26 Subroutinesub 95.2% 40 / 42 Podpod 0.0% 0 / 28 totaltotal 75.9% 345 / 454 CC 81 SCAR 19.8
CC
81
Cov
82%
_fmt_sc
20.0
_merge_in_caller_info
14.5
normalize_for_test
14.0
CRAP 7.2
« blib/lib/Devel/NYTProf/Apache.pm ↑ Summary blib/lib/Devel/NYTProf/Util.pm »
1 package Devel::NYTProf::SubInfo; # sub_subinfo
2  
3 700 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 700 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 700 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 700 ▶use List::Util qw(min max);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 700 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 700 ▶use Devel::NYTProf::Util qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
11 trace_level
12 700 );
13 700 ▶use Devel::NYTProf::Constants qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
14 NYTP_SIi_FID NYTP_SIi_FIRST_LINE NYTP_SIi_LAST_LINE
15 NYTP_SIi_CALL_COUNT NYTP_SIi_INCL_RTIME NYTP_SIi_EXCL_RTIME
16 NYTP_SIi_SUB_NAME NYTP_SIi_PROFILE
17 NYTP_SIi_REC_DEPTH NYTP_SIi_RECI_RTIME NYTP_SIi_CALLED_BY
18 NYTP_SIi_elements
19  
20 NYTP_SCi_CALL_COUNT
21 NYTP_SCi_INCL_RTIME NYTP_SCi_EXCL_RTIME NYTP_SCi_RECI_RTIME
22 NYTP_SCi_REC_DEPTH NYTP_SCi_CALLING_SUB
23 NYTP_SCi_elements
24 700 );
25  
26 # extra constants for private elements
27 700 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
28 700 NYTP_SIi_meta => NYTP_SIi_elements + 1,
29 NYTP_SIi_cache => NYTP_SIi_elements + 2,
30 700 };
31  
32  
33 556736 ▶sub fid { shift->[NYTP_SIi_FID] || 0 }
Subroutine fid: called CC=2 SCAR=6.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
+(shift())->[0] or 0 282 556454 556736
34  
35 806114 ▶sub first_line { shift->[NYTP_SIi_FIRST_LINE] }
Subroutine first_line: called CC=1 SCAR=0.0
Pod undocumented
36  
37 420528 ▶sub last_line { shift->[NYTP_SIi_LAST_LINE] }
Subroutine last_line: called CC=1 SCAR=0.0
Pod undocumented
38  
39 405324 ▶sub calls { shift->[NYTP_SIi_CALL_COUNT] }
Subroutine calls: called CC=1 SCAR=0.0
Pod undocumented
40  
41 7 ▶sub incl_time { shift->[NYTP_SIi_INCL_RTIME] }
Subroutine incl_time: called CC=1 SCAR=0.0
Pod undocumented
42  
43 1 ▶sub excl_time { shift->[NYTP_SIi_EXCL_RTIME] }
Subroutine excl_time: called CC=1 SCAR=0.0
Pod undocumented
44  
45 2472420 ▶sub subname { shift->[NYTP_SIi_SUB_NAME] }
Subroutine subname: called CC=1 SCAR=0.0
Pod undocumented
46  
47 1 ▶sub subname_without_package {
Subroutine subname_without_package: called CC=1 SCAR=0.0
Pod undocumented
48 1 my $subname = shift->[NYTP_SIi_SUB_NAME];
49 1 $subname =~ s/.*:://;
50 1 return $subname;
51 }
52  
53 125111 ▶sub profile { shift->[NYTP_SIi_PROFILE] }
Subroutine profile: called CC=1 SCAR=0.0
Pod undocumented
54  
55 1 ▶sub package { (my $pkg = shift->subname) =~ s/^(.*)::.*/$1/; return $pkg }
Subroutine package: called CC=1 SCAR=0.0
Pod undocumented
56  
57 1 ▶sub recur_max_depth { shift->[NYTP_SIi_REC_DEPTH] }
Subroutine recur_max_depth: called CC=1 SCAR=0.0
Pod undocumented
58  
59 1 ▶sub recur_incl_time { shift->[NYTP_SIi_RECI_RTIME] }
Subroutine recur_incl_time: called CC=1 SCAR=0.0
Pod undocumented
60  
61  
62 # general purpose hash - mainly a hack to help kill off Reader.pm
63 125113 ▶sub meta { shift->[NYTP_SIi_meta()] ||= {} }
Subroutine meta: called CC=2 SCAR=6.9
Pod undocumented
Condition100%2/2
+(shift())->[12] ||= {}
l!l
14125099
MC/DC100%1/1
+(shift())->[12] ||= {}
+(shift())->[12]
Truth table100%2/2
A
A= +(shift())->[12]
Aresult
11
00
64 # general purpose cache
65 1 ▶sub cache { shift->[NYTP_SIi_cache()] ||= {} }
Subroutine cache: called CC=2 SCAR=7.6
Pod undocumented
Condition50%1/2
+(shift())->[13] ||= {}
l!l
01
MC/DC0%0/1
+(shift())->[13] ||= {}
+(shift())->[13]
Truth table50%1/2
A
A= +(shift())->[13]
Aresult
11
00
66  
67  
68 # { fid => { line => [ count, incl_time ] } }
69 125683 ▶sub caller_fid_line_places {
Subroutine caller_fid_line_places: called CC=3 SCAR=11.0
Pod undocumented
70 125683 my ($self, $merge_evals) = @_;
71 125683 ▶ carp "caller_fid_line_places doesn't merge evals yet" if $merge_evals;
Branch: 1 branch
BranchTrueFalseTotal
if $merge_evals 0 125683 125683
72 # shallow clone to remove fid 0 is_sub hack
73 125683 ▶ my %tmp = %{ $self->[NYTP_SIi_CALLED_BY] || {} };
Condition100%2/2
$self->[10] || {}
l!l
1237751908
MC/DC100%1/1
$self->[10] || {}
$self->[10]
Truth table100%2/2
A
A= $self->[10]
Aresult
11
00
74 125683 delete $tmp{0};
75 125683 return \%tmp;
76 }
77  
78 289 ▶sub called_by_subnames {
Subroutine called_by_subnames: called CC=3 SCAR=11.0
Pod undocumented
79 289 my ($self) = @_;
80 289 ▶ my $callers = $self->caller_fid_line_places || {};
Condition50%1/2
$self->caller_fid_line_places || {}
l!l
2890
MC/DC0%0/1
$self->caller_fid_line_places || {}
$self->caller_fid_line_places
Truth table50%1/2
A
A= $self->caller_fid_line_places
Aresult
11
00
81  
82 289 my %subnames;
83 289 for my $sc (map { values %$_ } values %$callers) {
84 322 my $caller_subnames = $sc->[NYTP_SCi_CALLING_SUB];
85 322 @subnames{ keys %$caller_subnames } = (); # viv keys
86 }
87  
88 289 return \%subnames;
89 }
90  
91 189921 ▶sub is_xsub {
Subroutine is_xsub: called CC=4 SCAR=13.9
Pod undocumented
92 189921 my $self = shift;
93  
94 # XXX should test == 0 but some xsubs still have undef first_line etc
95 # XXX shouldn't include opcode
96 189921 my $first = $self->first_line;
97 189921 ▶ return undef if not defined $first;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $first 128082 61839 189921
98 61839 ▶ return 1 if $first == 0 && $self->last_line == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $first == 0 and $self->last_line == 0 56163 5676 61839
Condition66%2/3
$first == 0 and $self->last_line == 0
!ll&&!rl&&r
5676056163
MC/DC50%1/2
$first == 0 and $self->last_line == 0
$first == 0 $self->last_line == 0
Truth table66%2/3
A and B
A= $first == 0B= $self->last_line == 0
ABresult
0X0
100
111
99 5676 return 0;
100 }
101  
102 244929 ▶sub is_opcode {
Subroutine is_opcode: called CC=4 SCAR=13.9
Pod undocumented
103 244929 my $self = shift;
104 244929 ▶ return 0 if $self->first_line or $self->last_line;
Branch: 1 branch
BranchTrueFalseTotal
if $self->first_line or $self->last_line 5676 239253 244929
Condition66%2/3
$self->first_line or $self->last_line
l!l&&r!l&&!r
56760239253
MC/DC50%1/2
$self->first_line or $self->last_line
$self->first_line $self->last_line
Truth table66%2/3
A or B
A= $self->first_lineB= $self->last_line
ABresult
1X1
011
000
105 239253 ▶ return 1 if $self->subname =~ m/(?:^CORE::|::CORE:)\w+$/;
Branch: 1 branch
BranchTrueFalseTotal
if $self->subname =~ /(?:^CORE::|::CORE:)\w+$/ 55008 184245 239253
106 184245 return 0;
107 }
108  
109 4451 ▶sub is_anon {
Subroutine is_anon: called CC=1 SCAR=0.0
Pod undocumented
110 4451 shift->subname =~ m/::__ANON__\b/;
111 }
112  
113 244929 ▶sub kind {
Subroutine kind: called CC=3 SCAR=11.0
Pod undocumented
114 244929 my $self = shift;
115 244929 ▶ return 'opcode' if $self->is_opcode;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_opcode 55008 189921 244929
116 189921 ▶ return 'xsub' if $self->is_xsub;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_xsub 56163 133758 189921
117 133758 return 'perl';
118 }
119  
120 1 ▶sub fileinfo {
Subroutine fileinfo: called CC=2 SCAR=7.4
Pod undocumented
121 1 my $self = shift;
122 1 my $fid = $self->fid;
123 1 ▶ if (!$fid) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($fid) 0 1 1
124 0 return undef; # sub not have a known fid
125 }
126 1 $self->profile->fileinfo_of($fid);
127 }
128  
129 2 ▶sub clone { # shallow
Subroutine clone: called CC=1 SCAR=0.0
Pod undocumented
130 2 my $self = shift;
131 2 return bless [ @$self ] => ref $self;
132 }
133  
134 10 ▶sub _min {
Subroutine _min: called CC=4 SCAR=14.6
135 10 my ($a, $b) = @_;
136 10 ▶ $a = $b if not defined $a;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $a 0 10 10
137 10 ▶ $b = $a if not defined $b;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $b 0 10 10
138 # either both are defined or both are undefined here
139 10 ▶ return undef unless defined $a;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $a 0 10 10
140 10 return min($a, $b);
141 }
142  
143 10 ▶sub _max {
Subroutine _max: called CC=4 SCAR=14.6
144 10 my ($a, $b) = @_;
145 10 ▶ $a = $b if not defined $a;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $a 0 10 10
146 10 ▶ $b = $a if not defined $b;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $b 0 10 10
147 # either both are defined or both are undefined here
148 10 ▶ return undef unless defined $a;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $a 0 10 10
149 10 return max($a, $b);
150 }
151  
152  
153 278227 ▶sub _alter_fileinfo {
Subroutine _alter_fileinfo: called CC=6 SCAR=19.3
154 278227 my ($self, $remove_fi, $new_fi) = @_;
155 278227 ▶ my $remove_fid = ($remove_fi) ? $remove_fi->fid : 0;
Branch: 1 branch
BranchTrueFalseTotal
$remove_fi ? : 0 278227 278227
156 278227 ▶ my $new_fid = ( $new_fi) ? $new_fi->fid : 0;
Branch: 1 branch
BranchTrueFalseTotal
$new_fi ? : 278227 0 278227
157  
158 278227 ▶ if ($self->fid == $remove_fid) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->fid == $remove_fid) 278227 0 278227
159 278227 $self->[NYTP_SIi_FID] = $new_fid;
160  
161 278227 ▶ $remove_fi->_remove_sub_defined($self) if $remove_fi;
Branch: 1 branch
BranchTrueFalseTotal
if $remove_fi 0 278227 278227
162 278227 ▶ $new_fi->_add_new_sub_defined($self) if $new_fi;
Branch: 1 branch
BranchTrueFalseTotal
if $new_fi 278227 0 278227
163 }
164 }
165  
166  
167 874 ▶sub _alter_called_by_fileinfo {
Subroutine _alter_called_by_fileinfo: called CC=10 SCAR=24.2
168 874 my ($self, $remove_fi, $new_fi) = @_;
169 874 ▶ my $remove_fid = ($remove_fi) ? $remove_fi->fid : 0;
Branch: 1 branch
BranchTrueFalseTotal
$remove_fi ? : 874 0 874
170 874 ▶ my $new_fid = ( $new_fi) ? $new_fi->fid : 0;
Branch: 1 branch
BranchTrueFalseTotal
$new_fi ? : 874 0 874
171  
172 # remove mentions of $remove_fid from called-by details
173 # { fid => { line => [ count, incl, excl, ... ] } }
174 874 ▶ if (my $called_by = $self->[NYTP_SIi_CALLED_BY]) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $called_by = $self->[10]) 874 0 874
175 874 my $cb = delete $called_by->{$remove_fid};
176  
177 874 ▶ if ($cb && $new_fid) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cb and $new_fid) 874 0 874
Condition33%1/3
$cb and $new_fid
!ll&&!rl&&r
00874
MC/DC0%0/2
$cb and $new_fid
$cb $new_fid
Truth table33%1/3
A and B
A= $cbB= $new_fid
ABresult
0X0
100
111
178 874 ▶ my $new_cb = $called_by->{$new_fid} ||= {};
Condition100%2/2
$called_by->{$new_fid} ||= {}
l!l
85321
MC/DC100%1/1
$called_by->{$new_fid} ||= {}
$called_by->{$new_fid}
Truth table100%2/2
A
A= $called_by->{$new_fid}
Aresult
11
00
179  
180 874 ▶ warn sprintf "_alter_called_by_fileinfo: %s from fid %d to fid %d\n",
Branch: 1 branch
BranchTrueFalseTotal
if trace_level() >= 4 0 874 874
181 $self->subname, $remove_fid, $new_fid
182 if trace_level() >= 4;
183  
184 # merge $cb into $new_cb
185 874 ▶ while ( my ($line, $cb_li) = each %$cb ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$cb) 875 874 1749
186 875 ▶ my $dst_line_info = $new_cb->{$line} ||= [];
Condition100%2/2
$new_cb->{$line} ||= []
l!l
85421
MC/DC100%1/1
$new_cb->{$line} ||= []
$new_cb->{$line}
Truth table100%2/2
A
A= $new_cb->{$line}
Aresult
11
00
187 875 _merge_in_caller_info($dst_line_info, delete $cb->{$line},
188 tag => "$line:".$self->subname,
189 );
190 }
191  
192 }
193 }
194  
195 }
196  
197  
198  
199  
200 # merge details of another sub into this one
201 # there are very few cases where this is sane thing to do
202 # it's meant for merging things like anon-subs in evals
203 # e.g., "PPI::Node::__ANON__[(eval 286)[PPI/Node.pm:642]:4]"
204 10 ▶sub merge_in {
Subroutine merge_in: called CC=9 SCAR=22.1
Pod undocumented
205 10 my ($self, $donor, %opts) = @_;
206 10 my $self_subname = $self->subname;
207 10 my $donor_subname = $donor->subname;
208  
209 10 ▶ warn sprintf "Merging sub %s into %s (%s)\n",
Branch: 1 branch
BranchTrueFalseTotal
if trace_level() >= 4 0 10 10
210 $donor_subname, $self_subname, join(" ", %opts)
211 if trace_level() >= 4;
212  
213 # see also "case NYTP_TAG_SUB_CALLERS:" in load_profile_data_from_stream()
214 10 push @{ $self->meta->{merged_sub_names} }, $donor->subname;
215  
216 10 $self->[NYTP_SIi_FIRST_LINE] = _min($self->[NYTP_SIi_FIRST_LINE], $donor->[NYTP_SIi_FIRST_LINE]);
217 10 $self->[NYTP_SIi_LAST_LINE] = _max($self->[NYTP_SIi_LAST_LINE], $donor->[NYTP_SIi_LAST_LINE]);
218 10 $self->[NYTP_SIi_CALL_COUNT] += $donor->[NYTP_SIi_CALL_COUNT];
219 10 $self->[NYTP_SIi_INCL_RTIME] += $donor->[NYTP_SIi_INCL_RTIME];
220 10 $self->[NYTP_SIi_EXCL_RTIME] += $donor->[NYTP_SIi_EXCL_RTIME];
221 10 $self->[NYTP_SIi_REC_DEPTH] = max($self->[NYTP_SIi_REC_DEPTH], $donor->[NYTP_SIi_REC_DEPTH]);
222 # adding reci_rtime is correct only if one sub doesn't call the other
223 10 $self->[NYTP_SIi_RECI_RTIME] += $donor->[NYTP_SIi_RECI_RTIME]; # XXX
224  
225 # { fid => { line => [ count, incl_time, ... ] } }
226 10 ▶ my $dst_called_by = $self ->[NYTP_SIi_CALLED_BY] ||= {};
Condition100%2/2
$self->[10] ||= {}
l!l
82
MC/DC100%1/1
$self->[10] ||= {}
$self->[10]
Truth table100%2/2
A
A= $self->[10]
Aresult
11
00
227 10 ▶ my $src_called_by = $donor->[NYTP_SIi_CALLED_BY] || {};
Condition100%2/2
$donor->[10] || {}
l!l
82
MC/DC100%1/1
$donor->[10] || {}
$donor->[10]
Truth table100%2/2
A
A= $donor->[10]
Aresult
11
00
228  
229 10 ▶ $opts{opts} ||= "merge in $donor_subname";
Condition50%1/2
$opts{"opts"} ||= "merge in $donor_subname"
l!l
010
MC/DC0%0/1
$opts{"opts"} ||= "merge in $donor_subname"
$opts{"opts"}
Truth table50%1/2
A
A= $opts{"opts"}
Aresult
11
00
230  
231 # iterate over src and merge into dst
232 10 ▶ while (my ($fid, $src_line_hash) = each %$src_called_by) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$src_called_by) 10 10 20
233  
234 10 my $dst_line_hash = $dst_called_by->{$fid};
235  
236 # merge lines in %$src_line_hash into %$dst_line_hash
237 10 for my $line (keys %$src_line_hash) {
238 18 ▶ my $dst_line_info = $dst_line_hash->{$line} ||= [];
Condition50%1/2
$dst_line_hash->{$line} ||= []
l!l
018
MC/DC0%0/1
$dst_line_hash->{$line} ||= []
$dst_line_hash->{$line}
Truth table50%1/2
A
A= $dst_line_hash->{$line}
Aresult
11
00
239 18 my $src_line_info = $src_line_hash->{$line};
240 18 ▶ delete $src_line_hash->{$line} unless $opts{src_keep};
Branch: 1 branch
BranchTrueFalseTotal
unless $opts{"src_keep"} 0 18 18
241 18 _merge_in_caller_info($dst_line_info, $src_line_info, %opts);
242 }
243 }
244  
245 10 return;
246 }
247  
248  
249 1768 ▶sub _merge_in_caller_info {
Subroutine _merge_in_caller_info: called CC=11 SCAR=26.7
250 1768 my ($dst_line_info, $src_line_info, %opts) = @_;
251 1768 ▶ my $tag = ($opts{tag}) ? " $opts{tag}" : "";
Branch: 1 branch
BranchTrueFalseTotal
$opts{'tag'} ? : 1750 18 1768
252  
253 1768 ▶ if (!@$src_line_info) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@$src_line_info) 0 1768 1768
254 0 ▶ carp sprintf "_merge_in_caller_info%s skipped (empty donor)", $tag
Branch: 1 branch
BranchTrueFalseTotal
if trace_level() 0 0 0
255 if trace_level();
256 0 return;
257 }
258  
259 1768 ▶ if (trace_level() >= 5) {
Branch: 1 branch
BranchTrueFalseTotal
if (trace_level() >= 5) 0 1768 1768
260 0 carp sprintf "_merge_in_caller_info%s merging from $src_line_info -> $dst_line_info:", $tag;
261 0 warn sprintf " . %s\n", _fmt_sc($src_line_info);
262 0 warn sprintf " + %s\n", _fmt_sc($dst_line_info);
263 }
264 1768 ▶ if (!@$dst_line_info) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@$dst_line_info) 60 1708 1768
265 60 @$dst_line_info = (0) x NYTP_SCi_elements;
266 60 $dst_line_info->[NYTP_SCi_CALLING_SUB] = undef;
267 }
268  
269 # merge @$src_line_info into @$dst_line_info
270 1768 $dst_line_info->[$_] += $src_line_info->[$_] for (
271 NYTP_SCi_CALL_COUNT, NYTP_SCi_INCL_RTIME, NYTP_SCi_EXCL_RTIME,
272 );
273 1768 $dst_line_info->[NYTP_SCi_REC_DEPTH] = max($dst_line_info->[NYTP_SCi_REC_DEPTH],
274 $src_line_info->[NYTP_SCi_REC_DEPTH]);
275 # ug, we can't really combine recursive incl_time, but this is better than undef
276 1768 $dst_line_info->[NYTP_SCi_RECI_RTIME] = max($dst_line_info->[NYTP_SCi_RECI_RTIME],
277 $src_line_info->[NYTP_SCi_RECI_RTIME]);
278  
279 1768 ▶ my $src_cs = $src_line_info->[NYTP_SCi_CALLING_SUB]|| {};
Condition50%1/2
$src_line_info->[7] || {}
l!l
17680
MC/DC0%0/1
$src_line_info->[7] || {}
$src_line_info->[7]
Truth table50%1/2
A
A= $src_line_info->[7]
Aresult
11
00
280 1768 ▶ my $dst_cs = $dst_line_info->[NYTP_SCi_CALLING_SUB]||={};
Condition100%2/2
$dst_line_info->[7] ||= {}
l!l
170860
MC/DC100%1/1
$dst_line_info->[7] ||= {}
$dst_line_info->[7]
Truth table100%2/2
A
A= $dst_line_info->[7]
Aresult
11
00
281 1768 $dst_cs->{$_} = $src_cs->{$_} for keys %$src_cs;
282  
283 1768 ▶ warn sprintf " = %s\n", _fmt_sc($dst_line_info)
Branch: 1 branch
BranchTrueFalseTotal
if trace_level() >= 5 0 1768 1768
284 if trace_level() >= 5;
285  
286 1768 return;
287 }
288  
289 0 ▶sub _fmt_sc {
Subroutine _fmt_sc: not called CC=4 SCAR=30.0
290 0 my ($sc) = @_;
291 0 ▶ return "(empty)" if !@$sc;
Branch: 1 branch
BranchTrueFalseTotal
unless @$sc 0 0 0
292 0 ▶ my $dst_cs = $sc->[NYTP_SCi_CALLING_SUB]||{};
Condition0%0/2
$sc->[7] || {}
l!l
00
MC/DC0%0/1
$sc->[7] || {}
$sc->[7]
Truth table0%0/2
A
A= $sc->[7]
Aresult
11
00
293 0 my $by = join " & ", sort keys %$dst_cs;
294 0 ▶ sprintf "calls %d%s",
Branch: 1 branch
BranchTrueFalseTotal
$by ? : 0 0 0
295 $sc->[NYTP_SCi_CALL_COUNT], ($by) ? ", by $by" : "";
296 }
297  
298  
299 0 ▶sub caller_fids {
Subroutine caller_fids: not called CC=2 SCAR=17.9
Pod undocumented
300 0 my ($self, $merge_evals) = @_;
301 0 ▶ my $callers = $self->caller_fid_line_places($merge_evals) || {};
Condition0%0/2
$self->caller_fid_line_places($merge_evals) || {}
l!l
00
MC/DC0%0/1
$self->caller_fid_line_places($merge_evals) || {}
$self->caller_fid_line_places($merge_evals)
Truth table0%0/2
A
A= $self->caller_fid_line_places($merge_evals)
Aresult
11
00
302 0 my @fids = keys %$callers;
303 0 return @fids; # count in scalar context
304 }
305  
306 1 ▶sub caller_count { return scalar shift->caller_places; } # XXX deprecate later
Subroutine caller_count: called CC=1 SCAR=0.0
Pod undocumented
307  
308 # array of [ $fid, $line, $sub_call_info ], ...
309 125105 ▶sub caller_places {
Subroutine caller_places: called CC=4 SCAR=13.9
Pod undocumented
310 125105 my ($self, $merge_evals) = @_;
311 125105 ▶ my $callers = $self->caller_fid_line_places || {};
Condition50%1/2
$self->caller_fid_line_places || {}
l!l
1251050
MC/DC0%0/1
$self->caller_fid_line_places || {}
$self->caller_fid_line_places
Truth table50%1/2
A
A= $self->caller_fid_line_places
Aresult
11
00
312  
313 125105 my @callers;
314 125105 for my $fid (sort { $a <=> $b } keys %$callers) {
315 130384 my $lines_hash = $callers->{$fid};
316 130384 for my $line (sort { $a <=> $b } keys %$lines_hash) {
317 198075 push @callers, [ $fid, $line, $lines_hash->{$line} ];
318 }
319 }
320  
321 125105 return @callers; # scalar: number of distinct calling locations
322 }
323  
324 125109 ▶sub normalize_for_test {
Subroutine normalize_for_test: called CC=14 SCAR=26.4
Pod undocumented
325 125109 my $self = shift;
326 125109 my $profile = $self->profile;
327  
328 # normalize eval sequence numbers in anon sub names to 0
329 $self->[NYTP_SIi_SUB_NAME] =~ s/ \( ((?:re_)?) eval \s \d+ \) /(${1}eval 0)/xg
330 if $self->[NYTP_SIi_SUB_NAME] =~ m/__ANON__/
331 125109 ▶ && not $ENV{NYTPROF_TEST_SKIP_EVAL_NORM};
Branch: 1 branch
BranchTrueFalseTotal
if $self->[6] =~ /__ANON__/ and not $ENV{"NYTPROF_TEST_SKIP_EVAL_NORM"} 4934 120175 125109
Condition100%3/3
$self->[6] =~ /__ANON__/ and not $ENV{"NYTPROF_TEST_SKIP_EVAL_NORM"}
!ll&&!rl&&r
1194367394934
MC/DC100%2/2
$self->[6] =~ /__ANON__/ and not $ENV{"NYTPROF_TEST_SKIP_EVAL_NORM"}
$self->[6] =~ /__ANON__/ not $ENV{"NYTPROF_TEST_SKIP_EVAL_NORM"}
Truth table100%3/3
A and not(B)
A= $self->[6] =~ /__ANON__/B= not $ENV{"NYTPROF_TEST_SKIP_EVAL_NORM"}
ABresult
0X0
100
111
332  
333 # zero subroutine inclusive time
334 125109 $self->[NYTP_SIi_INCL_RTIME] = 0;
335 125109 $self->[NYTP_SIi_EXCL_RTIME] = 0;
336 125109 $self->[NYTP_SIi_RECI_RTIME] = 0;
337  
338 # { fid => { line => [ count, incl, excl, ... ] } }
339 125109 ▶ my $callers = $self->[NYTP_SIi_CALLED_BY] || {};
Condition100%2/2
$self->[10] || {}
l!l
1231991910
MC/DC100%1/1
$self->[10] || {}
$self->[10]
Truth table100%2/2
A
A= $self->[10]
Aresult
11
00
340  
341 # calls from modules shipped with perl cause problems for tests
342 # because the line numbers vary between perl versions, so here we
343 # edit the line number of calls from these modules
344 125109 for my $fid (keys %$callers) {
345 187310 ▶ next if not $fid;
Branch: 1 branch
BranchTrueFalseTotal
unless $fid 56924 130386 187310
346 130386 ▶ my $fileinfo = $profile->fileinfo_of($fid) or next;
Branch: 1 branch
BranchTrueFalseTotal
my $fileinfo = $profile->fileinfo_of($fid) or next 130386 0 130386
347 130386 ▶ next if $fileinfo->filename !~ /(AutoLoader|Exporter)\.pm$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $fileinfo->filename =~ /(AutoLoader|Exporter)\.pm$/ 130242 144 130386
348  
349 # normalize the lines X,Y,Z to 1,2,3
350 144 my %lines = %{ delete $callers->{$fid} };
351 144 my @lines = @lines{sort { $a <=> $b } keys %lines};
352 144 $callers->{$fid} = { map { $_ => shift @lines } 1..@lines };
353 }
354  
355 125109 for my $sc (map { values %$_ } values %$callers) {
356 # zero per-call-location subroutine inclusive time
357 198078 $sc->[NYTP_SCi_INCL_RTIME] =
358 $sc->[NYTP_SCi_EXCL_RTIME] =
359 $sc->[NYTP_SCi_RECI_RTIME] = 0;
360  
361 198078 ▶ if (not $ENV{NYTPROF_TEST_SKIP_EVAL_NORM}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ENV{"NYTPROF_TEST_SKIP_EVAL_NORM"}) 177069 21009 198078
362 # normalize eval sequence numbers in anon sub names to 0
363 177069 ▶ my $names = $sc->[NYTP_SCi_CALLING_SUB]||{};
Condition50%1/2
$sc->[7] || {}
l!l
1770690
MC/DC0%0/1
$sc->[7] || {}
$sc->[7]
Truth table50%1/2
A
A= $sc->[7]
Aresult
11
00
364 177069 for my $subname (keys %$names) {
365 177492 (my $newname = $subname) =~ s/ \( ((?:re_)?) eval \s \d+ \) /(${1}eval 0)/xg;
366 177492 ▶ next if $newname eq $subname;
Branch: 1 branch
BranchTrueFalseTotal
if $newname eq $subname 177428 64 177492
367 warn "Normalizing $subname to $newname overwrote other calling-sub data\n"
368 64 ▶ if $names->{$newname};
Branch: 1 branch
BranchTrueFalseTotal
if $names->{$newname} 0 64 64
369 64 $names->{$newname} = delete $names->{$subname};
370 }
371 }
372  
373 }
374 125109 return $self->[NYTP_SIi_SUB_NAME];
375 }
376  
377 125103 ▶sub dump {
Subroutine dump: called CC=7 SCAR=19.7
Pod undocumented
378 125103 my ($self, $separator, $fh, $path, $prefix) = @_;
379  
380 125103 my ($fid, $l1, $l2, $calls) = @{$self}[
381 NYTP_SIi_FID, NYTP_SIi_FIRST_LINE, NYTP_SIi_LAST_LINE, NYTP_SIi_CALL_COUNT
382 ];
383 125103 my @values = @{$self}[
384 NYTP_SIi_INCL_RTIME, NYTP_SIi_EXCL_RTIME,
385 NYTP_SIi_REC_DEPTH, NYTP_SIi_RECI_RTIME
386 ];
387 printf $fh "%s[ %s:%s-%s calls %s times %s ]\n",
388 $prefix,
389 500412 ▶ map({ defined($_) ? $_ : 'undef' } $fid, $l1, $l2, $calls),
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 367944 132468 500412
390 125103 ▶ join(" ", map { defined($_) ? $_ : 'undef' } @values);
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 500412 0 500412
391  
392 125103 my @caller_places = $self->caller_places;
393 125103 for my $cp (@caller_places) {
394 198069 my ($fid, $line, $sc) = @$cp;
395 198069 my @sc = @$sc;
396 198069 $sc[NYTP_SCi_CALLING_SUB] = join "|", sort keys %{ $sc[NYTP_SCi_CALLING_SUB] };
397 printf $fh "%s%s%s%d:%d%s[ %s ]\n",
398 $prefix,
399 'called_by', $separator,
400 $fid, $line, $separator,
401 198069 ▶ join(" ", map { defined($_) ? $_ : 'undef' } @sc);
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 1584552 0 1584552
402 }
403  
404 # where a sub has had others merged into it, list them
405 125103 ▶ my $merge_subs = $self->meta->{merged_sub_names} || [];
Condition50%1/2
$self->meta->{'merged_sub_names'} || []
l!l
0125103
MC/DC0%0/1
$self->meta->{'merged_sub_names'} || []
$self->meta->{'merged_sub_names'}
Truth table50%1/2
A
A= $self->meta->{'merged_sub_names'}
Aresult
11
00
406 125103 for my $ms (sort @$merge_subs) {
407 0 printf $fh "%s%s%s%s\n",
408 $prefix, 'merge_donor', $separator, $ms;
409 }
410 }
411  
412 # vim:ts=8:sw=4:et
413 700 1;
« blib/lib/Devel/NYTProf/Apache.pm ↑ Summary blib/lib/Devel/NYTProf/Util.pm »