| 1 | # vim: ts=8 sw=4 expandtab: | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | ########################################################## | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | # This script is part of the Devel::NYTProf distribution | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | # Copyright, contact and other information can be found | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | # at the bottom of this file, or by going to: | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | # http://metacpan.org/release/Devel-NYTProf/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | ########################################################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | package Devel::NYTProf::Data; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | Devel::NYTProf::Data - L<Devel::NYTProf> data loading and manipulation | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | use Devel::NYTProf::Data; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | $profile = Devel::NYTProf::Data->new( { filename => 'nytprof.out' } ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | $profile->dump_profile_data(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | Reads a profile data file written by L<Devel::NYTProf>, aggregates the | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | contents, and returns the results as a blessed data structure. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | Access to the data should be via methods in this class to avoid breaking | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | encapsulation (and thus breaking your code when the data structures change in | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | future versions). | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | B<NOTE> the documentation is out of date and may not be updated soon. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | It's also likely that the API will change drastically in future. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | It's possible, for example, that the data model will switch to use SQLite | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | and the http://metacpan.org/pod/ORLite ORM. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | Let me know if you come to depend on a particular API and I'll try to preserve | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | it if practical. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 700 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 700 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 700 | ▶ | use Carp qw(carp croak cluck); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 700 | ▶ | use Cwd qw(getcwd); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 700 | ▶ | use Scalar::Util qw(blessed); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 700 | ▶ | use Devel::NYTProf::Core; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 700 | ▶ | use Devel::NYTProf::FileInfo; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 700 | ▶ | use Devel::NYTProf::SubInfo; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 700 | ▶ | use Devel::NYTProf::Util qw( trace_level _dumper ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 700 | our $VERSION = '6.16'; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | =head2 new | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | $profile = Devel::NYTProf::Data->new( ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | $profile = Devel::NYTProf::Data->new( { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | filename => 'nytprof.out', # default | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | quiet => 0, # default, 1 to silence message | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | } ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | Reads the specified file containing profile data written by L<Devel::NYTProf>, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | aggregates the contents, and returns the results as a blessed data structure. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 1298 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=20 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 1298 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 1298 | ▶ | my $args = shift || { }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
shift() || {}
MC/DC100%1/1
shift() || {}
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 1298 | ▶ | my $file = $args->{filename} ||= 'nytprof.out'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$args->{"filename"} ||= "nytprof.out"
MC/DC100%1/1
$args->{"filename"} ||= "nytprof.out"
$args->{"filename"}
Truth table100%2/2
A
A= $args->{"filename"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 1298 | ▶ | croak "Devel::NYTProf::new() could not locate file for processing" | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | unless -f $file; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 1297 | ▶ | print "Reading $file\n" unless $args->{quiet}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | my $profile = load_profile_data_from_file( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | $file, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | $args->{callback}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 1297 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 1297 | ▶ | return undef if $args->{callback}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 948 | ▶ | print "Processing $file data\n" unless $args->{quiet}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 948 | bless $profile => $class; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 948 | my $fid_fileinfo = $profile->{fid_fileinfo}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 948 | my $sub_subinfo = $profile->{sub_subinfo}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | # add profile ref so fidinfo & subinfo objects | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | # XXX circular ref, add weaken | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 948 | ▶ | for (@$fid_fileinfo) { $_ and $_->[7] = $profile; } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 948 | $_->[7] = $profile for values %$sub_subinfo; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | # bless sub_subinfo data | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 948 | (my $sub_class = $class) =~ s/\w+$/SubInfo/; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 948 | ▶ | $_ and bless $_ => $sub_class for values %$sub_subinfo; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | # create profiler_active attribute by subtracting from profiler_duration | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | # currently we only subtract cumulative_overhead_ticks | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 948 | my $attribute = $profile->{attribute}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 948 | my $overhead_time = $attribute->{cumulative_overhead_ticks} / $attribute->{ticks_per_sec}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 948 | $attribute->{profiler_active} = $attribute->{profiler_duration} - $overhead_time; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | # find subs that have calls but no fid | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 948 | ▶ | my @homeless_subs = grep { $_->calls and not $_->fid } values %$sub_subinfo; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$_->calls && !$_->fid
MC/DC100%2/2
$_->calls && !$_->fid
$_->calls
!$_->fid
Truth table100%3/3
A && not(B)
A= $_->callsB= !$_->fid
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 948 | ▶ | if (@homeless_subs) { # give them a home... | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | # currently just the first existing fileinfo | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | # XXX ought to create a new dummy fileinfo for them | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 934 | my $new_fi = $profile->fileinfo_of(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 934 | $_->_alter_fileinfo(undef, $new_fi) for @homeless_subs; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | # Where a given eval() has been invoked more than once | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | # rollup the corresponding fids if they're "uninteresting". | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 948 | ▶ | if (not $args->{skip_collapse_evals}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 947 | for my $fi ($profile->noneval_fileinfos) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 19069 | $profile->collapse_evals_in($fi); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 948 | $profile->_clear_caches; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | # a hack for testing/debugging | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | # $ENV{NYTPROF_ONLOAD} must be a colon-delimited string of | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | # equal-sign-delimited substrings, e.g., | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | # 'alpha=beta:gamma=delta:dump=1:exit=1'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 948 | ▶ | if (my $env = $ENV{NYTPROF_ONLOAD}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 1 | my %onload = map { split /=/, $_, 2 } split /:/, $env, -1; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 1 | ▶ | warn _dumper($profile) if $onload{dump}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 1 | ▶ | exit $onload{exit} if defined $onload{exit}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 948 | return $profile; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 25900 | ▶ | sub collapse_evals_in { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
collapse_evals_in: called CC=18 SCAR=31.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 25900 | my ($profile, $parent_fi) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 25900 | my $parent_fid = $parent_fi->fid; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 25900 | my %evals_on_line; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 25900 | for my $fi ($parent_fi->has_evals) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 6831 | $profile->collapse_evals_in($fi); # recurse first | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 6831 | push @{ $evals_on_line{$fi->eval_line} }, $fi; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 25900 | ▶ | while ( my ($line, $siblings) = each %evals_on_line) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 2723 | ▶ | next if @$siblings == 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | # compare src code of evals and collapse identical ones | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 864 | my %src_keyed; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 864 | for my $fi (@$siblings) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 4972 | my $key = $fi->src_digest; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 4972 | ▶ | if (!$key) { # include extra info to segregate when there's no src | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 2461 | ▶ | $key .= ',evals' if $fi->has_evals; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 2461 | ▶ | $key .= ',subs' if $fi->subs_defined; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 4972 | push @{$src_keyed{$key}}, $fi; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 864 | ▶ | if (trace_level() >= 2) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | my @subs = map { $_->subs_defined } @$siblings; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | my @evals = map { $_->has_evals(0) } @$siblings; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | warn sprintf "%d:%d: has %d sibling evals (subs %d, evals %d, keys %d) in %s; fids: %s\n", | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | $parent_fid, $line, scalar @$siblings, scalar @subs, scalar @evals, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | scalar keys %src_keyed, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | $parent_fi->filename, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | join(" ", map { $_->fid } @$siblings); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 0 | for my $si (@subs) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 0 | warn sprintf "%d:%d evals: define sub %s in fid %s\n", | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | $parent_fid, $line, $si->subname, $si->fid; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | for my $fi (@evals) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | warn sprintf "%d:%d evals: execute eval %s\n", | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | $parent_fid, $line, $fi->filename; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | # if 'too many' distinct eval source keys then simply collapse all | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 864 | ▶ | my $max_evals_siblings = $ENV{NYTPROF_MAX_EVAL_SIBLINGS} || 200; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$ENV{'NYTPROF_MAX_EVAL_SIBLINGS'} || 200
MC/DC0%0/1
$ENV{'NYTPROF_MAX_EVAL_SIBLINGS'} || 200
$ENV{'NYTPROF_MAX_EVAL_SIBLINGS'}
Truth table50%1/2
A
A= $ENV{'NYTPROF_MAX_EVAL_SIBLINGS'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 864 | ▶ | if (values %src_keyed > $max_evals_siblings) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 0 | $parent_fi->collapse_sibling_evals(@$siblings); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | # finesse: consider each distinct src in turn | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 864 | ▶ | while ( my ($key, $src_same_fis) = each %src_keyed ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 1663 | ▶ | next if @$src_same_fis == 1; # unique src key | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 838 | my @fids = map { $_->fid } @$src_same_fis; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 838 | ▶ | if (grep { $_->has_evals(0) } @$src_same_fis) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 16 | ▶ | warn "evals($key): collapsing skipped due to evals in @fids\n" if trace_level() >= 3; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 822 | ▶ | warn "evals($key): collapsing identical: @fids\n" if trace_level() >= 3; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 822 | my $fi = $parent_fi->collapse_sibling_evals(@$src_same_fis); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 822 | @$src_same_fis = ( $fi ); # update list in-place | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 25900 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 351661 | ▶ | sub _caches { return shift->{caches} ||= {} } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_caches: called CC=2 SCAR=6.9
Condition100%2/2
+(shift())->{"caches"} ||= {}
MC/DC100%1/1
+(shift())->{"caches"} ||= {}
+(shift())->{"caches"}
Truth table100%2/2
A
A= +(shift())->{"caches"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 1398 | ▶ | sub _clear_caches { return delete shift->{caches} } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_clear_caches: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 1274 | ▶ | sub attributes { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
attributes: called CC=2 SCAR=7.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 1274 | ▶ | return shift->{attribute} || {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
+(shift())->{'attribute'} || {}
MC/DC0%0/1
+(shift())->{'attribute'} || {}
+(shift())->{'attribute'}
Truth table50%1/2
A
A= +(shift())->{'attribute'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 450 | ▶ | sub options { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
options: called CC=2 SCAR=7.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 450 | ▶ | return shift->{option} || {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
+(shift())->{'option'} || {}
MC/DC0%0/1
+(shift())->{'option'} || {}
+(shift())->{'option'}
Truth table50%1/2
A
A= +(shift())->{'option'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 113 | ▶ | sub subname_subinfo_map { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
subname_subinfo_map: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 113 | return { %{ shift->{sub_subinfo} } }; # shallow copy | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 0 | ▶ | sub _disconnect_subinfo { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_disconnect_subinfo: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | my ($self, $si) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 0 | my $subname = $si->subname; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 0 | my $si2 = delete $self->{sub_subinfo}{$subname}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | # sanity check | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 0 | ▶ | carp sprintf "disconnect_subinfo: deleted entry %s %s doesn't match argument %s %s", | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
$si2 != $si or $si2->subname ne $subname
MC/DC0%0/2
$si2 != $si or $si2->subname ne $subname
$si2 != $si
$si2->subname ne $subname
Truth table0%0/3
A or B
A= $si2 != $siB= $si2->subname ne $subname
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | ($si2) ? ($si2, $si2->subname) : ('undef', 'undef'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | $si, $subname | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | if $si2 != $si or $si2->subname ne $subname; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | # do more? | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | # package_tree_subinfo_map is like package_subinfo_map but returns | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | # nested data instead of flattened. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | # for "Foo::Bar::Baz" package: | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | # { Foo => { '' => [...], '::Bar' => { ''=>[...], '::Baz'=>[...] } } } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | # if merged is true then array contains a single 'merged' subinfo | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 6 | ▶ | sub package_subinfo_map { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
package_subinfo_map: called CC=11 SCAR=24.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 6 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 6 | my ($merge_subs, $nested_pkgs) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 6 | my %pkg; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | my %to_merge; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 6 | my $all_subs = $self->subname_subinfo_map; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 6 | ▶ | while ( my ($name, $subinfo) = each %$all_subs ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 36 | $name =~ s/^(.*::).*/$1/; # XXX $subinfo->package | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 36 | my $subinfos; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 36 | ▶ | if ($nested_pkgs) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 24 | my @parts = split /::/, $name; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 24 | ▶ | my $node = $pkg{ shift @parts } ||= {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$pkg{shift @parts} ||= {}
MC/DC100%1/1
$pkg{shift @parts} ||= {}
$pkg{shift @parts}
Truth table100%2/2
A
A= $pkg{shift @parts}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | # TODO: Need to figure out how to provide a multi-part name, e.g., 'alpha::beta' | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | # Otherwise @parts is now empty and so next line is not exercised | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | # during testing. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 24 | ▶ | $node = $node->{ shift @parts } ||= {} while @parts; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$$node{shift @parts} ||= {}
MC/DC0%0/1
$$node{shift @parts} ||= {}
$$node{shift @parts}
Truth table0%0/2
A
A= $$node{shift @parts}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 24 | ▶ | $subinfos = $node->{''} ||= []; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$node->{""} ||= []
MC/DC100%1/1
$node->{""} ||= []
$node->{""}
Truth table100%2/2
A
A= $node->{""}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 12 | ▶ | $subinfos = $pkg{$name} ||= []; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$pkg{$name} ||= []
MC/DC100%1/1
$pkg{$name} ||= []
$pkg{$name}
Truth table100%2/2
A
A= $pkg{$name}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 36 | push @$subinfos, $subinfo; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 36 | ▶ | $to_merge{$subinfos} = $subinfos if $merge_subs; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 6 | for my $subinfos (values %to_merge) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 2 | my $subinfo = shift(@$subinfos)->clone; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | $subinfo->merge_in($_, src_keep => 1) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 2 | for @$subinfos; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | # replace the many with the one | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 2 | @$subinfos = ($subinfo); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 6 | return \%pkg; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 4558 | ▶ | sub all_fileinfos { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
all_fileinfos: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 4558 | my @all = @{shift->{fid_fileinfo}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 4558 | shift @all; # drop fid 0 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | # return all non-nullified fileinfos | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 4558 | return grep { $_->fid } @all; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 1 | ▶ | sub eval_fileinfos { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
eval_fileinfos: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 1 | return grep { $_->eval_line } shift->all_fileinfos; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 949 | ▶ | sub noneval_fileinfos { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
noneval_fileinfos: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 949 | return grep { !$_->eval_line } shift->all_fileinfos; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 318858 | ▶ | sub fileinfo_of { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fileinfo_of: called CC=8 SCAR=20.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 318858 | my ($self, $arg, $silent_if_undef) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 318858 | ▶ | if (not defined $arg) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 2 | ▶ | carp "Can't resolve fid of undef value" unless $silent_if_undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 2 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | # check if already a file info object | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 318856 | ▶ | return $arg if ref $arg and UNIVERSAL::can($arg,'fid') and $arg->isa('Devel::NYTProf::FileInfo'); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
ref $arg and UNIVERSAL::can($arg, "fid") and $arg->isa("Devel::NYTProf::FileInfo")
ref $arg and UNIVERSAL::can($arg, "fid")
MC/DC100%3/3
ref $arg and UNIVERSAL::can($arg, "fid") and $arg->isa("Devel::NYTProf::FileInfo")
ref $arg
UNIVERSAL::can($arg, "fid")
$arg->isa("Devel::NYTProf::FileInfo")
Truth table100%4/4
A and B and C
A= ref $argB= UNIVERSAL::can($arg, "fid")C= $arg->isa("Devel::NYTProf::FileInfo")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 318852 | my $fid = $self->resolve_fid($arg); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 318852 | ▶ | if (not $fid) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 4 | carp "Can't resolve fid of '$arg'"; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 4 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 318848 | my $fi = $self->{fid_fileinfo}[$fid]; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 318848 | ▶ | return undef unless defined $fi->fid; # nullified? | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 314036 | return $fi; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 911 | ▶ | sub subinfo_of { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
subinfo_of: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 911 | my ($self, $subname) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 911 | ▶ | if (not defined $subname) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 1 | cluck "Can't resolve subinfo of undef value"; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 1 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 910 | ▶ | my $si = $self->{sub_subinfo}{$subname} | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | or cluck "Can't resolve subinfo of '$subname'"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 910 | return $si; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 32546 | ▶ | sub inc { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
inc: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | # XXX should return inc from profile data, when it's there | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 32546 | return @INC; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | =head2 dump_profile_data | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | $profile->dump_profile_data; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | $profile->dump_profile_data( { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | filehandle => \*STDOUT, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | separator => "", | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | } ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | Writes the profile data in a reasonably human friendly format to the specified | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | C<filehandle> (default STDOUT). | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | For non-trivial profiles the output can be very large. As a guide, there'll be | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | at least one line of output for each line of code executed, plus one for each | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | place a subroutine was called from, plus one per subroutine. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | The default format is a Data::Dumper style whitespace-indented tree. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | The types of data present can depend on the options used when profiling. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | If C<separator> is true then instead of whitespace, each item of data is | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | indented with the I<path> through the structure with C<separator> used to | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | separate the elements of the path. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | This format is especially useful for grep'ing and diff'ing. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | 450 | ▶ | sub dump_profile_data { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dump_profile_data: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | 450 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 450 | ▶ | my $args = shift || {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
shift() || {}
MC/DC100%1/1
shift() || {}
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | 450 | ▶ | my $separator = $args->{separator} || ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$args->{'separator'} || ''
MC/DC100%1/1
$args->{'separator'} || ''
$args->{'separator'}
Truth table100%2/2
A
A= $args->{'separator'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 450 | ▶ | my $filehandle = $args->{filehandle} || \*STDOUT; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$args->{'filehandle'} || \*STDOUT
MC/DC100%1/1
$args->{'filehandle'} || \*STDOUT
$args->{'filehandle'}
Truth table100%2/2
A
A= $args->{'filehandle'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | # shallow clone and add sub_caller for migration of tests | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | 450 | my $startnode = $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 450 | $self->_clear_caches; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 676270 | ▶ | my $callback = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=14 SCAR=26.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | 676270 | my ($path, $value) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | # not needed currently | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | #if ($path->[0] eq 'attribute' && @$path == 1) { my %v = %$value; return ({}, \%v); } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | 676270 | ▶ | if (my $hook = $args->{skip_fileinfo_hook}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | # for fid_fileinfo elements... | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 676114 | ▶ | if ($path->[0] eq 'fid_fileinfo' && @$path==2) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$path->[0] eq "fid_fileinfo" and @$path == 2
MC/DC100%2/2
$path->[0] eq "fid_fileinfo" and @$path == 2
$path->[0] eq "fid_fileinfo"
@$path == 2
Truth table100%3/3
A and B
A= $path->[0] eq "fid_fileinfo"B= @$path == 2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 10864 | my $fi = $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | # skip nullified fileinfo | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | 10864 | ▶ | return undef unless $fi->fid; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | # don't dump internal details of lib modules | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 9260 | return ({ skip_internal_details => scalar $hook->($fi, $path, $value) }, $value); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | # skip sub_subinfo data for 'library modules' | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | 665250 | ▶ | if ($path->[0] eq 'sub_subinfo' && @$path==2 && $value->[0]) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$path->[0] eq "sub_subinfo" and @$path == 2 and $value->[0]
$path->[0] eq "sub_subinfo" and @$path == 2
MC/DC66%2/3
$path->[0] eq "sub_subinfo" and @$path == 2 and $value->[0]
$path->[0] eq "sub_subinfo"
@$path == 2
$value->[0]
Truth table75%3/4
A and B and C
A= $path->[0] eq "sub_subinfo"B= @$path == 2C= $value->[0]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | 125091 | my $fi = $self->fileinfo_of($value->[0]); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | 125091 | ▶ | return undef if !$fi or $hook->($fi, $path, $value); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not $fi or &$hook($fi, $path, $value)
MC/DC0%0/2
not $fi or &$hook($fi, $path, $value)
not $fi
&$hook($fi, $path, $value)
Truth table33%1/3
not(A) or B
A= not $fiB= &$hook($fi, $path, $value)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | # skip fid_*_time data for 'library modules' | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | 665250 | ▶ | if ($path->[0] =~ /^fid_\w+_time$/ && @$path==2) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$path->[0] =~ /^fid_\w+_time$/ and @$path == 2
MC/DC100%2/2
$path->[0] =~ /^fid_\w+_time$/ and @$path == 2
$path->[0] =~ /^fid_\w+_time$/
@$path == 2
Truth table100%3/3
A and B
A= $path->[0] =~ /^fid_\w+_time$/B= @$path == 2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | 29520 | my $fi = $self->fileinfo_of($path->[1]); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | 29520 | ▶ | return undef if !$fi or $hook->($fi, $path, $value); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not $fi or &$hook($fi, $path, $value)
MC/DC100%2/2
not $fi or &$hook($fi, $path, $value)
not $fi
&$hook($fi, $path, $value)
Truth table100%3/3
not(A) or B
A= not $fiB= &$hook($fi, $path, $value)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | 660546 | return ({}, $value); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | 450 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | 450 | _dump_elements($startnode, $separator, $filehandle, [], $callback); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | 28716 | ▶ | sub _dump_elements { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_dump_elements: called CC=25 SCAR=32.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | 28716 | my ($r, $separator, $fh, $path, $callback) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | 28716 | my $pad = " "; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | 28716 | my $padN; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | 28716 | my $is_hash = (UNIVERSAL::isa($r, 'HASH')); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | 28716 | ▶ | my ($start, $end, $colon, $keys) = | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | ($is_hash) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | ? ('{', '}', ' => ', [sort keys %$r]) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | : ('[', ']', ': ', [0 .. @$r - 1]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | 28716 | ▶ | if ($separator) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | 28704 | ($start, $end, $colon) = (undef, undef, $separator); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | 28704 | $padN = join $separator, @$path, ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | 12 | $padN = $pad x (@$path + 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | 28716 | my $format = {sub_subinfo => {compact => 1},}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | 28716 | ▶ | print $fh "$start\n" if $start; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | 28716 | ▶ | my $key1 = $path->[0] || $keys->[0]; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$path->[0] || $keys->[0]
MC/DC0%0/2
$path->[0] || $keys->[0]
$path->[0]
$keys->[0]
Truth table66%2/3
A || B
A= $path->[0]B= $keys->[0]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | 28716 | for my $key (@$keys) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | 8383977 | ▶ | next if $key eq 'fid_srclines'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | 8383527 | ▶ | my $value = ($is_hash) ? $r->{$key} : $r->[$key]; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | # skip undef elements in array | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | 8383527 | ▶ | next if !$is_hash && !defined($value); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$is_hash or defined $value
MC/DC100%2/2
$is_hash or defined $value
$is_hash
defined $value
Truth table100%3/3
A or B
A= $is_hashB= defined $value
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | # skip refs to empty arrays in array | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | 676270 | ▶ | next if !$is_hash && ref $value eq 'ARRAY' && !@$value; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
not $is_hash and ref $value eq "ARRAY" and not @$value
not $is_hash and ref $value eq "ARRAY"
MC/DC0%0/3
not $is_hash and ref $value eq "ARRAY" and not @$value
not $is_hash
ref $value eq "ARRAY"
not @$value
Truth table75%3/4
not(A) and B and not(C)
A= not $is_hashB= ref $value eq "ARRAY"C= not @$value
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | 676270 | my $dump_opts = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | 676270 | ▶ | if ($callback) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | 676270 | ($dump_opts, $value) = $callback->([ @$path, $key ], $value); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | 676270 | ▶ | next if not $dump_opts; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | 669806 | my $prefix = "$padN$key$colon"; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | 669806 | ▶ | if (UNIVERSAL::can($value,'dump')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | 134365 | $value->dump($separator, $fh, [ @$path, $key ], $prefix, $dump_opts); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | # special case some common cases to be more compact: | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | # fid_*_time [fid][line] = [N,N] | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | # sub_subinfo {subname} = [fid,startline,endline,calls,incl_time] | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | 535441 | my $as_compact = $format->{$key1}{compact}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | 535441 | ▶ | if (not defined $as_compact) { # so guess... | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | $as_compact = | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | 535441 | ▶ | (UNIVERSAL::isa($value, 'ARRAY') && @$value <= 9 && !grep { ref or !defined } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%9/9
UNIVERSAL::isa($value, 'ARRAY') && @$value <= 9 && !grep({ref $_ or not defined $_;} @$value)
UNIVERSAL::isa($value, "ARRAY") and @$value <= 9
ref $_ || !defined($_)
MC/DC100%3/3
UNIVERSAL::isa($value, 'ARRAY') && @$value <= 9 && !grep({ref $_ or not defined $_;} @$value)
UNIVERSAL::isa($value, "ARRAY")
@$value <= 9
!grep({ref $_ or not defined $_;} @$value)
MC/DC100%2/2
ref $_ || !defined($_)
ref $_
!defined($_)
Truth table100%4/4
A and B && not(C)
A= UNIVERSAL::isa($value, "ARRAY")B= @$value <= 9C= !grep({ref $_ or not defined $_;} @$value)
Truth table100%3/3
A || not(B)
A= ref $_B= !defined($_)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | @$value); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | 535441 | ▶ | $as_compact = 0 if not ref $value eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | 535441 | ▶ | if ($as_compact) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | 700 | ▶ | no warnings qw(uninitialized); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | 498585 | ▶ | printf $fh "%s[ %s ]\n", $prefix, join(" ", map { defined($_) ? $_ : 'undef' } @$value); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | elsif (ref $value) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | 28266 | _dump_elements($value, $separator, $fh, [ @$path, $key ], $callback); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | 8590 | print $fh "$prefix$value\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | 700 | ▶ | no warnings 'numeric'; # @$path can be non-positive | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | 28716 | ▶ | printf $fh "%s$end\n", ($pad x (@$path - 1)) if $end; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | 28716 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | 306 | ▶ | sub get_profile_levels { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_profile_levels: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | 306 | return shift->{profile_modes}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | 22700 | ▶ | sub get_fid_line_data { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_fid_line_data: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | 22700 | my ($self, $level) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | 22700 | ▶ | $level ||= 'line'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$level ||= "line"
MC/DC100%1/1
$level ||= "line"
$level
Truth table100%2/2
A
A= $level
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | 22700 | my $fid_line_data = $self->{"fid_${level}_time"}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | 22700 | return $fid_line_data; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | =head2 normalize_variables | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | $profile->normalize_variables; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | Traverses the profile data structure and normalizes highly variable data, such | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | as the time, in order that the data can more easily be compared. This is mainly of | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | use to the test suite. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | The data normalized is: | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | =over | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | =item * | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | profile timing data: set to 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | =item * | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | subroutines: timings are set to 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | =item * | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | attributes, like basetime, xs_version, etc., are set to 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | =item * | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | filenames: path prefixes matching absolute paths in @INC are changed to "/.../" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | =item * | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | filenames: eval sequence numbers, like "(re_eval 2)" are changed to 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | 451 | ▶ | sub normalize_variables { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
normalize_variables: called CC=13 SCAR=25.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | 451 | my ($self, $normalize_options) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | 451 | ▶ | if ($normalize_options) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | 449 | %{ $self->options } = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | 451 | my $attributes = $self->attributes; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | 451 | for my $attr (qw( | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | basetime xs_version perl_version clock_id ticks_per_sec nv_size | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | profiler_duration profiler_end_time profiler_start_time | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | cumulative_overhead_ticks profiler_active | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | total_stmts_duration total_stmts_measured total_stmts_discounted | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | total_sub_calls sawampersand_line | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | )) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | 7216 | ▶ | $attributes->{$attr} = 0 if exists $attributes->{$attr}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | 451 | for my $attr (qw(PL_perldb cumulative_overhead_ticks)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | 902 | delete $attributes->{$attr}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | # normalize line data | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | 451 | for my $level (qw(line block sub)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | 1353 | ▶ | my $fid_line_data = $self->get_fid_line_data($level) || []; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->get_fid_line_data($level) || []
MC/DC0%0/1
$self->get_fid_line_data($level) || []
$self->get_fid_line_data($level)
Truth table50%1/2
A
A= $self->get_fid_line_data($level)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | # zero the statement timing data | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | 1353 | for my $of_fid (@$fid_line_data) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | 30930 | ▶ | _zero_array_elem($of_fid, 0) if $of_fid; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | 451 | my $sub_subinfo = $self->{sub_subinfo}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | 451 | for my $subname (keys %$sub_subinfo) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | 125109 | my $si = $self->{sub_subinfo}{$subname}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | # zero sub info and sub caller times etc. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | 125109 | my $newname = $si->normalize_for_test; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | 125109 | ▶ | if ($newname ne $subname) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | warn "Normalizing $subname to $newname overwrote other data\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 592 | 32 | ▶ | if $sub_subinfo->{$newname}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | 32 | $sub_subinfo->{$newname} = delete $sub_subinfo->{$subname}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 594 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 595 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 596 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 597 | 451 | $_->normalize_for_test for $self->all_fileinfos; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 598 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 599 | 451 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 600 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 601 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 602 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 603 | 29529 | ▶ | sub _zero_array_elem { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_zero_array_elem: called CC=4 SCAR=14.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 604 | 29529 | my ($ary_of_line_data, $index) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 605 | 29529 | for my $line_data (@$ary_of_line_data) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 606 | 8218523 | ▶ | next unless $line_data; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 607 | 504042 | $line_data->[$index] = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 608 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 609 | # if line was a string eval | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 610 | # then recurse to zero the times within the eval lines | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 611 | 504042 | ▶ | if (my $eval_lines = $line_data->[2]) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 612 | 0 | _zero_array_elem($eval_lines, $index); # recurse | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 613 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 614 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 615 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 616 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 617 | 318853 | ▶ | sub _filename_to_fid { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_filename_to_fid: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 618 | 318853 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 619 | 318853 | my $caches = $self->_caches; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 620 | 318853 | ▶ | return $caches->{_filename_to_fid_cache} ||= do { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$caches->{"_filename_to_fid_cache"} ||= do {
my $filename_to_fid = {};
$$filename_to_fid{$_->filename} = $_->fid foreach ($self->all_fileinfos);
$filename_to_fid
}
MC/DC0%0/2
$caches->{"_filename_to_fid_cache"} ||= do {
my $filename_to_fid = {};
$$filename_to_fid{$_->filename} = $_->fid foreach ($self->all_fileinfos);
$filename_to_fid
}
$caches->{"_filename_to_fid_cache"}
do {
my $filename_to_fid = {};
$$filename_to_fid{$_->filename} = $_->fid foreach ($self->all_fileinfos);
$filename_to_fid
}
Truth table66%2/3
A ||= B
A= $caches->{"_filename_to_fid_cache"}B= do {
my $filename_to_fid = {};
$$filename_to_fid{$_->filename} = $_->fid foreach ($self->all_fileinfos);
$filename_to_fid
}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 621 | 2190 | my $filename_to_fid = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 622 | 2190 | $filename_to_fid->{$_->filename} = $_->fid for $self->all_fileinfos; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 623 | 2190 | $filename_to_fid; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 624 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 625 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 626 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 627 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 628 | =head2 subs_defined_in_file | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 629 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 630 | $subs_defined_hash = $profile->subs_defined_in_file( $file, $include_lines ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 631 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 632 | Returns a reference to a hash containing information about subroutines defined | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 633 | in a source file. The $file argument can be an integer file id (fid) or a file | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 634 | path. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 635 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 636 | Returns undef if the profile contains no C<sub_subinfo> data for the $file. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 637 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 638 | The keys of the returned hash are fully qualified subroutine names and the | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 639 | corresponding value is a hash reference containing L<Devel::NYTProf::SubInfo> | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 640 | objects. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 641 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 642 | If $include_lines is true then the hash also contains integer keys | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 643 | corresponding to the first line of the subroutine. The corresponding value is a | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 644 | reference to an array. The array contains a hash ref for each of the | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 645 | subroutines defined on that line, typically just one. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 646 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 647 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 648 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 649 | 32808 | ▶ | sub subs_defined_in_file { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
subs_defined_in_file: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 650 | 32808 | my ($self, $fid, $incl_lines) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 651 | 32808 | ▶ | croak "incl_lines is deprecated in subs_defined_in_file, use subs_defined_in_file_by_line instead" if $incl_lines; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 652 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 653 | 32808 | ▶ | my $fi = $self->fileinfo_of($fid) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 654 | or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 655 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 656 | 32808 | $fid = $fi->fid; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 657 | 32808 | my $caches = $self->_caches; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 658 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 659 | 32808 | my $cache_key = "subs_defined_in_file:$fid"; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 660 | 32808 | ▶ | return $caches->{$cache_key} if $caches->{$cache_key}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 661 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 662 | 5987 | my %subs = map { $_->subname => $_ } $fi->subs_defined; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 663 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 664 | 5987 | $caches->{$cache_key} = \%subs; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 665 | 5987 | return $caches->{$cache_key}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 666 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 667 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 668 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 669 | 16404 | ▶ | sub subs_defined_in_file_by_line { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
subs_defined_in_file_by_line: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 670 | 16404 | my $subs = shift->subs_defined_in_file(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 671 | 16404 | my %line2subs; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 672 | 16404 | for (values %$subs) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 673 | 246152 | ▶ | my $first_line = $_->first_line || 0; # 0 = xsub? | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$_->first_line || 0
MC/DC100%1/1
$_->first_line || 0
$_->first_line
Truth table100%2/2
A
A= $_->first_line
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 674 | 246152 | push @{$line2subs{$first_line}}, $_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 675 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 676 | 16404 | return \%line2subs; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 677 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 678 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 679 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 680 | =head2 file_line_range_of_sub | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 681 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 682 | ($file, $fid, $first, $last, $fi) = $profile->file_line_range_of_sub("main::foo"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 683 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 684 | Returns the filename, fid, and first and last line numbers, and fileinfo object | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 685 | for the specified subroutine (which must be fully qualified with a package name). | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 686 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 687 | Returns an empty list if the subroutine name is not in the profile data. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 688 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 689 | The $fid return is the 'original' fid associated with the file the subroutine was created in. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 690 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 691 | The $file returned is the source file that defined the subroutine. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 692 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 693 | Subroutines that are implemented in XS have a line range of 0,0 and a possibly | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 694 | unknown file (if NYTProf couldn't find a good match based on the package name). | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 695 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 696 | Subroutines that were called but only returned via an exception may have a line | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 697 | range of undef,undef if they're xsubs or were defined before NYTProf was enabled. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 698 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 699 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 700 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 701 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 702 | 29 | ▶ | sub file_line_range_of_sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
file_line_range_of_sub: called CC=5 SCAR=17.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 703 | 29 | my ($self, $sub) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 704 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 705 | 29 | ▶ | my $sub_subinfo = $self->subinfo_of($sub) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 706 | or return; # no such sub; warning supplied by subinfo_of() | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 707 | 27 | my ($fid, $first, $last) = @$sub_subinfo; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 708 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 709 | 27 | ▶ | return if not $fid; # sub has no known file | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 710 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 711 | 27 | ▶ | my $fileinfo = $fid && $self->fileinfo_of($fid) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$fid && $self->fileinfo_of($fid)
MC/DC0%0/2
$fid && $self->fileinfo_of($fid)
$fid
$self->fileinfo_of($fid)
Truth table33%1/3
A && B
A= $fidB= $self->fileinfo_of($fid)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 712 | or croak "No fid_fileinfo for sub $sub fid '$fid'"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 713 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 714 | 27 | return ($fileinfo->filename, $fid, $first, $last, $fileinfo); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 715 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 716 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 717 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 718 | =head2 resolve_fid | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 719 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 720 | $fid = $profile->resolve_fid( $file ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 721 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 722 | Returns the integer I<file id> that corresponds to $file. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 723 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 724 | If $file can't be found and $file looks like a positive integer then it's | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 725 | presumed to already be a fid and is returned. This is used to enable other | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 726 | methods to work with fid or file arguments. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 727 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 728 | If $file can't be found but it uniquely matches the suffix of one of the files | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 729 | then that corresponding fid is returned. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 730 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 731 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 732 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 733 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 734 | 318854 | ▶ | sub resolve_fid { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
resolve_fid: called CC=8 SCAR=20.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 735 | 318854 | my ($self, $file) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 736 | 318854 | ▶ | Carp::confess("No file specified") unless defined $file; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 737 | 318853 | my $resolve_fid_cache = $self->_filename_to_fid; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 738 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 739 | # exact match | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 740 | return $resolve_fid_cache->{$file} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 741 | 318853 | ▶ | if exists $resolve_fid_cache->{$file}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 742 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 743 | # looks like a fid already | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 744 | 286014 | ▶ | return $file | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 745 | if $file =~ m/^\d+$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 746 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 747 | # XXX hack needed to because of how _map_new_to_old deals | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 748 | # with .pmc files because of how ::Reporter works | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 749 | 5 | ▶ | return $self->resolve_fid($file) if $file =~ s/\.pmc$/.pm/; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 750 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 751 | # unfound absolute path, so we're sure we won't find it | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 752 | return undef # XXX carp? | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 753 | 5 | ▶ | if $file =~ m/^\//; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 754 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 755 | # prepend '/' and grep for trailing matches - if just one then use that | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 756 | 4 | my $match = qr{/\Q$file\E$}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 757 | 4 | my @matches = grep {m/$match/} keys %$resolve_fid_cache; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 758 | # XXX: Not clear how to exercise either of the following conditions | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 759 | 4 | ▶ | return $self->resolve_fid($matches[0]) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 760 | if @matches == 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 761 | 4 | ▶ | carp "Can't resolve '$file' to a unique file id (matches @matches)" | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 762 | if @matches >= 2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 763 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 764 | 4 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 765 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 766 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 767 | 700 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 768 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 769 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||