← Index
NYTProf Performance Profile   « line view »
For /usr/local/bin/sa-learn
  Run on Tue Nov 7 05:38:10 2017
Reported on Tue Nov 7 06:16:00 2017

Filename/usr/local/lib/perl5/5.24/Exporter/Heavy.pm
StatementsExecuted 9538 statements in 97.0ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
581185.1ms93.2msExporter::Heavy::::heavy_exportExporter::Heavy::heavy_export
2620416.82ms6.82msExporter::Heavy::::CORE:substExporter::Heavy::CORE:subst (opcode)
4111.02ms1.29msExporter::Heavy::::_rebuild_cacheExporter::Heavy::_rebuild_cache
1711602µs7.77msExporter::Heavy::::heavy_export_to_levelExporter::Heavy::heavy_export_to_level
11041316µs316µsExporter::Heavy::::CORE:matchExporter::Heavy::CORE:match (opcode)
11149µs59µsExporter::Heavy::::BEGIN@3Exporter::Heavy::BEGIN@3
11131µs92µsExporter::Heavy::::BEGIN@202Exporter::Heavy::BEGIN@202
11118µs69µsExporter::Heavy::::BEGIN@4Exporter::Heavy::BEGIN@4
0000s0sExporter::Heavy::::__ANON__[:57]Exporter::Heavy::__ANON__[:57]
0000s0sExporter::Heavy::::__ANON__[:63]Exporter::Heavy::__ANON__[:63]
0000s0sExporter::Heavy::::_push_tagsExporter::Heavy::_push_tags
0000s0sExporter::Heavy::::heavy_export_ok_tagsExporter::Heavy::heavy_export_ok_tags
0000s0sExporter::Heavy::::heavy_export_tagsExporter::Heavy::heavy_export_tags
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
3277µs270µs
# spent 59µs (49+10) within Exporter::Heavy::BEGIN@3 which was called: # once (49µs+10µs) by Exporter::as_heavy at line 3
use strict;
# spent 59µs making 1 call to Exporter::Heavy::BEGIN@3 # spent 10µs making 1 call to strict::import
422.08ms2119µs
# spent 69µs (18+50) within Exporter::Heavy::BEGIN@4 which was called: # once (18µs+50µs) by Exporter::as_heavy at line 4
no strict 'refs';
# spent 69µs making 1 call to Exporter::Heavy::BEGIN@4 # spent 50µs making 1 call to strict::unimport
5
6# On one line so MakeMaker will see it.
727µsrequire Exporter; our $VERSION = $Exporter::VERSION;
8
9=head1 NAME
10
11Exporter::Heavy - Exporter guts
12
13=head1 SYNOPSIS
14
15(internal use only)
16
17=head1 DESCRIPTION
18
19No user-serviceable parts inside.
20
21=cut
22
23#
24# We go to a lot of trouble not to 'require Carp' at file scope,
25# because Carp requires Exporter, and something has to give.
26#
27
28
# spent 1.29ms (1.02+266µs) within Exporter::Heavy::_rebuild_cache which was called 4 times, avg 322µs/call: # 4 times (1.02ms+266µs) by Exporter::Heavy::heavy_export at line 72, avg 322µs/call
sub _rebuild_cache {
29411µs my ($pkg, $exports, $cache) = @_;
30420µs s/^&// foreach @$exports;
31833µs @{$cache}{@$exports} = (1) x @$exports;
32837µs my $ok = \@{"${pkg}::EXPORT_OK"};
33450µs if (@$ok) {
3441.04ms112266µs s/^&// foreach @$ok;
# spent 266µs making 112 calls to Exporter::Heavy::CORE:subst, avg 2µs/call
358103µs @{$cache}{@$ok} = (1) x @$ok;
36 }
37}
38
39
# spent 93.2ms (85.1+8.16) within Exporter::Heavy::heavy_export which was called 58 times, avg 1.61ms/call: # 58 times (85.1ms+8.16ms) by Exporter::Heavy::heavy_export_to_level or Exporter::import or IO::Socket::import at line 25 of Exporter.pm, avg 1.61ms/call
sub heavy_export {
40
41 # Save the old __WARN__ handler in case it was defined
4258197µs my $oldwarn = $SIG{__WARN__};
43
44 # First make import warnings look like they're coming from the "use".
45 local $SIG{__WARN__} = sub {
46 # restore it back so proper stacking occurs
47 local $SIG{__WARN__} = $oldwarn;
48 my $text = shift;
49 if ($text =~ s/ at \S*Exporter\S*.pm line \d+.*\n//) {
50 require Carp;
51 local $Carp::CarpLevel = 1; # ignore package calling us too.
52 Carp::carp($text);
53 }
54 else {
55 warn $text;
56 }
5758753µs };
58 local $SIG{__DIE__} = sub {
59 require Carp;
60 local $Carp::CarpLevel = 1; # ignore package calling us too.
61 Carp::croak("$_[0]Illegal null symbol in \@${1}::EXPORT")
62 if $_[0] =~ /^Unable to create sub named "(.*?)::"/;
6358575µs };
64
6558218µs my($pkg, $callpkg, @imports) = @_;
6658109µs my($type, $sym, $cache_is_current, $oops);
6758160µs my($exports, $export_cache) = (\@{"${pkg}::EXPORT"},
6858556µs $Exporter::Cache{$pkg} ||= {});
69
7058235µs if (@imports) {
7137247µs if (!%$export_cache) {
72434µs41.29ms _rebuild_cache ($pkg, $exports, $export_cache);
# spent 1.29ms making 4 calls to Exporter::Heavy::_rebuild_cache, avg 322µs/call
73410µs $cache_is_current = 1;
74 }
75
7637964µs78238µs if (grep m{^[/!:]}, @imports) {
# spent 238µs making 78 calls to Exporter::Heavy::CORE:match, avg 3µs/call
7748198µs my $tagsref = \%{"${pkg}::EXPORT_TAGS"};
782446µs my $tagdata;
79 my %imports;
80 my($remove, $spec, @names, @allexports);
81 # negated first item implies starting with default set:
8224243µs2460µs unshift @imports, ':DEFAULT' if $imports[0] =~ m/^!/;
# spent 60µs making 24 calls to Exporter::Heavy::CORE:match, avg 3µs/call
8324106µs foreach $spec (@imports){
8434371µs3472µs $remove = $spec =~ s/^!//;
# spent 72µs making 34 calls to Exporter::Heavy::CORE:subst, avg 2µs/call
85
8634552µs41183µs if ($spec =~ s/^://){
# spent 169µs making 34 calls to Exporter::Heavy::CORE:subst, avg 5µs/call # spent 14µs making 7 calls to Exporter::Heavy::CORE:match, avg 2µs/call
8727155µs if ($spec eq 'DEFAULT'){
88121µs @names = @$exports;
89 }
90 elsif ($tagdata = $tagsref->{$spec}) {
9126262µs @names = @$tagdata;
92 }
93 else {
94 warn qq["$spec" is not defined in %${pkg}::EXPORT_TAGS];
95 ++$oops;
96 next;
97 }
98 }
99 elsif ($spec =~ m:^/(.*)/$:){
100 my $patn = $1;
101 @allexports = keys %$export_cache unless @allexports; # only do keys once
102 @names = grep(/$patn/, @allexports); # not anchored by default
103 }
104 else {
105719µs @names = ($spec); # is a normal symbol name
106 }
107
1083491µs warn "Import ".($remove ? "del":"add").": @names "
109 if $Exporter::Verbose;
110
11134242µs if ($remove) {
112 foreach $sym (@names) { delete $imports{$sym} }
113 }
114 else {
11534566µs @imports{@names} = (1) x @names;
116 }
117 }
11824557µs @imports = keys %imports;
119 }
120
1213764µs my @carp;
12237152µs foreach $sym (@imports) {
1236823.71ms if (!$export_cache->{$sym}) {
124 if ($sym =~ m/^\d/) {
125 $pkg->VERSION($sym); # inherit from UNIVERSAL
126 # If the version number was the only thing specified
127 # then we should act as if nothing was specified:
128 if (@imports == 1) {
129 @imports = @$exports;
130 last;
131 }
132 # We need a way to emulate 'use Foo ()' but still
133 # allow an easy version check: "use Foo 1.23, ''";
134 if (@imports == 2 and !$imports[1]) {
135 @imports = ();
136 last;
137 }
138 } elsif ($sym !~ s/^&// || !$export_cache->{$sym}) {
139 # Last chance - see if they've updated EXPORT_OK since we
140 # cached it.
141
142 unless ($cache_is_current) {
143 %$export_cache = ();
144 _rebuild_cache ($pkg, $exports, $export_cache);
145 $cache_is_current = 1;
146 }
147
148 if (!$export_cache->{$sym}) {
149 # accumulate the non-exports
150 push @carp,
151 qq["$sym" is not exported by the $pkg module\n];
152 $oops++;
153 }
154 }
155 }
156 }
1573798µs if ($oops) {
158 require Carp;
159 Carp::croak("@{carp}Can't continue after import errors");
160 }
161 }
162 else {
16321510µs @imports = @$exports;
164 }
165
16658134µs my($fail, $fail_cache) = (\@{"${pkg}::EXPORT_FAIL"},
16758493µs $Exporter::FailCache{$pkg} ||= {});
168
16958118µs if (@$fail) {
170314µs if (!%$fail_cache) {
171 # Build cache of symbols. Optimise the lookup by adding
172 # barewords twice... both with and without a leading &.
173 # (Technique could be applied to $export_cache at cost of memory)
174224µs14µs my @expanded = map { /^\w/ ? ($_, '&'.$_) : $_ } @$fail;
# spent 4µs making 1 call to Exporter::Heavy::CORE:match
17512µs warn "${pkg}::EXPORT_FAIL cached: @expanded" if $Exporter::Verbose;
176210µs @{$fail_cache}{@expanded} = (1) x @expanded;
177 }
17836µs my @failed;
179313µs foreach $sym (@imports) { push(@failed, $sym) if $fail_cache->{$sym} }
18036µs if (@failed) {
181 @failed = $pkg->export_fail(@failed);
182 foreach $sym (@failed) {
183 require Carp;
184 Carp::carp(qq["$sym" is not implemented by the $pkg module ],
185 "on this architecture");
186 }
187 if (@failed) {
188 require Carp;
189 Carp::croak("Can't continue after import errors");
190 }
191 }
192 }
193
19458126µs warn "Importing into $callpkg from $pkg: ",
195 join(", ",sort @imports) if $Exporter::Verbose;
196
197586.39ms foreach $sym (@imports) {
198 # shortcut for the common case of no type character
199727872.2ms24406.32ms (*{"${callpkg}::$sym"} = \&{"${pkg}::$sym"}, next)
# spent 6.32ms making 2440 calls to Exporter::Heavy::CORE:subst, avg 3µs/call
200 unless $sym =~ s/^(\W)//;
2012164µs $type = $1;
2022988µs2154µs
# spent 92µs (31+62) within Exporter::Heavy::BEGIN@202 which was called: # once (31µs+62µs) by Exporter::as_heavy at line 202
no warnings 'once';
# spent 92µs making 1 call to Exporter::Heavy::BEGIN@202 # spent 62µs making 1 call to warnings::unimport
2032145µs *{"${callpkg}::$sym"} =
20438µs $type eq '&' ? \&{"${pkg}::$sym"} :
205919µs $type eq '$' ? \${"${pkg}::$sym"} :
206 $type eq '@' ? \@{"${pkg}::$sym"} :
207921µs $type eq '%' ? \%{"${pkg}::$sym"} :
208 $type eq '*' ? *{"${pkg}::$sym"} :
20921425µs do { require Carp; Carp::croak("Can't export symbol: $type$sym") };
210 }
211}
212
213sub heavy_export_to_level
214
# spent 7.77ms (602µs+7.17) within Exporter::Heavy::heavy_export_to_level which was called 17 times, avg 457µs/call: # 17 times (602µs+7.17ms) by NetAddr::IP::InetBase::import or NetAddr::IP::Lite::import or NetAddr::IP::Util::import or NetAddr::IP::import or Time::HiRes::import at line 81 of Exporter.pm, avg 457µs/call
{
2151745µs my $pkg = shift;
2161736µs my $level = shift;
2171741µs (undef) = shift; # XXX redundant arg
2181744µs my $callpkg = caller($level);
21917276µs171.05ms $pkg->export($callpkg, @_);
# spent 1.05ms making 17 calls to Exporter::export, avg 62µs/call
220}
221
222# Utility functions
223
224sub _push_tags {
225 my($pkg, $var, $syms) = @_;
226 my @nontag = ();
227 my $export_tags = \%{"${pkg}::EXPORT_TAGS"};
228 push(@{"${pkg}::$var"},
229 map { $export_tags->{$_} ? @{$export_tags->{$_}}
230 : scalar(push(@nontag,$_),$_) }
231 (@$syms) ? @$syms : keys %$export_tags);
232 if (@nontag and $^W) {
233 # This may change to a die one day
234 require Carp;
235 Carp::carp(join(", ", @nontag)." are not tags of $pkg");
236 }
237}
238
239sub heavy_require_version {
240 my($self, $wanted) = @_;
241 my $pkg = ref $self || $self;
242 return ${pkg}->VERSION($wanted);
243}
244
245sub heavy_export_tags {
246 _push_tags((caller)[0], "EXPORT", \@_);
247}
248
249sub heavy_export_ok_tags {
250 _push_tags((caller)[0], "EXPORT_OK", \@_);
251}
252
253114µs1;
 
# spent 316µs within Exporter::Heavy::CORE:match which was called 110 times, avg 3µs/call: # 78 times (238µs+0s) by Exporter::Heavy::heavy_export at line 76, avg 3µs/call # 24 times (60µs+0s) by Exporter::Heavy::heavy_export at line 82, avg 3µs/call # 7 times (14µs+0s) by Exporter::Heavy::heavy_export at line 86, avg 2µs/call # once (4µs+0s) by Exporter::Heavy::heavy_export at line 174
sub Exporter::Heavy::CORE:match; # opcode
# spent 6.82ms within Exporter::Heavy::CORE:subst which was called 2620 times, avg 3µs/call: # 2440 times (6.32ms+0s) by Exporter::Heavy::heavy_export at line 199, avg 3µs/call # 112 times (266µs+0s) by Exporter::Heavy::_rebuild_cache at line 34, avg 2µs/call # 34 times (169µs+0s) by Exporter::Heavy::heavy_export at line 86, avg 5µs/call # 34 times (72µs+0s) by Exporter::Heavy::heavy_export at line 84, avg 2µs/call
sub Exporter::Heavy::CORE:subst; # opcode