← Index
NYTProf Performance Profile   « line view »
For ./view
  Run on Fri Jul 31 18:42:36 2015
Reported on Fri Jul 31 18:48:13 2015

Filename/usr/share/perl5/vendor_perl/Carp.pm
StatementsExecuted 922 statements in 6.40ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
4021867µs1.23msCarp::::caller_infoCarp::caller_info
211349µs1.58msCarp::::ret_backtraceCarp::ret_backtrace
4831145µs145µsCarp::::_cgcCarp::_cgc
411109µs138µsCarp::::format_argCarp::format_arg
3811104µs108µsCarp::::get_subnameCarp::get_subname
21140µs56µsCarp::::long_error_locCarp::long_error_loc
11132µs32µsCarp::::BEGIN@3Carp::BEGIN@3
21130µs1.72msCarp::::confessCarp::confess
21124µs1.69msCarp::::longmessCarp::longmess
62124µs24µsCarp::::str_len_trimCarp::str_len_trim
11124µs45µsCarp::::BEGIN@399Carp::BEGIN@399
21119µs1.66msCarp::::longmess_heavyCarp::longmess_heavy
11118µs49µsCarp::::BEGIN@398Carp::BEGIN@398
11118µs36µsCarp::::BEGIN@406Carp::BEGIN@406
11116µs37µsCarp::::BEGIN@67Carp::BEGIN@67
11115µs41µsCarp::::BEGIN@4Carp::BEGIN@4
11115µs23µsCarp::::BEGIN@5Carp::BEGIN@5
11114µs34µsCarp::::BEGIN@18Carp::BEGIN@18
11114µs34µsCarp::::BEGIN@413Carp::BEGIN@413
11114µs14µsCarp::::BEGIN@7Carp::BEGIN@7
11113µs37µsCarp::::BEGIN@8Carp::BEGIN@8
11113µs13µsCarp::::BEGIN@105Carp::BEGIN@105
11111µs11µsCarp::::BEGIN@17Carp::BEGIN@17
0000s0sCarp::::__ANON__[:13]Carp::__ANON__[:13]
0000s0sCarp::::__ANON__[:23]Carp::__ANON__[:23]
0000s0sCarp::::carpCarp::carp
0000s0sCarp::::cluckCarp::cluck
0000s0sCarp::::croakCarp::croak
0000s0sCarp::::export_failCarp::export_fail
0000s0sCarp::::get_statusCarp::get_status
0000s0sCarp::::ret_summaryCarp::ret_summary
0000s0sCarp::::short_error_locCarp::short_error_loc
0000s0sCarp::::shortmessCarp::shortmess
0000s0sCarp::::shortmess_heavyCarp::shortmess_heavy
0000s0sCarp::::trustsCarp::trusts
0000s0sCarp::::trusts_directlyCarp::trusts_directly
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package Carp;
2
3396µs132µs
# spent 32µs within Carp::BEGIN@3 which was called: # once (32µs+0s) by CGI::Carp::BEGIN@334 at line 3
{ use 5.006; }
# spent 32µs making 1 call to Carp::BEGIN@3
4247µs266µs
# spent 41µs (15+26) within Carp::BEGIN@4 which was called: # once (15µs+26µs) by CGI::Carp::BEGIN@334 at line 4
use strict;
# spent 41µs making 1 call to Carp::BEGIN@4 # spent 26µs making 1 call to strict::import
5254µs232µs
# spent 23µs (15+8) within Carp::BEGIN@5 which was called: # once (15µs+8µs) by CGI::Carp::BEGIN@334 at line 5
use warnings;
# spent 23µs making 1 call to Carp::BEGIN@5 # spent 8µs making 1 call to warnings::import
6
7
# spent 14µs within Carp::BEGIN@7 which was called: # once (14µs+0s) by CGI::Carp::BEGIN@334 at line 15
BEGIN {
82159µs261µs
# spent 37µs (13+24) within Carp::BEGIN@8 which was called: # once (13µs+24µs) by CGI::Carp::BEGIN@334 at line 8
no strict "refs";
# spent 37µs making 1 call to Carp::BEGIN@8 # spent 24µs making 1 call to strict::unimport
9120µs if(exists($::{"utf8::"}) && exists(*{$::{"utf8::"}}{HASH}->{"is_utf8"}) &&
10 defined(*{*{$::{"utf8::"}}{HASH}->{"is_utf8"}}{CODE})) {
11 *is_utf8 = \&{"utf8::is_utf8"};
12 } else {
13 *is_utf8 = sub { 0 };
14 }
15154µs114µs}
# spent 14µs making 1 call to Carp::BEGIN@7
16
17
# spent 11µs within Carp::BEGIN@17 which was called: # once (11µs+0s) by CGI::Carp::BEGIN@334 at line 25
BEGIN {
182141µs253µs
# spent 34µs (14+20) within Carp::BEGIN@18 which was called: # once (14µs+20µs) by CGI::Carp::BEGIN@334 at line 18
no strict "refs";
# spent 34µs making 1 call to Carp::BEGIN@18 # spent 20µs making 1 call to strict::unimport
19119µs if(exists($::{"utf8::"}) && exists(*{$::{"utf8::"}}{HASH}->{"downgrade"}) &&
20 defined(*{*{$::{"utf8::"}}{HASH}->{"downgrade"}}{CODE})) {
21 *downgrade = \&{"utf8::downgrade"};
22 } else {
23 *downgrade = sub {};
24 }
251371µs111µs}
# spent 11µs making 1 call to Carp::BEGIN@17
26
2711µsour $VERSION = '1.26';
28
291400nsour $MaxEvalLen = 0;
301200nsour $Verbose = 0;
311200nsour $CarpLevel = 0;
321200nsour $MaxArgLen = 64; # How much of each argument to print. 0 = all.
331200nsour $MaxArgNums = 8; # How many arguments to print. 0 = all.
34
351900nsrequire Exporter;
36113µsour @ISA = ('Exporter');
3712µsour @EXPORT = qw(confess croak carp);
3811µsour @EXPORT_OK = qw(cluck verbose longmess shortmess);
3911µsour @EXPORT_FAIL = qw(verbose); # hook to enable verbose mode
40
41# The members of %Internal are packages that are internal to perl.
42# Carp will not report errors from within these packages if it
43# can. The members of %CarpInternal are internal to Perl's warning
44# system. Carp will not report errors from within these packages
45# either, and will not report calls *to* these packages for carp and
46# croak. They replace $CarpLevel, which is deprecated. The
47# $Max(EvalLen|(Arg(Len|Nums)) variables are used to specify how the eval
48# text and function arguments should be formatted when printed.
49
501300nsour %CarpInternal;
511100nsour %Internal;
52
53# disable these by default, so they can live w/o require Carp
5413µs$CarpInternal{Carp}++;
551600ns$CarpInternal{warnings}++;
561700ns$Internal{Exporter}++;
571400ns$Internal{'Exporter::Heavy'}++;
58
59# if the caller specifies verbose usage ("perl -MCarp=verbose script.pl")
60# then the following method will be called by the Exporter which knows
61# to do this thanks to @EXPORT_FAIL, above. $_[1] will contain the word
62# 'verbose'.
63
64sub export_fail { shift; $Verbose = shift if $_[0] eq 'verbose'; @_ }
65
66
# spent 145µs within Carp::_cgc which was called 48 times, avg 3µs/call: # 40 times (119µs+0s) by Carp::caller_info at line 117, avg 3µs/call # 6 times (16µs+0s) by Carp::long_error_loc at line 245, avg 3µs/call # 2 times (10µs+0s) by Carp::longmess at line 79, avg 5µs/call
sub _cgc {
672582µs259µs
# spent 37µs (16+22) within Carp::BEGIN@67 which was called: # once (16µs+22µs) by CGI::Carp::BEGIN@334 at line 67
no strict 'refs';
# spent 37µs making 1 call to Carp::BEGIN@67 # spent 22µs making 1 call to strict::unimport
6848107µs return \&{"CORE::GLOBAL::caller"} if defined &{"CORE::GLOBAL::caller"};
6948115µs return;
70}
71
72
# spent 1.69ms (24µs+1.67) within Carp::longmess which was called 2 times, avg 846µs/call: # 2 times (24µs+1.67ms) by Carp::confess at line 101, avg 846µs/call
sub longmess {
73 # Icky backwards compatibility wrapper. :-(
74 #
75 # The story is that the original implementation hard-coded the
76 # number of call levels to go back, so calls to longmess were off
77 # by one. Other code began calling longmess and expecting this
78 # behaviour, so the replacement has to emulate that behaviour.
7923µs210µs my $cgc = _cgc();
# spent 10µs making 2 calls to Carp::_cgc, avg 5µs/call
8024µs my $call_pack = $cgc ? $cgc->() : caller();
81216µs21.66ms if ( $Internal{$call_pack} or $CarpInternal{$call_pack} ) {
# spent 1.66ms making 2 calls to Carp::longmess_heavy, avg 828µs/call
82 return longmess_heavy(@_);
83 }
84 else {
85 local $CarpLevel = $CarpLevel + 1;
86 return longmess_heavy(@_);
87 }
88}
89
901200nsour @CARP_NOT;
91
92sub shortmess {
93 my $cgc = _cgc();
94
95 # Icky backwards compatibility wrapper. :-(
96 local @CARP_NOT = $cgc ? $cgc->() : caller();
97 shortmess_heavy(@_);
98}
99
100sub croak { die shortmess @_ }
101256µs21.69ms
# spent 1.72ms (30µs+1.69) within Carp::confess which was called 2 times, avg 861µs/call: # 2 times (30µs+1.69ms) by JSON::BEGIN@2 or JSON::_load_xs at line 2 of (eval 12)[JSON.pm:252], avg 861µs/call
sub confess { die longmess @_ }
# spent 1.69ms making 2 calls to Carp::longmess, avg 846µs/call
102sub carp { warn shortmess @_ }
103sub cluck { warn longmess @_ }
104
105
# spent 13µs within Carp::BEGIN@105 which was called: # once (13µs+0s) by CGI::Carp::BEGIN@334 at line 112
BEGIN {
106114µs if("$]" >= 5.015002 || ("$]" >= 5.014002 && "$]" < 5.015) ||
107 ("$]" >= 5.012005 && "$]" < 5.013)) {
108 *CALLER_OVERRIDE_CHECK_OK = sub () { 1 };
109 } else {
110 *CALLER_OVERRIDE_CHECK_OK = sub () { 0 };
111 }
11212.63ms113µs}
# spent 13µs making 1 call to Carp::BEGIN@105
113
114
# spent 1.23ms (867µs+366µs) within Carp::caller_info which was called 40 times, avg 31µs/call: # 38 times (778µs+250µs) by Carp::ret_backtrace at line 302, avg 27µs/call # 2 times (89µs+116µs) by Carp::ret_backtrace at line 288, avg 102µs/call
sub caller_info {
1154022µs my $i = shift(@_) + 1;
116406µs my %call_info;
1174039µs40119µs my $cgc = _cgc();
# spent 119µs making 40 calls to Carp::_cgc, avg 3µs/call
118 {
119 # Some things override caller() but forget to implement the
120 # @DB::args part of it, which we need. We check for this by
121 # pre-populating @DB::args with a sentinel which no-one else
122 # has the address of, so that we can detect whether @DB::args
123 # has been properly populated. However, on earlier versions
124 # of perl this check tickles a bug in CORE::caller() which
125 # leaks memory. So we only check on fixed perls.
1268083µs @DB::args = \$i if CALLER_OVERRIDE_CHECK_OK;
127 package DB;
128
12940259µs
- -
1334020µs unless ( defined $call_info{pack} ) {
134 return ();
135 }
136
1373857µs38108µs my $sub_name = Carp::get_subname( \%call_info );
# spent 108µs making 38 calls to Carp::get_subname, avg 3µs/call
1383814µs if ( $call_info{has_args} ) {
139153µs my @args;
1401512µs if (CALLER_OVERRIDE_CHECK_OK && @DB::args == 1
141 && ref $DB::args[0] eq ref \$i
142 && $DB::args[0] == \$i ) {
143 @DB::args = (); # Don't let anyone see the address of $i
144 local $@;
145 my $where = eval {
146 my $func = $cgc or return '';
147 my $gv =
148 *{
149 ( $::{"B::"} || return '') # B stash
150 ->{svref_2object} || return '' # entry in stash
151 }{CODE} # coderef in entry
152 ->($func)->GV;
153 my $package = $gv->STASH->NAME;
154 my $subname = $gv->NAME;
155 return unless defined $package && defined $subname;
156
157 # returning CORE::GLOBAL::caller isn't useful for tracing the cause:
158 return if $package eq 'CORE::GLOBAL' && $subname eq 'caller';
159 " in &${package}::$subname";
160 } || '';
161 @args
162 = "** Incomplete caller override detected$where; \@DB::args were not set **";
163 }
164 else {
1651924µs4138µs @args = map { Carp::format_arg($_) } @DB::args;
# spent 138µs making 4 calls to Carp::format_arg, avg 35µs/call
166 }
167157µs if ( $MaxArgNums and @args > $MaxArgNums )
168 { # More than we want to show?
169 $#args = $MaxArgNums;
170 push @args, '...';
171 }
172
173 # Push the args onto the subroutine
1741518µs $sub_name .= '(' . join( ', ', @args ) . ')';
175 }
1763824µs $call_info{sub_name} = $sub_name;
17738223µs return wantarray() ? %call_info : \%call_info;
178}
179
180# Transform an argument to a function into a string.
181
# spent 138µs (109+30) within Carp::format_arg which was called 4 times, avg 35µs/call: # 4 times (109µs+30µs) by Carp::caller_info at line 165, avg 35µs/call
sub format_arg {
18245µs my $arg = shift;
1834900ns if ( ref($arg) ) {
184 $arg = defined($overload::VERSION) ? overload::StrVal($arg) : "$arg";
185 }
18642µs if ( defined($arg) ) {
187418µs $arg =~ s/'/\\'/g;
18847µs420µs $arg = str_len_trim( $arg, $MaxArgLen );
# spent 20µs making 4 calls to Carp::str_len_trim, avg 5µs/call
189
190 # Quote it?
191 # Downgrade, and use [0-9] rather than \d, to avoid loading
192 # Unicode tables, which would be liable to fail if we're
193 # processing a syntax error.
194417µs46µs downgrade($arg, 1);
# spent 6µs making 4 calls to utf8::downgrade, avg 1µs/call
195414µs $arg = "'$arg'" unless $arg =~ /^-?[0-9.]+\z/;
196 }
197 else {
198 $arg = 'undef';
199 }
200
201 # The following handling of "control chars" is direct from
202 # the original code - it is broken on Unicode though.
203 # Suggestions?
204 is_utf8($arg)
205442µs44µs or $arg =~ s/([[:cntrl:]]|[[:^ascii:]])/sprintf("\\x{%x}",ord($1))/eg;
# spent 4µs making 4 calls to utf8::is_utf8, avg 900ns/call
206416µs return $arg;
207}
208
209# Takes an inheritance cache and a package and returns
210# an anon hash of known inheritances and anon array of
211# inheritances which consequences have not been figured
212# for.
213sub get_status {
214 my $cache = shift;
215 my $pkg = shift;
216 $cache->{$pkg} ||= [ { $pkg => $pkg }, [ trusts_directly($pkg) ] ];
217 return @{ $cache->{$pkg} };
218}
219
220# Takes the info from caller() and figures out the name of
221# the sub/require/eval
222
# spent 108µs (104+4) within Carp::get_subname which was called 38 times, avg 3µs/call: # 38 times (104µs+4µs) by Carp::caller_info at line 137, avg 3µs/call
sub get_subname {
2233811µs my $info = shift;
2243814µs if ( defined( $info->{evaltext} ) ) {
225124µs my $eval = $info->{evaltext};
2261231µs if ( $info->{is_require} ) {
227 return "require $eval";
228 }
229 else {
23022µs $eval =~ s/([\\\'])/\\$1/g;
23129µs24µs return "eval '" . str_len_trim( $eval, $MaxEvalLen ) . "'";
# spent 4µs making 2 calls to Carp::str_len_trim, avg 2µs/call
232 }
233 }
234
2352674µs return ( $info->{sub} eq '(eval)' ) ? 'eval {...}' : $info->{sub};
236}
237
238# Figures out what call (from the point of view of the caller)
239# the long error backtrace should start at.
240
# spent 56µs (40+16) within Carp::long_error_loc which was called 2 times, avg 28µs/call: # 2 times (40µs+16µs) by Carp::longmess_heavy at line 270, avg 28µs/call
sub long_error_loc {
2412500ns my $i;
24221µs my $lvl = $CarpLevel;
243 {
24482µs ++$i;
24566µs616µs my $cgc = _cgc();
# spent 16µs making 6 calls to Carp::_cgc, avg 3µs/call
24669µs my $pkg = $cgc ? $cgc->($i) : caller($i);
24761µs unless ( defined($pkg) ) {
248
249 # This *shouldn't* happen.
250 if (%Internal) {
251 local %Internal;
252 $i = long_error_loc();
253 last;
254 }
255 else {
256
257 # OK, now I am irritated.
258 return 2;
259 }
260 }
26165µs redo if $CarpInternal{$pkg};
26221µs redo unless 0 > --$lvl;
26322µs redo if $Internal{$pkg};
264 }
26527µs return $i - 1;
266}
267
268
# spent 1.66ms (19µs+1.64) within Carp::longmess_heavy which was called 2 times, avg 828µs/call: # 2 times (19µs+1.64ms) by Carp::longmess at line 81, avg 828µs/call
sub longmess_heavy {
2692800ns return @_ if ref( $_[0] ); # don't break references as exceptions
27023µs256µs my $i = long_error_loc();
# spent 56µs making 2 calls to Carp::long_error_loc, avg 28µs/call
271210µs21.58ms return ret_backtrace( $i, @_ );
# spent 1.58ms making 2 calls to Carp::ret_backtrace, avg 791µs/call
272}
273
274# Returns a full stack backtrace starting from where it is
275# told.
276
# spent 1.58ms (349µs+1.23) within Carp::ret_backtrace which was called 2 times, avg 791µs/call: # 2 times (349µs+1.23ms) by Carp::longmess_heavy at line 271, avg 791µs/call
sub ret_backtrace {
27724µs my ( $i, @error ) = @_;
2782300ns my $mess;
279212µs my $err = join '', @error;
2802300ns $i++;
281
2822800ns my $tid_msg = '';
28321µs if ( defined &threads::tid ) {
284 my $tid = threads->tid;
285 $tid_msg = " thread $tid" if $tid;
286 }
287
288212µs2205µs my %i = caller_info($i);
# spent 205µs making 2 calls to Carp::caller_info, avg 102µs/call
28927µs $mess = "$err at $i{file} line $i{line}$tid_msg";
29022µs if( defined $. ) {
291 local $@ = '';
292 local $SIG{__DIE__};
293 eval {
294 CORE::die;
295 };
296 if($@ =~ /^Died at .*(, <.*?> line \d+).$/ ) {
297 $mess .= $1;
298 }
299 }
3002700ns $mess .= "\.\n";
301
3022237µs381.03ms while ( my %i = caller_info( ++$i ) ) {
# spent 1.03ms making 38 calls to Carp::caller_info, avg 27µs/call
303 $mess .= "\t$i{sub_name} called at $i{file} line $i{line}$tid_msg\n";
304 }
305
306217µs return $mess;
307}
308
309sub ret_summary {
310 my ( $i, @error ) = @_;
311 my $err = join '', @error;
312 $i++;
313
314 my $tid_msg = '';
315 if ( defined &threads::tid ) {
316 my $tid = threads->tid;
317 $tid_msg = " thread $tid" if $tid;
318 }
319
320 my %i = caller_info($i);
321 return "$err at $i{file} line $i{line}$tid_msg\.\n";
322}
323
324sub short_error_loc {
325 # You have to create your (hash)ref out here, rather than defaulting it
326 # inside trusts *on a lexical*, as you want it to persist across calls.
327 # (You can default it on $_[2], but that gets messy)
328 my $cache = {};
329 my $i = 1;
330 my $lvl = $CarpLevel;
331 {
332 my $cgc = _cgc();
333 my $called = $cgc ? $cgc->($i) : caller($i);
334 $i++;
335 my $caller = $cgc ? $cgc->($i) : caller($i);
336
337 return 0 unless defined($caller); # What happened?
338 redo if $Internal{$caller};
339 redo if $CarpInternal{$caller};
340 redo if $CarpInternal{$called};
341 redo if trusts( $called, $caller, $cache );
342 redo if trusts( $caller, $called, $cache );
343 redo unless 0 > --$lvl;
344 }
345 return $i - 1;
346}
347
348sub shortmess_heavy {
349 return longmess_heavy(@_) if $Verbose;
350 return @_ if ref( $_[0] ); # don't break references as exceptions
351 my $i = short_error_loc();
352 if ($i) {
353 ret_summary( $i, @_ );
354 }
355 else {
356 longmess_heavy(@_);
357 }
358}
359
360# If a string is too long, trims it with ...
361
# spent 24µs within Carp::str_len_trim which was called 6 times, avg 4µs/call: # 4 times (20µs+0s) by Carp::format_arg at line 188, avg 5µs/call # 2 times (4µs+0s) by Carp::get_subname at line 231, avg 2µs/call
sub str_len_trim {
36264µs my $str = shift;
36362µs my $max = shift || 0;
36469µs if ( 2 < $max and $max < length($str) ) {
365 substr( $str, $max - 3 ) = '...';
366 }
367620µs return $str;
368}
369
370# Takes two packages and an optional cache. Says whether the
371# first inherits from the second.
372#
373# Recursive versions of this have to work to avoid certain
374# possible endless loops, and when following long chains of
375# inheritance are less efficient.
376sub trusts {
377 my $child = shift;
378 my $parent = shift;
379 my $cache = shift;
380 my ( $known, $partial ) = get_status( $cache, $child );
381
382 # Figure out consequences until we have an answer
383 while ( @$partial and not exists $known->{$parent} ) {
384 my $anc = shift @$partial;
385 next if exists $known->{$anc};
386 $known->{$anc}++;
387 my ( $anc_knows, $anc_partial ) = get_status( $cache, $anc );
388 my @found = keys %$anc_knows;
389 @$known{@found} = ();
390 push @$partial, @$anc_partial;
391 }
392 return exists $known->{$parent};
393}
394
395# Takes a package and gives a list of those trusted directly
396sub trusts_directly {
397 my $class = shift;
398264µs279µs
# spent 49µs (18+30) within Carp::BEGIN@398 which was called: # once (18µs+30µs) by CGI::Carp::BEGIN@334 at line 398
no strict 'refs';
# spent 49µs making 1 call to Carp::BEGIN@398 # spent 30µs making 1 call to strict::unimport
3992131µs267µs
# spent 45µs (24+22) within Carp::BEGIN@399 which was called: # once (24µs+22µs) by CGI::Carp::BEGIN@334 at line 399
no warnings 'once';
# spent 45µs making 1 call to Carp::BEGIN@399 # spent 22µs making 1 call to warnings::unimport
400 return @{"$class\::CARP_NOT"}
401 ? @{"$class\::CARP_NOT"}
402 : @{"$class\::ISA"};
403}
404
40512µsif(!defined($warnings::VERSION) ||
406373µs254µs
# spent 36µs (18+18) within Carp::BEGIN@406 which was called: # once (18µs+18µs) by CGI::Carp::BEGIN@334 at line 406
do { no warnings "numeric"; $warnings::VERSION < 1.03 }) {
# spent 36µs making 1 call to Carp::BEGIN@406 # spent 18µs making 1 call to warnings::unimport
407 # Very old versions of warnings.pm import from Carp. This can go
408 # wrong due to the circular dependency. If Carp is invoked before
409 # warnings, then Carp starts by loading warnings, then warnings
410 # tries to import from Carp, and gets nothing because Carp is in
411 # the process of loading and hasn't defined its import method yet.
412 # So we work around that by manually exporting to warnings here.
4132132µs254µs
# spent 34µs (14+20) within Carp::BEGIN@413 which was called: # once (14µs+20µs) by CGI::Carp::BEGIN@334 at line 413
no strict "refs";
# spent 34µs making 1 call to Carp::BEGIN@413 # spent 20µs making 1 call to strict::unimport
414 *{"warnings::$_"} = \&$_ foreach @EXPORT;
415}
416
417132µs1;
418
419__END__