← Index
NYTProf Performance Profile   « block view • line view • sub view »
For /usr/local/src/github.com/foswiki/core/bin/view
  Run on Sun Dec 4 17:17:59 2011
Reported on Sun Dec 4 17:26:38 2011

Filename/usr/share/perl/5.14/Exporter/Heavy.pm
StatementsExecuted 2514 statements in 15.5ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
281111.6ms12.9msExporter::Heavy::::heavy_exportExporter::Heavy::heavy_export
454311.08ms1.08msExporter::Heavy::::CORE:substExporter::Heavy::CORE:subst (opcode)
7441185µs185µsExporter::Heavy::::CORE:matchExporter::Heavy::CORE:match (opcode)
21192µs92µsExporter::Heavy::::_push_tagsExporter::Heavy::_push_tags
11137µs45µsExporter::Heavy::::BEGIN@3Exporter::Heavy::BEGIN@3
21127µs118µsExporter::Heavy::::heavy_export_tagsExporter::Heavy::heavy_export_tags
11127µs65µsExporter::Heavy::::BEGIN@183Exporter::Heavy::BEGIN@183
11116µs50µsExporter::Heavy::::BEGIN@4Exporter::Heavy::BEGIN@4
0000s0sExporter::Heavy::::__ANON__[:38]Exporter::Heavy::__ANON__[:38]
0000s0sExporter::Heavy::::__ANON__[:44]Exporter::Heavy::__ANON__[:44]
0000s0sExporter::Heavy::::_rebuild_cacheExporter::Heavy::_rebuild_cache
0000s0sExporter::Heavy::::heavy_export_ok_tagsExporter::Heavy::heavy_export_ok_tags
0000s0sExporter::Heavy::::heavy_export_to_levelExporter::Heavy::heavy_export_to_level
0000s0sExporter::Heavy::::heavy_require_versionExporter::Heavy::heavy_require_version
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package Exporter::Heavy;
2
3254µs253µs
# spent 45µs (37+8) within Exporter::Heavy::BEGIN@3 which was called: # once (37µs+8µs) by Exporter::as_heavy at line 3
use strict;
# spent 45µs making 1 call to Exporter::Heavy::BEGIN@3 # spent 8µs making 1 call to strict::import
421.70ms283µs
# spent 50µs (16+33) within Exporter::Heavy::BEGIN@4 which was called: # once (16µs+33µs) by Exporter::as_heavy at line 4
no strict 'refs';
# spent 50µs making 1 call to Exporter::Heavy::BEGIN@4 # spent 33µs making 1 call to strict::unimport
5
6# On one line so MakeMaker will see it.
724µsrequire Exporter; our $VERSION = $Exporter::VERSION;
8
9#
10# We go to a lot of trouble not to 'require Carp' at file scope,
11# because Carp requires Exporter, and something has to give.
12#
13
14sub _rebuild_cache {
15 my ($pkg, $exports, $cache) = @_;
16 s/^&// foreach @$exports;
17 @{$cache}{@$exports} = (1) x @$exports;
18 my $ok = \@{"${pkg}::EXPORT_OK"};
19 if (@$ok) {
20 s/^&// foreach @$ok;
21 @{$cache}{@$ok} = (1) x @$ok;
22 }
23}
24
25
# spent 12.9ms (11.6+1.30) within Exporter::Heavy::heavy_export which was called 28 times, avg 460µs/call: # 28 times (11.6ms+1.30ms) by Exporter::import at line 25 of Exporter.pm, avg 460µs/call
sub heavy_export {
26
27 # First make import warnings look like they're coming from the "use".
28 local $SIG{__WARN__} = sub {
29 my $text = shift;
30 if ($text =~ s/ at \S*Exporter\S*.pm line \d+.*\n//) {
31 require Carp;
32 local $Carp::CarpLevel = 1; # ignore package calling us too.
33 Carp::carp($text);
34 }
35 else {
36 warn $text;
37 }
382801.71ms };
39 local $SIG{__DIE__} = sub {
40 require Carp;
41 local $Carp::CarpLevel = 1; # ignore package calling us too.
42 Carp::croak("$_[0]Illegal null symbol in \@${1}::EXPORT")
43 if $_[0] =~ /^Unable to create sub named "(.*?)::"/;
44 };
45
46 my($pkg, $callpkg, @imports) = @_;
47 my($type, $sym, $cache_is_current, $oops);
482859µs my($exports, $export_cache) = (\@{"${pkg}::EXPORT"},
49 $Exporter::Cache{$pkg} ||= {});
50
51140745µs if (@imports) {
52 if (!%$export_cache) {
53 _rebuild_cache ($pkg, $exports, $export_cache);
54 $cache_is_current = 1;
55 }
56
57189786µs45130µs if (grep m{^[/!:]}, @imports) {
# spent 130µs making 45 calls to Exporter::Heavy::CORE:match, avg 3µs/call
582756µs my $tagsref = \%{"${pkg}::EXPORT_TAGS"};
59 my $tagdata;
60 my %imports;
61 my($remove, $spec, @names, @allexports);
62 # negated first item implies starting with default set:
632751µs unshift @imports, ':DEFAULT' if $imports[0] =~ m/^!/;
# spent 51µs making 27 calls to Exporter::Heavy::CORE:match, avg 2µs/call
64 foreach $spec (@imports){
65128701µs3249µs $remove = $spec =~ s/^!//;
# spent 49µs making 32 calls to Exporter::Heavy::CORE:subst, avg 2µs/call
66
6732129µs3393µs if ($spec =~ s/^://){
# spent 91µs making 32 calls to Exporter::Heavy::CORE:subst, avg 3µs/call # spent 2µs making 1 call to Exporter::Heavy::CORE:match
6831210µs if ($spec eq 'DEFAULT'){
69 @names = @$exports;
70 }
71 elsif ($tagdata = $tagsref->{$spec}) {
72 @names = @$tagdata;
73 }
74 else {
75 warn qq["$spec" is not defined in %${pkg}::EXPORT_TAGS];
76 ++$oops;
77 next;
78 }
79 }
80 elsif ($spec =~ m:^/(.*)/$:){
81 my $patn = $1;
82 @allexports = keys %$export_cache unless @allexports; # only do keys once
83 @names = grep(/$patn/, @allexports); # not anchored by default
84 }
85 else {
86 @names = ($spec); # is a normal symbol name
87 }
88
89 warn "Import ".($remove ? "del":"add").": @names "
90 if $Exporter::Verbose;
91
9232338µs if ($remove) {
93 foreach $sym (@names) { delete $imports{$sym} }
94 }
95 else {
96 @imports{@names} = (1) x @names;
97 }
98 }
99 @imports = keys %imports;
100 }
101
102 my @carp;
103 foreach $sym (@imports) {
1043911.09ms if (!$export_cache->{$sym}) {
105348µs13µs if ($sym =~ m/^\d/) {
# spent 3µs making 1 call to Exporter::Heavy::CORE:match
106132µs $pkg->VERSION($sym); # inherit from UNIVERSAL
# spent 32µs making 1 call to UNIVERSAL::VERSION
107 # If the version number was the only thing specified
108 # then we should act as if nothing was specified:
109 if (@imports == 1) {
110 @imports = @$exports;
111 last;
112 }
113 # We need a way to emulate 'use Foo ()' but still
114 # allow an easy version check: "use Foo 1.23, ''";
115 if (@imports == 2 and !$imports[1]) {
116 @imports = ();
117 last;
118 }
119 } elsif ($sym !~ s/^&// || !$export_cache->{$sym}) {
120 # Last chance - see if they've updated EXPORT_OK since we
121 # cached it.
122
123 unless ($cache_is_current) {
124 %$export_cache = ();
125 _rebuild_cache ($pkg, $exports, $export_cache);
126 $cache_is_current = 1;
127 }
128
129 if (!$export_cache->{$sym}) {
130 # accumulate the non-exports
131 push @carp,
132 qq["$sym" is not exported by the $pkg module\n];
133 $oops++;
134 }
135 }
136 }
137 }
138 if ($oops) {
139 require Carp;
140 Carp::croak("@{carp}Can't continue after import errors");
141 }
142 }
143 else {
144 @imports = @$exports;
145 }
146
1472865µs my($fail, $fail_cache) = (\@{"${pkg}::EXPORT_FAIL"},
148 $Exporter::FailCache{$pkg} ||= {});
149
150 if (@$fail) {
151 if (!%$fail_cache) {
152 # Build cache of symbols. Optimise the lookup by adding
153 # barewords twice... both with and without a leading &.
154 # (Technique could be applied to $export_cache at cost of memory)
155 my @expanded = map { /^\w/ ? ($_, '&'.$_) : $_ } @$fail;
156 warn "${pkg}::EXPORT_FAIL cached: @expanded" if $Exporter::Verbose;
157 @{$fail_cache}{@expanded} = (1) x @expanded;
158 }
159 my @failed;
160 foreach $sym (@imports) { push(@failed, $sym) if $fail_cache->{$sym} }
161 if (@failed) {
162 @failed = $pkg->export_fail(@failed);
163 foreach $sym (@failed) {
164 require Carp;
165 Carp::carp(qq["$sym" is not implemented by the $pkg module ],
166 "on this architecture");
167 }
168 if (@failed) {
169 require Carp;
170 Carp::croak("Can't continue after import errors");
171 }
172 }
173 }
174
175 warn "Importing into $callpkg from $pkg: ",
176 join(", ",sort @imports) if $Exporter::Verbose;
177
178 foreach $sym (@imports) {
179 # shortcut for the common case of no type character
18011707.01ms390943µs (*{"${callpkg}::$sym"} = \&{"${pkg}::$sym"}, next)
# spent 943µs making 390 calls to Exporter::Heavy::CORE:subst, avg 2µs/call
181 unless $sym =~ s/^(\W)//;
182 $type = $1;
1832701µs2103µs
# spent 65µs (27+38) within Exporter::Heavy::BEGIN@183 which was called: # once (27µs+38µs) by Exporter::as_heavy at line 183
no warnings 'once';
# spent 65µs making 1 call to Exporter::Heavy::BEGIN@183 # spent 38µs making 1 call to warnings::unimport
184 *{"${callpkg}::$sym"} =
185 $type eq '&' ? \&{"${pkg}::$sym"} :
186 $type eq '$' ? \${"${pkg}::$sym"} :
187 $type eq '@' ? \@{"${pkg}::$sym"} :
188 $type eq '%' ? \%{"${pkg}::$sym"} :
189 $type eq '*' ? *{"${pkg}::$sym"} :
190 do { require Carp; Carp::croak("Can't export symbol: $type$sym") };
191 }
192}
193
194sub heavy_export_to_level
195{
196 my $pkg = shift;
197 my $level = shift;
198 (undef) = shift; # XXX redundant arg
199 my $callpkg = caller($level);
200 $pkg->export($callpkg, @_);
201}
202
203# Utility functions
204
205
# spent 92µs within Exporter::Heavy::_push_tags which was called 2 times, avg 46µs/call: # 2 times (92µs+0s) by Exporter::Heavy::heavy_export_tags at line 227, avg 46µs/call
sub _push_tags {
2061060µs my($pkg, $var, $syms) = @_;
207 my @nontag = ();
20824µs my $export_tags = \%{"${pkg}::EXPORT_TAGS"};
209 push(@{"${pkg}::$var"},
2101232µs map { $export_tags->{$_} ? @{$export_tags->{$_}}
211 : scalar(push(@nontag,$_),$_) }
212 (@$syms) ? @$syms : keys %$export_tags);
213 if (@nontag and $^W) {
214 # This may change to a die one day
215 require Carp;
216 Carp::carp(join(", ", @nontag)." are not tags of $pkg");
217 }
218}
219
220sub heavy_require_version {
221 my($self, $wanted) = @_;
222 my $pkg = ref $self || $self;
223 return ${pkg}->VERSION($wanted);
224}
225
226
# spent 118µs (27+92) within Exporter::Heavy::heavy_export_tags which was called 2 times, avg 59µs/call: # 2 times (27µs+92µs) by Foswiki::BEGIN@46 or Foswiki::Sandbox::BEGIN@39 at line 86 of Exporter.pm, avg 59µs/call
sub heavy_export_tags {
227225µs292µs _push_tags((caller)[0], "EXPORT", \@_);
# spent 92µs making 2 calls to Exporter::Heavy::_push_tags, avg 46µs/call
228}
229
230sub heavy_export_ok_tags {
231 _push_tags((caller)[0], "EXPORT_OK", \@_);
232}
233
23417µs1;
 
# spent 185µs within Exporter::Heavy::CORE:match which was called 74 times, avg 3µs/call: # 45 times (130µs+0s) by Exporter::Heavy::heavy_export at line 57, avg 3µs/call # 27 times (51µs+0s) by Exporter::Heavy::heavy_export at line 63, avg 2µs/call # once (3µs+0s) by Exporter::Heavy::heavy_export at line 105 # once (2µs+0s) by Exporter::Heavy::heavy_export at line 67
sub Exporter::Heavy::CORE:match; # opcode
# spent 1.08ms within Exporter::Heavy::CORE:subst which was called 454 times, avg 2µs/call: # 390 times (943µs+0s) by Exporter::Heavy::heavy_export at line 180, avg 2µs/call # 32 times (91µs+0s) by Exporter::Heavy::heavy_export at line 67, avg 3µs/call # 32 times (49µs+0s) by Exporter::Heavy::heavy_export at line 65, avg 2µs/call
sub Exporter::Heavy::CORE:subst; # opcode