blib/lib/Devel/NYTProf/FileInfo.pm

filter: Statementstmt 83.8% 228 / 272 Branchbran 59.8% 61 / 102 Conditioncond 65.2% 30 / 46 MC/DCmcdc 48.0% 12 / 25 Subroutinesub 97.8% 45 / 46 Podpod 5.7% 2 / 35 totaltotal 71.8% 378 / 526 CC 95 SCAR 39.8
CC
95
Cov
76%
collapse_sibling_evals
183.3
outer
19.0
dump
12.0
CRAP 53.4
« blib/lib/Devel/NYTProf/Reader.pm ↑ Summary blib/lib/Devel/NYTProf/Constants.pm »
1 package Devel::NYTProf::FileInfo; # fid_fileinfo
2  
3 =head1 NAME
4  
5 Devel::NYTProf::FileInfo
6  
7 =head1 METHODS
8  
9 =cut
10  
11 700 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 700 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 700 ▶use Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 700 ▶use List::Util qw(sum);
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 700 ▶use Devel::NYTProf::Util qw(strip_prefix_from_paths trace_level);
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 700 ▶use Devel::NYTProf::Constants qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
20 NYTP_FIDf_HAS_SRC NYTP_FIDf_SAVE_SRC NYTP_FIDf_IS_FAKE NYTP_FIDf_IS_PMC
21 NYTP_FIDf_IS_EVAL
22  
23 NYTP_FIDi_FILENAME NYTP_FIDi_EVAL_FID NYTP_FIDi_EVAL_LINE NYTP_FIDi_FID
24 NYTP_FIDi_FLAGS NYTP_FIDi_FILESIZE NYTP_FIDi_FILEMTIME NYTP_FIDi_PROFILE
25 NYTP_FIDi_EVAL_FI NYTP_FIDi_HAS_EVALS NYTP_FIDi_SUBS_DEFINED NYTP_FIDi_SUBS_CALLED
26 NYTP_FIDi_elements
27  
28 NYTP_SCi_CALL_COUNT NYTP_SCi_INCL_RTIME NYTP_SCi_EXCL_RTIME NYTP_SCi_RECI_RTIME
29 NYTP_SCi_REC_DEPTH NYTP_SCi_CALLING_SUB
30 NYTP_SCi_elements
31 700 );
32  
33 # extra constants for private elements
34 700 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
35 700 NYTP_FIDi_meta => NYTP_FIDi_elements + 1,
36 NYTP_FIDi_cache => NYTP_FIDi_elements + 2,
37 700 };
38  
39 558588 ▶sub filename { shift->[NYTP_FIDi_FILENAME()] }
Subroutine filename: called CC=1 SCAR=0.0
Pod undocumented
40 6603 ▶sub eval_fid { shift->[NYTP_FIDi_EVAL_FID()] }
Subroutine eval_fid: called CC=1 SCAR=0.0
Pod undocumented
41 43821 ▶sub eval_line { shift->[NYTP_FIDi_EVAL_LINE()] }
Subroutine eval_line: called CC=1 SCAR=0.0
Pod undocumented
42 927800 ▶sub fid { shift->[NYTP_FIDi_FID()] }
Subroutine fid: called CC=1 SCAR=0.0
Pod undocumented
43 1 ▶sub size { shift->[NYTP_FIDi_FILESIZE()] }
Subroutine size: called CC=1 SCAR=0.0
Pod undocumented
44 1 ▶sub mtime { shift->[NYTP_FIDi_FILEMTIME()] }
Subroutine mtime: called CC=1 SCAR=0.0
Pod undocumented
45 96586 ▶sub profile { shift->[NYTP_FIDi_PROFILE()] }
Subroutine profile: called CC=1 SCAR=0.0
Pod undocumented
46 15032 ▶sub flags { shift->[NYTP_FIDi_FLAGS()] }
Subroutine flags: called CC=1 SCAR=0.0
Pod undocumented
47  
48 # if an eval then return fileinfo obj for the fid that executed the eval
49 18 ▶sub eval_fi { shift->[NYTP_FIDi_EVAL_FI()] }
Subroutine eval_fi: called CC=1 SCAR=0.0
Pod undocumented
50 # is_eval is true only for simple string evals (doesn't consider NYTP_FIDf_IS_EVAL)
51 12314 ▶sub is_eval { shift->[NYTP_FIDi_EVAL_FI()] ? 1 : 0 }
Subroutine is_eval: called CC=2 SCAR=6.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
+(shift())->[8] ? : 1868 10446 12314
52  
53 339 ▶sub is_fake { shift->flags & NYTP_FIDf_IS_FAKE }
Subroutine is_fake: called CC=1 SCAR=0.0
Pod undocumented
54 4 ▶sub is_file {
Subroutine is_file: called CC=3 SCAR=14.2
Pod undocumented
55 4 my $self = shift;
56 4 ▶ return not ($self->is_fake or $self->is_eval or $self->flags & NYTP_FIDf_IS_EVAL());
Condition33%2/6
$self->is_fake || $self->is_eval || $self->flags & 256
l!l&&r!l&&!r
004
$self->is_fake or $self->is_eval
l!l&&r!l&&!r
004
MC/DC0%0/3
$self->is_fake || $self->is_eval || $self->flags & 256
$self->is_fake $self->is_eval $self->flags & 256
Truth table25%1/4
A or B || C
A= $self->is_fakeB= $self->is_evalC= $self->flags & 256
ABCresult
1XX1
01X1
0011
0000
57 }
58  
59 # general purpose hash - mainly a hack to help kill off Reader.pm
60 37343 ▶sub meta { shift->[NYTP_FIDi_meta()] ||= {} }
Subroutine meta: called CC=2 SCAR=6.9
Pod undocumented
Condition100%2/2
+(shift())->[13] ||= {}
l!l
300007343
MC/DC100%1/1
+(shift())->[13] ||= {}
+(shift())->[13]
Truth table100%2/2
A
A= +(shift())->[13]
Aresult
11
00
61 # general purpose cache
62 13982 ▶sub cache { shift->[NYTP_FIDi_cache()] ||= {} }
Subroutine cache: called CC=2 SCAR=6.9
Pod undocumented
Condition100%2/2
+(shift())->[14] ||= {}
l!l
86185364
MC/DC100%1/1
+(shift())->[14] ||= {}
+(shift())->[14]
Truth table100%2/2
A
A= +(shift())->[14]
Aresult
11
00
63  
64 # array of fileinfo's for each string eval in the file
65 65214 ▶sub has_evals {
Subroutine has_evals: called CC=4 SCAR=13.9
Pod undocumented
66 65214 my ($self, $include_nested) = @_;
67  
68 65214 ▶ my $eval_fis = $self->[NYTP_FIDi_HAS_EVALS()]
Branch: 1 branch
BranchTrueFalseTotal
my $eval_fis = $self->[9] or return 5231 59983 65214
69 or return;
70 5231 ▶ return @$eval_fis if !$include_nested;
Branch: 1 branch
BranchTrueFalseTotal
unless $include_nested 5023 208 5231
71  
72 208 my @eval_fis = @$eval_fis;
73 # walk down tree of nested evals, adding them to @fi
74 208 ▶ for (my $i=0; my $fi = $eval_fis[$i]; ++$i) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $fi = $eval_fis[$i]) 272 208 480
75 272 push @eval_fis, $fi->has_evals(0);
76 }
77  
78 208 return @eval_fis;
79 }
80  
81  
82 1 ▶sub sibling_evals {
Subroutine sibling_evals: called CC=2 SCAR=10.1
Pod undocumented
83 1 my ($self) = @_;
84 1 ▶ my $parent_fi = $self->eval_fi
Branch: 1 branch
BranchTrueFalseTotal
my $parent_fi = $self->eval_fi or return 0 1 1
85 or return; # not an eval
86 0 my $eval_line = $self->eval_line;
87 0 return grep { $_->eval_line == $eval_line } $parent_fi->has_evals;
88 }
89  
90  
91 3293 ▶sub _nullify {
Subroutine _nullify: called CC=1 SCAR=0.0
92 3293 my $self = shift;
93 3293 @$self = (); # Zap!
94 }
95  
96  
97  
98 # return subs defined as list of SubInfo objects
99 21811 ▶sub subs_defined {
Subroutine subs_defined: called CC=2 SCAR=7.4
Pod undocumented
100 21811 my ($self, $incl_nested_evals) = @_;
101  
102 0 ▶ return map { $_->subs_defined(0) } $self, $self->has_evals(1)
Branch: 1 branch
BranchTrueFalseTotal
if $incl_nested_evals 0 21811 21811
103 if $incl_nested_evals;
104  
105 21811 return values %{ $self->[NYTP_FIDi_SUBS_DEFINED()] };
106 }
107  
108 10069 ▶sub subs_defined_sorted {
Subroutine subs_defined_sorted: called CC=1 SCAR=0.0
Pod undocumented
109 10069 my ($self, $incl_nested_evals) = @_;
110 10069 return sort { $a->subname cmp $b->subname } $self->subs_defined($incl_nested_evals);
111 }
112  
113 0 ▶sub _remove_sub_defined {
Subroutine _remove_sub_defined: not called CC=2 SCAR=17.9
114 0 my ($self, $si) = @_;
115 0 my $subname = $si->subname;
116 0 ▶ delete $self->[NYTP_FIDi_SUBS_DEFINED()]->{$subname}
Branch: 1 branch
BranchTrueFalseTotal
delete $self->[10]{$subname} or carp(sprintf("_remove_sub_defined: sub %s wasn't defined in %d %s", $subname, $self->fid, $self->filename)) 0 0 0
117 or carp sprintf "_remove_sub_defined: sub %s wasn't defined in %d %s",
118 $subname, $self->fid, $self->filename;
119 }
120  
121 278227 ▶sub _add_new_sub_defined {
Subroutine _add_new_sub_defined: called CC=3 SCAR=11.2
122 278227 my ($self, $subinfo) = @_;
123 278227 my $subname = $subinfo->subname;
124 278227 ▶ my $subs_defined = $self->[NYTP_FIDi_SUBS_DEFINED()] ||= {};
Condition50%1/2
$self->[10] ||= {}
l!l
2782270
MC/DC0%0/1
$self->[10] ||= {}
$self->[10]
Truth table50%1/2
A
A= $self->[10]
Aresult
11
00
125 278227 my $existing_si = $subs_defined->{$subname};
126 278227 ▶ croak sprintf "sub %s already defined in fid %d %s",
Branch: 1 branch
BranchTrueFalseTotal
if $existing_si 0 278227 278227
127 $subname, $self->fid, $self->filename
128 if $existing_si;
129  
130 278227 $subs_defined->{$subname} = $subinfo;
131 }
132  
133  
134 =head2 sub_call_lines
135  
136 $hash = $fi->sub_call_lines;
137  
138 Returns a reference to a hash containing information about subroutine calls
139 made at individual lines within the source file.
140 Returns undef if no subroutine calling information is available.
141  
142 The keys of the returned hash are line numbers. The values are references to
143 hashes with fully qualified subroutine names as keys. Each hash value is an
144 reference to an array containing an integer call count (how many times the sub
145 was called from that line of that file) and an inclusive time (how much time
146 was spent inside the sub when it was called from that line of that file).
147  
148 For example, if the following was line 42 of a file C<foo.pl>:
149  
150 ++$wiggle if foo(24) == bar(42);
151  
152 that line was executed once, and foo and bar were imported from pkg1, then
153 sub_call_lines() would return something like:
154  
155 {
156 42 => {
157 'pkg1::foo' => [ 1, 0.02093 ],
158 'pkg1::bar' => [ 1, 0.00154 ],
159 },
160 }
161  
162 =cut
163  
164 39075 ▶sub sub_call_lines { shift->[NYTP_FIDi_SUBS_CALLED()] }
Subroutine sub_call_lines: called CC=1 SCAR=0.0
Pod documented
165  
166  
167 =head2 evals_by_line
168  
169 # { line => { fid_of_eval_at_line => $fi, ... }, ... }
170 $hash = $fi->evals_by_line;
171  
172 Returns a reference to a hash containing information about string evals
173 executed at individual lines within a source file.
174  
175 The keys of the returned hash are line numbers. The values are references to
176 hashes with file id integers as keys and FileInfo objects as values.
177  
178 =cut
179  
180 16419 ▶sub evals_by_line {
Subroutine evals_by_line: called CC=2 SCAR=6.9
Pod documented
181 16419 my ($self) = @_;
182  
183 # find all fids that have this fid as an eval_fid
184 # { line => { fid_of_eval_at_line => $fi, ... } }
185  
186 16419 my %evals_by_line;
187 16419 for my $fi ($self->has_evals) {
188 2232 $evals_by_line{ $fi->eval_line }->{ $fi->fid } = $fi;
189 }
190  
191 16419 return \%evals_by_line;
192 }
193  
194  
195 21343 ▶sub line_time_data {
Subroutine line_time_data: called CC=5 SCAR=16.1
Pod undocumented
196 21343 my ($self, $levels) = @_;
197 21343 ▶ $levels ||= [ 'line' ];
Condition100%2/2
$levels ||= ["line"]
l!l
164044939
MC/DC100%1/1
$levels ||= ["line"]
$levels
Truth table100%2/2
A
A= $levels
Aresult
11
00
198 # XXX this can be optimized once the fidinfo contains directs refs to the data
199 21343 my $profile = $self->profile;
200 21343 my $fid = $self->fid;
201 21343 for my $level (@$levels) {
202 21343 my $fid_ary = $profile->get_fid_line_data($level);
203 21343 ▶ return $fid_ary->[$fid] if $fid_ary && $fid_ary->[$fid];
Branch: 1 branch
BranchTrueFalseTotal
if $fid_ary and $fid_ary->[$fid] 19110 2233 21343
Condition66%2/3
$fid_ary and $fid_ary->[$fid]
!ll&&!rl&&r
0223319110
MC/DC50%1/2
$fid_ary and $fid_ary->[$fid]
$fid_ary $fid_ary->[$fid]
Truth table66%2/3
A and B
A= $fid_aryB= $fid_ary->[$fid]
ABresult
0X0
100
111
204 }
205 2233 return undef;
206 }
207  
208 1 ▶sub excl_time { # total exclusive time for fid
Subroutine excl_time: called CC=4 SCAR=13.9
Pod undocumented
209 1 my $self = shift;
210 1 ▶ my $line_data = $self->line_time_data([qw(sub block line)])
Condition50%1/2
$self->line_time_data(['sub', 'block', 'line']) || (return undef)
l!l
10
MC/DC0%0/1
$self->line_time_data(['sub', 'block', 'line']) || (return undef)
$self->line_time_data(['sub', 'block', 'line'])
Truth table50%1/2
A
A= $self->line_time_data(['sub', 'block', 'line'])
Aresult
11
00
211 || return undef;
212 1 my $excl_time = 0;
213 1 for (@$line_data) {
214 19 ▶ next unless $_;
Branch: 1 branch
BranchTrueFalseTotal
unless $_ 13 6 19
215 6 $excl_time += $_->[0];
216 }
217 1 return $excl_time;
218 }
219  
220  
221 16 ▶sub sum_of_stmts_count {
Subroutine sum_of_stmts_count: called CC=3 SCAR=11.8
Pod undocumented
222 16 my ($self, $incl_nested_evals) = @_;
223  
224 0 ▶ return sum(map { $_->sum_of_stmts_count(0) } $self, $self->has_evals(1))
Branch: 1 branch
BranchTrueFalseTotal
if $incl_nested_evals 0 16 16
225 if $incl_nested_evals;
226  
227 16 my $ref = \$self->cache->{NYTP_FIDi_sum_stmts_count};
228 16 ▶ $$ref = $self->_sum_of_line_time_data(1)
Branch: 1 branch
BranchTrueFalseTotal
unless defined $$ref 16 0 16
229 if not defined $$ref;
230  
231 16 return $$ref;
232 }
233  
234 2408 ▶sub sum_of_stmts_time {
Subroutine sum_of_stmts_time: called CC=3 SCAR=11.2
Pod undocumented
235 2408 my ($self, $incl_nested_evals) = @_;
236  
237 0 ▶ return sum(map { $_->sum_of_stmts_time(0) } $self, $self->has_evals(1))
Branch: 1 branch
BranchTrueFalseTotal
if $incl_nested_evals 0 2408 2408
238 if $incl_nested_evals;
239  
240 2408 my $ref = \$self->cache->{NYTP_FIDi_sum_stmts_times};
241 2408 ▶ $$ref = $self->_sum_of_line_time_data(0)
Branch: 1 branch
BranchTrueFalseTotal
unless defined $$ref 792 1616 2408
242 if not defined $$ref;
243  
244 2408 return $$ref;
245 }
246  
247 808 ▶sub _sum_of_line_time_data {
Subroutine _sum_of_line_time_data: called CC=3 SCAR=11.0
248 808 my ($self, $idx) = @_;
249 808 my $line_time_data = $self->line_time_data;
250 808 my $sum = 0;
251 808 ▶ $sum += $_->[$idx]||0 for @$line_time_data;
Condition100%2/2
$_->[$idx] || 0
l!l
980844
MC/DC100%1/1
$_->[$idx] || 0
$_->[$idx]
Truth table100%2/2
A
A= $_->[$idx]
Aresult
11
00
252 808 return $sum;
253 }
254  
255  
256 1 ▶sub outer {
Subroutine outer: called CC=5 SCAR=29.4
Pod undocumented
257 1 my ($self, $recurse) = @_;
258 1 ▶ my $fi = $self->eval_fi
Branch: 1 branch
BranchTrueFalseTotal
my $fi = $self->eval_fi or return 0 1 1
259 or return;
260 0 my $prev = $self;
261  
262 0 ▶ while ($recurse and my $eval_fi = $fi->eval_fi) {
Branch: 1 branch
BranchTrueFalseTotal
if ($recurse and my $eval_fi = $fi->eval_fi) 0 0 0
Condition0%0/3
$recurse and my $eval_fi = $fi->eval_fi
!ll&&!rl&&r
000
MC/DC0%0/2
$recurse and my $eval_fi = $fi->eval_fi
$recurse my $eval_fi = $fi->eval_fi
Truth table0%0/3
A and B
A= $recurseB= my $eval_fi = $fi->eval_fi
ABresult
0X0
100
111
263 0 $prev = $fi;
264 0 $fi = $eval_fi;
265 }
266 0 ▶ return $fi unless wantarray;
Branch: 1 branch
BranchTrueFalseTotal
unless wantarray 0 0 0
267 0 return ($fi, $prev->eval_line);
268 }
269  
270  
271 14688 ▶sub is_pmc {
Subroutine is_pmc: called CC=1 SCAR=0.0
Pod undocumented
272 14688 return (shift->flags & NYTP_FIDf_IS_PMC());
273 }
274  
275  
276 822 ▶sub collapse_sibling_evals {
Subroutine collapse_sibling_evals: called CC=38 SCAR=52.1
Pod undocumented
277 822 my ($self, $survivor_fi, @donors) = @_;
278 822 my $profile = $self->profile;
279  
280 die "Can't collapse_sibling_evals of non-sibling evals"
281 822 ▶ if grep { $_->eval_fid != $survivor_fi->eval_fid or
Branch: 1 branch
BranchTrueFalseTotal
if grep {$_->eval_fid != $survivor_fi->eval_fid or $_->eval_line != $survivor_fi->eval_line;} @donors 0 822 822
Condition33%1/3
$_->eval_fid != $survivor_fi->eval_fid || $_->eval_line != $survivor_fi->eval_line
l!l&&r!l&&!r
003293
MC/DC0%0/2
$_->eval_fid != $survivor_fi->eval_fid || $_->eval_line != $survivor_fi->eval_line
$_->eval_fid != $survivor_fi->eval_fid $_->eval_line != $survivor_fi->eval_line
Truth table33%1/3
A || B
A= $_->eval_fid != $survivor_fi->eval_fidB= $_->eval_line != $survivor_fi->eval_line
ABresult
1X1
011
000
282 $_->eval_line != $survivor_fi->eval_line
283 } @donors;
284  
285 822 my $s_ltd = $survivor_fi->line_time_data; # XXX line only
286 822 my $s_scl = $survivor_fi->sub_call_lines;
287 822 my %donor_fids;
288  
289 822 for my $donor_fi (@donors) {
290 # copy data from donor to survivor_fi then delete donor
291 3293 my $donor_fid = $donor_fi->fid;
292 3293 $donor_fids{$donor_fid} = $donor_fi;
293  
294 3293 ▶ warn sprintf "collapse_sibling_evals: processing donor fid %d: %s\n",
Branch: 1 branch
BranchTrueFalseTotal
if trace_level() >= 3 0 3293 3293
295 $donor_fid, $donor_fi->filename
296 if trace_level() >= 3;
297  
298 # XXX nested evals not handled yet
299 3293 ▶ warn sprintf "collapse_sibling_evals: nested evals in %s not handled",
Branch: 1 branch
BranchTrueFalseTotal
if $donor_fi->has_evals 0 3293 3293
300 $donor_fi->filename
301 if $donor_fi->has_evals;
302  
303 # for each sub defined in the donor,
304 # move the sub definition to the survivor
305 3293 ▶ if (my @subs_defined = $donor_fi->subs_defined) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@subs_defined) = $donor_fi->subs_defined) 0 3293 3293
306  
307 0 for my $si (@subs_defined) {
308 0 ▶ warn sprintf " - moving from fid %d: sub %s\n",
Branch: 1 branch
BranchTrueFalseTotal
if trace_level() >= 4 0 0 0
309 $donor_fid, $si->subname
310 if trace_level() >= 4;
311 0 $si->_alter_fileinfo($donor_fi, $survivor_fi);
312 0 ▶ warn sprintf " - moving done\n"
Branch: 1 branch
BranchTrueFalseTotal
if trace_level() >= 4 0 0 0
313 if trace_level() >= 4;
314 }
315 }
316  
317 # for each sub call made by the donor,
318 # move the sub calls to the survivor
319 # 1 => { 'main::foo' => [ 1, '1.38e-05', '1.24e-05', ..., { 'main::RUNTIME' => undef } ] }
320 3293 ▶ if (my $sub_call_lines = $donor_fi->sub_call_lines) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $sub_call_lines = $donor_fi->sub_call_lines) 3293 0 3293
321  
322 3293 my %subnames_called_by_donor;
323  
324 # merge details of subs called from $donor_fi
325 3293 ▶ while ( my ($line, $sc_hash) = each %$sub_call_lines ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$sub_call_lines) 874 3293 4167
326 874 ▶ my $s_sc_hash = $s_scl->{$line} ||= {};
Condition100%2/2
$s_scl->{$line} ||= {}
l!l
8704
MC/DC100%1/1
$s_scl->{$line} ||= {}
$s_scl->{$line}
Truth table100%2/2
A
A= $s_scl->{$line}
Aresult
11
00
327 874 for my $subname (keys %$sc_hash ) {
328 875 ▶ my $s_sc_info = $s_sc_hash->{$subname} ||= [];
Condition100%2/2
$s_sc_hash->{$subname} ||= []
l!l
85421
MC/DC100%1/1
$s_sc_hash->{$subname} ||= []
$s_sc_hash->{$subname}
Truth table100%2/2
A
A= $s_sc_hash->{$subname}
Aresult
11
00
329 875 my $sc_info = delete $sc_hash->{$subname};
330 875 Devel::NYTProf::SubInfo::_merge_in_caller_info($s_sc_info, $sc_info,
331 tag => "line $line calls to $subname",
332 );
333  
334 875 $subnames_called_by_donor{$subname}++;
335 }
336 }
337 3293 %$sub_call_lines = (); # zap
338  
339 # update subinfo (NYTP_SIi_CALLED_BY)
340 $profile->subinfo_of($_)->_alter_called_by_fileinfo($donor_fi, $survivor_fi)
341 3293 for keys %subnames_called_by_donor;
342 }
343  
344 # copy line time data
345 3293 ▶ my $d_ltd = $donor_fi->line_time_data || []; # XXX line only
Condition100%2/2
$donor_fi->line_time_data || []
l!l
3021272
MC/DC100%1/1
$donor_fi->line_time_data || []
$donor_fi->line_time_data
Truth table100%2/2
A
A= $donor_fi->line_time_data
Aresult
11
00
346 3293 for my $line (0..@$d_ltd-1) {
347 6106 ▶ my $d_tld_l = $d_ltd->[$line] or next;
Branch: 1 branch
BranchTrueFalseTotal
my $d_tld_l = $d_ltd->[$line] or next 3085 3021 6106
348 3085 ▶ my $s_tld_l = $s_ltd->[$line] ||= [];
Condition50%1/2
$s_ltd->[$line] ||= []
l!l
30850
MC/DC0%0/1
$s_ltd->[$line] ||= []
$s_ltd->[$line]
Truth table50%1/2
A
A= $s_ltd->[$line]
Aresult
11
00
349 3085 $s_tld_l->[$_] += $d_tld_l->[$_] for (0..@$d_tld_l-1);
350 3085 warn sprintf "%d:%d: @$s_tld_l from @$d_tld_l fid:%d\n",
351 $survivor_fi->fid, $line, $donor_fid if 0;
352 }
353  
354 3293 push @{ $survivor_fi->meta->{merged_fids} }, $donor_fid;
355 ++$survivor_fi->meta->{merged_fids_src_varied}
356 3293 ▶ if $donor_fi->src_digest ne $survivor_fi->src_digest;
Branch: 1 branch
BranchTrueFalseTotal
if $donor_fi->src_digest ne $survivor_fi->src_digest 0 3293 3293
357  
358 3293 $donor_fi->_nullify;
359 }
360  
361 # remove donors from parent NYTP_FIDi_HAS_EVALS
362 822 ▶ if (my $eval_fis = $self->[NYTP_FIDi_HAS_EVALS()]) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $eval_fis = $self->[9]) 822 0 822
363 822 my %donors = map { +"$_" => 1 } @donors;
364 822 my $count = @$eval_fis;
365 822 @$eval_fis = grep { !$donors{$_} } @$eval_fis;
366 822 ▶ warn "_delete_eval mismatch"
Branch: 1 branch
BranchTrueFalseTotal
if @$eval_fis != $count - @donors 0 822 822
367 if @$eval_fis != $count - @donors;
368 }
369  
370 # update sawampersand_fid if it's one of the now-dead donors
371 822 ▶ if ($donor_fids{ $profile->attributes->{sawampersand_fid} || 0 }) {
Branch: 1 branch
BranchTrueFalseTotal
if ($donor_fids{$profile->attributes->{"sawampersand_fid"} or 0}) 0 822 822
Condition50%1/2
$profile->attributes->{'sawampersand_fid'} || 0
l!l
0822
MC/DC0%0/1
$profile->attributes->{'sawampersand_fid'} || 0
$profile->attributes->{'sawampersand_fid'}
Truth table50%1/2
A
A= $profile->attributes->{'sawampersand_fid'}
Aresult
11
00
372 0 $profile->attributes->{sawampersand_fid} = $survivor_fi->fid;
373 }
374  
375 # now the fid merging is complete...
376 # look for any anon subs that are effectively duplicates
377 # (ie have the same name except for eval seqn)
378 # if more than one for any given name we merge them
379 822 ▶ if (my @subs_defined = $survivor_fi->subs_defined_sorted) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@subs_defined) = $survivor_fi->subs_defined_sorted) 0 822 822
380  
381 # bucket anon subs by normalized name
382 0 my %newname;
383 0 for my $si (@subs_defined) {
384 0 ▶ next unless $si->is_anon;
Branch: 1 branch
BranchTrueFalseTotal
unless $si->is_anon 0 0 0
385 0 (my $newname = $si->subname) =~ s/ \( ((?:re_)?) eval \s \d+ \) /(${1}eval 0)/xg;
386 0 push @{ $newname{$newname} }, $si;
387 }
388  
389 0 ▶ while ( my ($newname, $to_merge) = each %newname ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %newname) 0 0 0
390 0 my $survivor_si = shift @$to_merge;
391 0 ▶ next unless @$to_merge; # nothing to do
Branch: 1 branch
BranchTrueFalseTotal
unless @$to_merge 0 0 0
392  
393 0 my $survivor_subname = $survivor_si->subname;
394 warn sprintf "collapse_sibling_evals: merging %d subs into %s: %s\n",
395 scalar @$to_merge, $survivor_subname,
396 0 ▶ join ", ", map { $_->subname } @$to_merge
Branch: 1 branch
BranchTrueFalseTotal
if trace_level() >= 3 0 0 0
397 if trace_level() >= 3;
398  
399 0 for my $delete_si (@$to_merge) {
400 0 my $delete_subname = $delete_si->subname;
401  
402 # for every file that called this sub, find the lines that made the calls
403 # and change the name to the new sub
404 0 for my $caller_fid ($delete_si->caller_fids) {
405 0 my $caller_fi = $profile->fileinfo_of($caller_fid);
406 # sub_call_lines ==> { line => { sub => ... } }
407 0 for my $subs_called_on_line (values %{ $caller_fi->sub_call_lines }) {
408 0 ▶ my $sc_info = delete $subs_called_on_line->{$delete_subname}
Branch: 1 branch
BranchTrueFalseTotal
my $sc_info = delete $subs_called_on_line->{$delete_subname} or next 0 0 0
409 or next;
410 0 ▶ my $s_sc_info = $subs_called_on_line->{$survivor_subname} ||= [];
Condition0%0/2
$subs_called_on_line->{$survivor_subname} ||= []
l!l
00
MC/DC0%0/1
$subs_called_on_line->{$survivor_subname} ||= []
$subs_called_on_line->{$survivor_subname}
Truth table0%0/2
A
A= $subs_called_on_line->{$survivor_subname}
Aresult
11
00
411 0 Devel::NYTProf::SubInfo::_merge_in_caller_info($s_sc_info, $sc_info,
412 tag => "collapse eval $delete_subname",
413 );
414 }
415 }
416  
417 0 $survivor_si->merge_in($delete_si);
418 0 $survivor_fi->_remove_sub_defined($delete_si);
419 0 $profile->_disconnect_subinfo($delete_si);
420 }
421 }
422 }
423  
424 822 ▶ warn sprintf "collapse_sibling_evals done for ".$survivor_fi->filename."\n"
Branch: 1 branch
BranchTrueFalseTotal
if trace_level() >= 2 0 822 822
425 if trace_level() >= 2;
426  
427 822 return $survivor_fi;
428 }
429  
430  
431 # Should return the filename that the application used when loading the file
432 # For evals should remove the @INC portion from within the "(eval N)[$path]"
433 # and similarly for Class::MOP #line evals "... defined at $path".
434 # This is a bit of a fudge. Filename handling should be improved in the profiler.
435 25689 ▶sub filename_without_inc {
Subroutine filename_without_inc: called CC=1 SCAR=0.0
Pod undocumented
436 25689 my $self = shift;
437 25689 my $f = [$self->filename];
438 25689 strip_prefix_from_paths([$self->profile->inc], $f,
439 qr/(?: ^ | \[ | \sdefined\sat\s )/x
440 );
441 25689 return $f->[0];
442 }
443  
444  
445 14672 ▶sub abs_filename {
Subroutine abs_filename: called CC=5 SCAR=16.1
Pod undocumented
446 14672 my $self = shift;
447  
448 14672 my $filename = $self->filename;
449  
450 # strip of autosplit annotation, if any
451 14672 $filename =~ s/ \(autosplit into .*//;
452  
453 # if it's a .pmc then assume that's the file we want to look at
454 # (because the main use for .pmc's are related to perl6)
455 14672 ▶ $filename .= "c" if $self->is_pmc;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_pmc 24 14648 14672
456  
457 # search profile @INC if filename is not absolute
458 14672 my @files = ($filename);
459 14672 ▶ if ($filename !~ m/^\//) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($filename =~ m[^/]) 6857 7815 14672
460 6857 my @inc = $self->profile->inc;
461 6857 @files = map { "$_/$filename" } @inc;
462 }
463  
464 14672 for my $file (@files) {
465 98670 ▶ return $file if -f $file;
Branch: 1 branch
BranchTrueFalseTotal
if -f $file 7812 90858 98670
466 }
467  
468 # returning the still-relative filename is better than returning an undef
469 6860 return $filename;
470 }
471  
472 # has source code stored within the profile data file
473 41858 ▶sub has_savesrc {
Subroutine has_savesrc: called CC=1 SCAR=0.0
Pod undocumented
474 41858 my $self = shift;
475 41858 return $self->profile->{fid_srclines}[ $self->fid ];
476 }
477  
478 25455 ▶sub srclines_array {
Subroutine srclines_array: called CC=3 SCAR=11.0
Pod undocumented
479 25455 my $self = shift;
480  
481 25455 ▶ if (my $srclines = $self->has_savesrc) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $srclines = $self->has_savesrc) 10799 14656 25455
482 10799 my $copy = [ @$srclines ]; # shallow clone
483 10799 shift @$copy; # line 0 not used
484 10799 return $copy;
485 }
486  
487 14656 my $filename = $self->abs_filename;
488 14656 ▶ if (open my $fh, "<", $filename) {
Branch: 1 branch
BranchTrueFalseTotal
if (open my $fh, "<", $filename) 7812 6844 14656
489 7812 return [ <$fh> ];
490 }
491  
492 6844 return undef;
493 }
494  
495 11558 ▶sub src_digest {
Subroutine src_digest: called CC=4 SCAR=13.9
Pod undocumented
496 11558 my $self = shift;
497 11558 ▶ return $self->cache->{src_digest} ||= do {
Condition100%3/3
$self->cache->{"src_digest"} ||= do { my $srclines_array = $self->srclines_array || []; my $src = join("\n", @$srclines_array); $src ? join(",", (scalar @$srclines_array, length $src, unpack("%32C*", $src))) : "" }
l!l&&r!l&&!r
252225116525
MC/DC100%2/2
$self->cache->{"src_digest"} ||= do { my $srclines_array = $self->srclines_array || []; my $src = join("\n", @$srclines_array); $src ? join(",", (scalar @$srclines_array, length $src, unpack("%32C*", $src))) : "" }
$self->cache->{"src_digest"} do { my $srclines_array = $self->srclines_array || []; my $src = join("\n", @$srclines_array); $src ? join(",", (scalar @$srclines_array, length $src, unpack("%32C*", $src))) : "" }
Truth table100%3/3
A ||= B
A= $self->cache->{"src_digest"}B= do { my $srclines_array = $self->srclines_array || []; my $src = join("\n", @$srclines_array); $src ? join(",", (scalar @$srclines_array, length $src, unpack("%32C*", $src))) : "" }
ABresult
1X1
011
000
498 9036 ▶ my $srclines_array = $self->srclines_array || [];
Condition100%2/2
$self->srclines_array || []
l!l
25116525
MC/DC100%1/1
$self->srclines_array || []
$self->srclines_array
Truth table100%2/2
A
A= $self->srclines_array
Aresult
11
00
499 9036 my $src = join "\n", @$srclines_array;
500 # return empty string for digest if there's no src
501 9036 ▶ ($src) ? join ",", (
Branch: 1 branch
BranchTrueFalseTotal
$src ? : 2511 6525 9036
502 scalar @$srclines_array, # number of lines
503 length $src, # total length
504 unpack("%32C*",$src) ) # 32-bit checksum
505 : '';
506 };
507 }
508  
509  
510 9263 ▶sub normalize_for_test {
Subroutine normalize_for_test: called CC=7 SCAR=19.5
Pod undocumented
511 9263 my $self = shift;
512  
513 # normalize eval sequence numbers in 'file' names to 0
514 $self->[NYTP_FIDi_FILENAME] =~ s/ \( ((?:re_)?) eval \s \d+ \) /(${1}eval 0)/xg
515 9263 ▶ if not $ENV{NYTPROF_TEST_SKIP_EVAL_NORM};
Branch: 1 branch
BranchTrueFalseTotal
unless $ENV{"NYTPROF_TEST_SKIP_EVAL_NORM"} 8139 1124 9263
516  
517 # normalize flags to avoid failures due to savesrc and perl version
518 9263 $self->[NYTP_FIDi_FLAGS] &= ~(NYTP_FIDf_HAS_SRC|NYTP_FIDf_SAVE_SRC);
519  
520 # '1' => { 'main::foo' => [ 1, '1.38e-05', '1.24e-05', ..., { 'main::RUNTIME' => undef } ] }
521 9263 for my $subscalled (values %{ $self->sub_call_lines }) {
522  
523 157608 for my $subname (keys %$subscalled) {
524 198078 my $sc = $subscalled->{$subname};
525 198078 $sc->[NYTP_SCi_INCL_RTIME] =
526 $sc->[NYTP_SCi_EXCL_RTIME] =
527 $sc->[NYTP_SCi_RECI_RTIME] = 0;
528  
529 198078 ▶ if (not $ENV{NYTPROF_TEST_SKIP_EVAL_NORM}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ENV{"NYTPROF_TEST_SKIP_EVAL_NORM"}) 177069 21009 198078
530 # normalize eval sequence numbers in anon sub names to 0
531 177069 (my $newname = $subname) =~ s/ \( ((?:re_)?) eval \s \d+ \) /(${1}eval 0)/xg;
532 177069 ▶ if ($newname ne $subname) {
Branch: 1 branch
BranchTrueFalseTotal
if ($newname ne $subname) 48 177021 177069
533 warn "Normalizing $subname to $newname overwrote other called-by data\n"
534 48 ▶ if $subscalled->{$newname};
Branch: 1 branch
BranchTrueFalseTotal
if $subscalled->{$newname} 0 48 48
535 48 $subscalled->{$newname} = delete $subscalled->{$subname};
536 }
537 }
538 }
539  
540 }
541 }
542  
543  
544 1 ▶sub summary {
Subroutine summary: called CC=1 SCAR=0.0
Pod undocumented
545 1 my ($fi) = @_;
546 1 return sprintf "fid%d: %s",
547 $fi->fid, $fi->filename_without_inc;
548 }
549  
550 9262 ▶sub dump {
Subroutine dump: called CC=12 SCAR=24.9
Pod undocumented
551 9262 my ($self, $separator, $fh, $path, $prefix, $opts) = @_;
552  
553 9262 my @values = @{$self}[
554 NYTP_FIDi_FILENAME, NYTP_FIDi_EVAL_FID, NYTP_FIDi_EVAL_LINE, NYTP_FIDi_FID,
555 NYTP_FIDi_FLAGS, NYTP_FIDi_FILESIZE, NYTP_FIDi_FILEMTIME
556 ];
557 9262 $values[0] = $self->filename_without_inc;
558 # also remove possible remaining perl version seen in some cpantesters
559 # http://www.cpantesters.org/cpan/report/bf913910-bfdd-11df-a657-c9f38a00995b
560 9262 $values[0] =~ s!^$Config{version}/!!o;
561  
562 9262 ▶ printf $fh "%s[ %s ]\n", $prefix, join(" ", map { defined($_) ? $_ : 'undef' } @values);
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 64834 0 64834
563  
564 9262 ▶ if (not $opts->{skip_internal_details}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $opts->{"skip_internal_details"}) 9246 16 9262
565  
566 9246 for my $si ($self->subs_defined_sorted) {
567 125103 my ($fl, $ll) = ($si->first_line, $si->last_line);
568 125103 ▶ defined $_ or $_ = 'undef' for ($fl, $ll);
Branch: 1 branch
BranchTrueFalseTotal
defined $_ or $_ = "undef" 117738 132468 250206
569 125103 printf $fh "%s%s%s%s%s%s-%s\n",
570 $prefix, 'sub', $separator,
571 $si->subname(' and '), $separator,
572 $fl, $ll;
573 }
574  
575 # { line => { subname => [...] }, ... }
576 9246 my $sub_call_lines = $self->sub_call_lines;
577 9246 for my $line (sort { $a <=> $b } keys %$sub_call_lines) {
578 157471 my $subs_called = $sub_call_lines->{$line};
579  
580 157471 for my $subname (sort keys %$subs_called) {
581 197893 my @sc = @{$subs_called->{$subname}};
582 197893 $sc[NYTP_SCi_CALLING_SUB] = join "|", sort keys %{ $sc[NYTP_SCi_CALLING_SUB] };
583  
584 printf $fh "%s%s%s%s%s%s%s[ %s ]\n",
585 $prefix, 'call', $separator,
586 $line, $separator, $subname, $separator,
587 197893 ▶ join(" ", map { defined($_) ? $_ : 'undef' } @sc)
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 1583144 0 1583144
588 }
589 }
590  
591 # string evals, group by the line the eval is on
592 9246 my %eval_lines;
593 9246 for my $eval_fi ($self->has_evals(0)) {
594 1244 push @{ $eval_lines{ $eval_fi->eval_line } }, $eval_fi;
595 }
596 9246 for my $line (sort { $a <=> $b } keys %eval_lines) {
597 1008 my $eval_fis = $eval_lines{$line};
598  
599 1008 my @has_evals = map { $_->has_evals(1) } @$eval_fis;
600 1008 ▶ my @merged_fids = map { @{ $_->meta->{merged_fids}||[]} } @$eval_fis;
Condition100%2/2
$_->meta->{'merged_fids'} || []
l!l
444800
MC/DC100%1/1
$_->meta->{'merged_fids'} || []
$_->meta->{'merged_fids'}
Truth table100%2/2
A
A= $_->meta->{'merged_fids'}
Aresult
11
00
601  
602 1008 printf $fh "%s%s%s%d%s[ count %d nested %d merged %d ]\n",
603 $prefix, 'eval', $separator,
604 $eval_fis->[0]->eval_line, $separator,
605 scalar @$eval_fis, # count of evals executed on this line
606 scalar @has_evals, # count of nested evals they executed
607 scalar @merged_fids, # count of evals merged (collapsed) away
608 }
609  
610 }
611  
612 }
613  
614 # vim: ts=8:sw=4:et
615 700 1;
« blib/lib/Devel/NYTProf/Reader.pm ↑ Summary blib/lib/Devel/NYTProf/Constants.pm »