← Index
NYTProf Performance Profile   « block view • line view • sub view »
For ddd2.pl
  Run on Tue May 25 16:52:24 2010
Reported on Tue May 25 16:57:00 2010

File /usr/local/lib/perl5/5.8.8/Exporter/Heavy.pm
Statements Executed 1384
Statement Execution Time 32.7ms
Subroutines — ordered by exclusive time
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
221124.6ms28.5msExporter::Heavy::::heavy_exportExporter::Heavy::heavy_export
743323.78ms3.78msExporter::Heavy::::CORE:substExporter::Heavy::CORE:subst (opcode)
611493µs493µsExporter::Heavy::::_push_tagsExporter::Heavy::_push_tags
3132203µs203µsExporter::Heavy::::CORE:matchExporter::Heavy::CORE:match (opcode)
611201µs694µsExporter::Heavy::::heavy_export_ok_tagsExporter::Heavy::heavy_export_ok_tags
11163µs268µsExporter::Heavy::::heavy_require_versionExporter::Heavy::heavy_require_version
0000s0sExporter::Heavy::::BEGINExporter::Heavy::BEGIN
0000s0sExporter::Heavy::::__ANON__[:53]Exporter::Heavy::__ANON__[:53]
0000s0sExporter::Heavy::::__ANON__[:59]Exporter::Heavy::__ANON__[:59]
0000s0sExporter::Heavy::::_rebuild_cacheExporter::Heavy::_rebuild_cache
0000s0sExporter::Heavy::::heavy_export_tagsExporter::Heavy::heavy_export_tags
0000s0sExporter::Heavy::::heavy_export_to_levelExporter::Heavy::heavy_export_to_level
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
3392µs126µsuse strict;
# spent 26µs making 1 call to strict::import
432.96ms188µsno strict 'refs';
# spent 88µs making 1 call to strict::unimport
5
6# On one line so MakeMaker will see it.
7211µsrequire Exporter; our $VERSION = $Exporter::VERSION;
816µs$Carp::Internal{"Exporter::Heavy"} = 1;
9
10=head1 NAME
11
12Exporter::Heavy - Exporter guts
13
14=head1 SYNOPSIS
15
16(internal use only)
17
18=head1 DESCRIPTION
19
20No user-serviceable parts inside.
21
22=cut
23
24#
25# We go to a lot of trouble not to 'require Carp' at file scope,
26# because Carp requires Exporter, and something has to give.
27#
28
29sub _rebuild_cache {
30 my ($pkg, $exports, $cache) = @_;
31 s/^&// foreach @$exports;
32 @{$cache}{@$exports} = (1) x @$exports;
33 my $ok = \@{"${pkg}::EXPORT_OK"};
34 if (@$ok) {
35 s/^&// foreach @$ok;
36 @{$cache}{@$ok} = (1) x @$ok;
37 }
38}
39
40
# spent 28.5ms (24.6+3.98) within Exporter::Heavy::heavy_export which was called 22 times, avg 1.30ms/call: # 22 times (24.6ms+3.98ms) by Exporter::import or FileHandle::import or IO::Socket::import at line 26 of Exporter.pm, avg 1.30ms/call
sub heavy_export {
41
42 # First make import warnings look like they're coming from the "use".
43 local $SIG{__WARN__} = sub {
44 my $text = shift;
45 if ($text =~ s/ at \S*Exporter\S*.pm line \d+.*\n//) {
46 require Carp;
47 local $Carp::CarpLevel = 1; # ignore package calling us too.
48 Carp::carp($text);
49 }
50 else {
51 warn $text;
52 }
5322331µs };
54 local $SIG{__DIE__} = sub {
55 require Carp;
56 local $Carp::CarpLevel = 1; # ignore package calling us too.
57 Carp::croak("$_[0]Illegal null symbol in \@${1}::EXPORT")
58 if $_[0] =~ /^Unable to create sub named "(.*?)::"/;
5922193µs };
60
6122188µs my($pkg, $callpkg, @imports) = @_;
622298µs my($type, $sym, $cache_is_current, $oops);
6322249µs my($exports, $export_cache) = (\@{"${pkg}::EXPORT"},
64 $Exporter::Cache{$pkg} ||= {});
65
6622273µs if (@imports) {
671192µs if (!%$export_cache) {
68 _rebuild_cache ($pkg, $exports, $export_cache);
69 $cache_is_current = 1;
70 }
71
7211416µs16103µs if (grep m{^[/!:]}, @imports) {
# spent 103µs making 16 calls to Exporter::Heavy::CORE:match, avg 6µs/call
7311104µs my $tagsref = \%{"${pkg}::EXPORT_TAGS"};
741146µs my $tagdata;
751149µs my %imports;
761153µs my($remove, $spec, @names, @allexports);
77 # negated first item implies starting with default set:
7811218µs1178µs unshift @imports, ':DEFAULT' if $imports[0] =~ m/^!/;
# spent 78µs making 11 calls to Exporter::Heavy::CORE:match, avg 7µs/call
7911115µs foreach $spec (@imports){
8016284µs1674µs $remove = $spec =~ s/^!//;
# spent 74µs making 16 calls to Exporter::Heavy::CORE:subst, avg 5µs/call
81
8216417µs20111µs if ($spec =~ s/^://){
# spent 89µs making 16 calls to Exporter::Heavy::CORE:subst, avg 6µs/call # spent 22µs making 4 calls to Exporter::Heavy::CORE:match, avg 6µs/call
8312270µs if ($spec eq 'DEFAULT'){
84 @names = @$exports;
85 }
86 elsif ($tagdata = $tagsref->{$spec}) {
87 @names = @$tagdata;
88 }
89 else {
90 warn qq["$spec" is not defined in %${pkg}::EXPORT_TAGS];
91 ++$oops;
92 next;
93 }
94 }
95 elsif ($spec =~ m:^/(.*)/$:){
96 my $patn = $1;
97 @allexports = keys %$export_cache unless @allexports; # only do keys once
98 @names = grep(/$patn/, @allexports); # not anchored by default
99 }
100 else {
101428µs @names = ($spec); # is a normal symbol name
102 }
103
1041690µs warn "Import ".($remove ? "del":"add").": @names "
105 if $Exporter::Verbose;
106
10716246µs if ($remove) {
108 foreach $sym (@names) { delete $imports{$sym} }
109 }
110 else {
11116260µs @imports{@names} = (1) x @names;
112 }
113 }
11411250µs @imports = keys %imports;
115 }
116
1171148µs my @carp;
11811106µs foreach $sym (@imports) {
1191351.25ms if (!$export_cache->{$sym}) {
120 if ($sym =~ m/^\d/) {
121 $pkg->VERSION($sym); # inherit from UNIVERSAL
122 # If the version number was the only thing specified
123 # then we should act as if nothing was specified:
124 if (@imports == 1) {
125 @imports = @$exports;
126 last;
127 }
128 # We need a way to emulate 'use Foo ()' but still
129 # allow an easy version check: "use Foo 1.23, ''";
130 if (@imports == 2 and !$imports[1]) {
131 @imports = ();
132 last;
133 }
134 } elsif ($sym !~ s/^&// || !$export_cache->{$sym}) {
135 # Last chance - see if they've updated EXPORT_OK since we
136 # cached it.
137
138 unless ($cache_is_current) {
139 %$export_cache = ();
140 _rebuild_cache ($pkg, $exports, $export_cache);
141 $cache_is_current = 1;
142 }
143
144 if (!$export_cache->{$sym}) {
145 # accumulate the non-exports
146 push @carp,
147 qq["$sym" is not exported by the $pkg module\n];
148 $oops++;
149 }
150 }
151 }
152 }
1531151µs if ($oops) {
154 require Carp;
155 Carp::croak("@{carp}Can't continue after import errors");
156 }
157 }
158 else {
15911550µs @imports = @$exports;
160 }
161
16222277µs my($fail, $fail_cache) = (\@{"${pkg}::EXPORT_FAIL"},
163 $Exporter::FailCache{$pkg} ||= {});
164
16522105µs if (@$fail) {
166 if (!%$fail_cache) {
167 # Build cache of symbols. Optimise the lookup by adding
168 # barewords twice... both with and without a leading &.
169 # (Technique could be applied to $export_cache at cost of memory)
170 my @expanded = map { /^\w/ ? ($_, '&'.$_) : $_ } @$fail;
171 warn "${pkg}::EXPORT_FAIL cached: @expanded" if $Exporter::Verbose;
172 @{$fail_cache}{@expanded} = (1) x @expanded;
173 }
174 my @failed;
175 foreach $sym (@imports) { push(@failed, $sym) if $fail_cache->{$sym} }
176 if (@failed) {
177 @failed = $pkg->export_fail(@failed);
178 foreach $sym (@failed) {
179 require Carp;
180 Carp::carp(qq["$sym" is not implemented by the $pkg module ],
181 "on this architecture");
182 }
183 if (@failed) {
184 require Carp;
185 Carp::croak("Can't continue after import errors");
186 }
187 }
188 }
189
19022104µs warn "Importing into $callpkg from $pkg: ",
191 join(", ",sort @imports) if $Exporter::Verbose;
192
193223.89ms foreach $sym (@imports) {
194 # shortcut for the common case of no type character
19571117.6ms7113.61ms (*{"${callpkg}::$sym"} = \&{"${pkg}::$sym"}, next)
# spent 3.61ms making 711 calls to Exporter::Heavy::CORE:subst, avg 5µs/call
196 unless $sym =~ s/^(\W)//;
19715129µs $type = $1;
198 *{"${callpkg}::$sym"} =
199 $type eq '&' ? \&{"${pkg}::$sym"} :
200 $type eq '$' ? \${"${pkg}::$sym"} :
201 $type eq '@' ? \@{"${pkg}::$sym"} :
202 $type eq '%' ? \%{"${pkg}::$sym"} :
203 $type eq '*' ? *{"${pkg}::$sym"} :
20415302µs do { require Carp; Carp::croak("Can't export symbol: $type$sym") };
205 }
206}
207
208sub heavy_export_to_level
209{
210 my $pkg = shift;
211 my $level = shift;
212 (undef) = shift; # XXX redundant arg
213 my $callpkg = caller($level);
214 $pkg->export($callpkg, @_);
215}
216
217# Utility functions
218
219
# spent 493µs within Exporter::Heavy::_push_tags which was called 6 times, avg 82µs/call: # 6 times (493µs+0s) by Exporter::Heavy::heavy_export_ok_tags at line 245, avg 82µs/call
sub _push_tags {
220643µs my($pkg, $var, $syms) = @_;
221628µs my @nontag = ();
222662µs my $export_tags = \%{"${pkg}::EXPORT_TAGS"};
223 push(@{"${pkg}::$var"},
2246277µs map { $export_tags->{$_} ? @{$export_tags->{$_}}
225 : scalar(push(@nontag,$_),$_) }
226 (@$syms) ? @$syms : keys %$export_tags);
2276118µs if (@nontag and $^W) {
228 # This may change to a die one day
229 require Carp;
230 Carp::carp(join(", ", @nontag)." are not tags of $pkg");
231 }
232}
233
234
# spent 268µs (63+205) within Exporter::Heavy::heavy_require_version which was called # once (63µs+205µs) by DBI::install_driver at line 92 of Exporter.pm
sub heavy_require_version {
23517µs my($self, $wanted) = @_;
23615µs my $pkg = ref $self || $self;
2371262µs1205µs return ${pkg}->VERSION($wanted);
# spent 205µs making 1 call to UNIVERSAL::VERSION
238}
239
240sub heavy_export_tags {
241 _push_tags((caller)[0], "EXPORT", \@_);
242}
243
244
# spent 694µs (201+493) within Exporter::Heavy::heavy_export_ok_tags which was called 6 times, avg 116µs/call: # 6 times (201µs+493µs) by DBI::install_driver or Net::HTTP::Methods::zlib_ok or base::import at line 88 of Exporter.pm, avg 116µs/call
sub heavy_export_ok_tags {
2456185µs6493µs _push_tags((caller)[0], "EXPORT_OK", \@_);
# spent 493µs making 6 calls to Exporter::Heavy::_push_tags, avg 82µs/call
246}
247
248115µs1;
# spent 203µs within Exporter::Heavy::CORE:match which was called 31 times, avg 7µs/call: # 16 times (103µs+0s) by Exporter::Heavy::heavy_export at line 72 of Exporter/Heavy.pm, avg 6µs/call # 11 times (78µs+0s) by Exporter::Heavy::heavy_export at line 78 of Exporter/Heavy.pm, avg 7µs/call # 4 times (22µs+0s) by Exporter::Heavy::heavy_export at line 82 of Exporter/Heavy.pm, avg 6µs/call
sub Exporter::Heavy::CORE:match; # xsub
# spent 3.78ms within Exporter::Heavy::CORE:subst which was called 743 times, avg 5µs/call: # 711 times (3.61ms+0s) by Exporter::Heavy::heavy_export at line 195 of Exporter/Heavy.pm, avg 5µs/call # 16 times (89µs+0s) by Exporter::Heavy::heavy_export at line 82 of Exporter/Heavy.pm, avg 6µs/call # 16 times (74µs+0s) by Exporter::Heavy::heavy_export at line 80 of Exporter/Heavy.pm, avg 5µs/call
sub Exporter::Heavy::CORE:subst; # xsub