Filename | /usr/share/perl/5.18/Exporter/Heavy.pm |
Statements | Executed 1090 statements in 13.4ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
18 | 1 | 1 | 7.76ms | 12.6ms | heavy_export | Exporter::Heavy::
5 | 2 | 1 | 4.11ms | 4.19ms | _rebuild_cache | Exporter::Heavy::
1694 | 6 | 1 | 260µs | 260µs | CORE:subst (opcode) | Exporter::Heavy::
2 | 2 | 1 | 43µs | 43µs | _push_tags | Exporter::Heavy::
3 | 1 | 1 | 28µs | 269µs | heavy_export_to_level | Exporter::Heavy::
18 | 4 | 1 | 12µs | 12µs | CORE:match (opcode) | Exporter::Heavy::
3 | 1 | 1 | 12µs | 13µs | __ANON__[:44] | Exporter::Heavy::
1 | 1 | 1 | 9µs | 44µs | BEGIN@183 | Exporter::Heavy::
1 | 1 | 1 | 9µs | 18µs | BEGIN@3 | Exporter::Heavy::
1 | 1 | 1 | 6µs | 34µs | heavy_export_ok_tags | Exporter::Heavy::
1 | 1 | 1 | 5µs | 12µs | BEGIN@4 | Exporter::Heavy::
1 | 1 | 1 | 5µs | 20µs | heavy_export_tags | Exporter::Heavy::
0 | 0 | 0 | 0s | 0s | __ANON__[:38] | Exporter::Heavy::
0 | 0 | 0 | 0s | 0s | heavy_require_version | Exporter::Heavy::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package Exporter::Heavy; | ||||
2 | |||||
3 | 2 | 21µs | 2 | 28µs | # spent 18µs (9+9) within Exporter::Heavy::BEGIN@3 which was called:
# once (9µs+9µs) by Exporter::as_heavy at line 3 # spent 18µs making 1 call to Exporter::Heavy::BEGIN@3
# spent 9µs making 1 call to strict::import |
4 | 2 | 747µs | 2 | 18µs | # spent 12µs (5+7) within Exporter::Heavy::BEGIN@4 which was called:
# once (5µs+7µs) by Exporter::as_heavy at line 4 # spent 12µs making 1 call to Exporter::Heavy::BEGIN@4
# spent 7µs making 1 call to strict::unimport |
5 | |||||
6 | # On one line so MakeMaker will see it. | ||||
7 | 2 | 800ns | require 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 | |||||
14 | sub _rebuild_cache { | ||||
15 | 5 | 2µs | my ($pkg, $exports, $cache) = @_; | ||
16 | 5 | 10µs | 1 | 400ns | s/^&// foreach @$exports; # spent 400ns making 1 call to Exporter::Heavy::CORE:subst |
17 | 5 | 8µs | @{$cache}{@$exports} = (1) x @$exports; | ||
18 | 5 | 9µs | my $ok = \@{"${pkg}::EXPORT_OK"}; | ||
19 | 5 | 17µs | if (@$ok) { | ||
20 | 4 | 4.00ms | 1037 | 83µs | s/^&// foreach @$ok; # spent 83µs making 1037 calls to Exporter::Heavy::CORE:subst, avg 80ns/call |
21 | 4 | 157µs | @{$cache}{@$ok} = (1) x @$ok; | ||
22 | } | ||||
23 | } | ||||
24 | |||||
25 | # spent 12.6ms (7.76+4.84) within Exporter::Heavy::heavy_export which was called 18 times, avg 700µs/call:
# 18 times (7.76ms+4.84ms) by Exporter::Heavy::heavy_export_to_level or Exporter::import or FileHandle::import or IO::Socket::import at line 25 of Exporter.pm, avg 700µs/call | ||||
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 | } | ||||
38 | 18 | 87µs | }; | ||
39 | # spent 13µs (12+1) within Exporter::Heavy::__ANON__[/usr/share/perl/5.18/Exporter/Heavy.pm:44] which was called 3 times, avg 4µs/call:
# 3 times (12µs+1µs) by Carp::croak at line 100 of Carp.pm, avg 4µs/call | ||||
40 | 3 | 1µs | require Carp; | ||
41 | 3 | 1µs | local $Carp::CarpLevel = 1; # ignore package calling us too. | ||
42 | 3 | 12µs | 3 | 1µs | Carp::croak("$_[0]Illegal null symbol in \@${1}::EXPORT") # spent 1µs making 3 calls to Exporter::Heavy::CORE:match, avg 400ns/call |
43 | if $_[0] =~ /^Unable to create sub named "(.*?)::"/; | ||||
44 | 18 | 84µs | }; | ||
45 | |||||
46 | 18 | 17µs | my($pkg, $callpkg, @imports) = @_; | ||
47 | 18 | 4µs | my($type, $sym, $cache_is_current, $oops); | ||
48 | 18 | 44µs | my($exports, $export_cache) = (\@{"${pkg}::EXPORT"}, | ||
49 | $Exporter::Cache{$pkg} ||= {}); | ||||
50 | |||||
51 | 18 | 10µs | if (@imports) { | ||
52 | 9 | 15µs | if (!%$export_cache) { | ||
53 | 2 | 3µs | 2 | 84µs | _rebuild_cache ($pkg, $exports, $export_cache); # spent 84µs making 2 calls to Exporter::Heavy::_rebuild_cache, avg 42µs/call |
54 | 2 | 600ns | $cache_is_current = 1; | ||
55 | } | ||||
56 | |||||
57 | 9 | 40µs | 9 | 8µs | if (grep m{^[/!:]}, @imports) { # spent 8µs making 9 calls to Exporter::Heavy::CORE:match, avg 900ns/call |
58 | 3 | 5µs | my $tagsref = \%{"${pkg}::EXPORT_TAGS"}; | ||
59 | 3 | 700ns | my $tagdata; | ||
60 | 3 | 700ns | my %imports; | ||
61 | 3 | 800ns | my($remove, $spec, @names, @allexports); | ||
62 | # negated first item implies starting with default set: | ||||
63 | 3 | 10µs | 3 | 2µs | unshift @imports, ':DEFAULT' if $imports[0] =~ m/^!/; # spent 2µs making 3 calls to Exporter::Heavy::CORE:match, avg 600ns/call |
64 | 3 | 5µs | foreach $spec (@imports){ | ||
65 | 3 | 10µs | 3 | 1µs | $remove = $spec =~ s/^!//; # spent 1µs making 3 calls to Exporter::Heavy::CORE:subst, avg 367ns/call |
66 | |||||
67 | 3 | 12µs | 3 | 4µs | if ($spec =~ s/^://){ # spent 4µs making 3 calls to Exporter::Heavy::CORE:subst, avg 1µs/call |
68 | 3 | 12µ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 | 3 | 800ns | warn "Import ".($remove ? "del":"add").": @names " | ||
90 | if $Exporter::Verbose; | ||||
91 | |||||
92 | 3 | 6µs | if ($remove) { | ||
93 | foreach $sym (@names) { delete $imports{$sym} } | ||||
94 | } | ||||
95 | else { | ||||
96 | 3 | 17µs | @imports{@names} = (1) x @names; | ||
97 | } | ||||
98 | } | ||||
99 | 3 | 16µs | @imports = keys %imports; | ||
100 | } | ||||
101 | |||||
102 | 9 | 2µs | my @carp; | ||
103 | 9 | 6µs | foreach $sym (@imports) { | ||
104 | 56 | 17µs | if (!$export_cache->{$sym}) { | ||
105 | 3 | 13µs | 6 | 3µs | if ($sym =~ m/^\d/) { # spent 1µs making 3 calls to Exporter::Heavy::CORE:subst, avg 467ns/call
# spent 1µs making 3 calls to Exporter::Heavy::CORE:match, avg 433ns/call |
106 | $pkg->VERSION($sym); # inherit from UNIVERSAL | ||||
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 | 3 | 600ns | unless ($cache_is_current) { | ||
124 | 3 | 33µs | %$export_cache = (); | ||
125 | 3 | 14µs | 3 | 4.11ms | _rebuild_cache ($pkg, $exports, $export_cache); # spent 4.11ms making 3 calls to Exporter::Heavy::_rebuild_cache, avg 1.37ms/call |
126 | 3 | 800ns | $cache_is_current = 1; | ||
127 | } | ||||
128 | |||||
129 | 3 | 1µs | if (!$export_cache->{$sym}) { | ||
130 | # accumulate the non-exports | ||||
131 | 3 | 5µs | push @carp, | ||
132 | qq["$sym" is not exported by the $pkg module\n]; | ||||
133 | 3 | 900ns | $oops++; | ||
134 | } | ||||
135 | } | ||||
136 | } | ||||
137 | } | ||||
138 | 9 | 3µs | if ($oops) { | ||
139 | 3 | 1µs | require Carp; | ||
140 | 3 | 5µs | 3 | 465µs | Carp::croak("@{carp}Can't continue after import errors"); # spent 465µs making 3 calls to Carp::croak, avg 155µs/call |
141 | } | ||||
142 | } | ||||
143 | else { | ||||
144 | 9 | 65µs | @imports = @$exports; | ||
145 | } | ||||
146 | |||||
147 | 15 | 48µs | my($fail, $fail_cache) = (\@{"${pkg}::EXPORT_FAIL"}, | ||
148 | $Exporter::FailCache{$pkg} ||= {}); | ||||
149 | |||||
150 | 15 | 8µs | 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 | 15 | 3µs | warn "Importing into $callpkg from $pkg: ", | ||
176 | join(", ",sort @imports) if $Exporter::Verbose; | ||||
177 | |||||
178 | 15 | 243µs | foreach $sym (@imports) { | ||
179 | # shortcut for the common case of no type character | ||||
180 | 647 | 7.03ms | 647 | 170µs | (*{"${callpkg}::$sym"} = \&{"${pkg}::$sym"}, next) # spent 170µs making 647 calls to Exporter::Heavy::CORE:subst, avg 263ns/call |
181 | unless $sym =~ s/^(\W)//; | ||||
182 | 7 | 8µs | $type = $1; | ||
183 | 2 | 350µs | 2 | 78µs | # spent 44µs (9+35) within Exporter::Heavy::BEGIN@183 which was called:
# once (9µs+35µs) by Exporter::as_heavy at line 183 # spent 44µs making 1 call to Exporter::Heavy::BEGIN@183
# spent 35µ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 | 7 | 35µs | do { require Carp; Carp::croak("Can't export symbol: $type$sym") }; | ||
191 | } | ||||
192 | } | ||||
193 | |||||
194 | sub heavy_export_to_level | ||||
195 | # spent 269µs (28+241) within Exporter::Heavy::heavy_export_to_level which was called 3 times, avg 90µs/call:
# 3 times (28µs+241µs) by Class::Struct::import or Time::HiRes::import at line 81 of Exporter.pm, avg 90µs/call | ||||
196 | 3 | 1µs | my $pkg = shift; | ||
197 | 3 | 700ns | my $level = shift; | ||
198 | 3 | 1µs | (undef) = shift; # XXX redundant arg | ||
199 | 3 | 2µs | my $callpkg = caller($level); | ||
200 | 3 | 15µs | 3 | 29µs | $pkg->export($callpkg, @_); # spent 29µs making 3 calls to Exporter::export, avg 10µs/call |
201 | } | ||||
202 | |||||
203 | # Utility functions | ||||
204 | |||||
205 | sub _push_tags { | ||||
206 | 2 | 2µs | my($pkg, $var, $syms) = @_; | ||
207 | 2 | 800ns | my @nontag = (); | ||
208 | 2 | 3µs | my $export_tags = \%{"${pkg}::EXPORT_TAGS"}; | ||
209 | push(@{"${pkg}::$var"}, | ||||
210 | 2 | 33µs | map { $export_tags->{$_} ? @{$export_tags->{$_}} | ||
211 | : scalar(push(@nontag,$_),$_) } | ||||
212 | (@$syms) ? @$syms : keys %$export_tags); | ||||
213 | 2 | 7µs | 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 | |||||
220 | sub heavy_require_version { | ||||
221 | my($self, $wanted) = @_; | ||||
222 | my $pkg = ref $self || $self; | ||||
223 | return ${pkg}->VERSION($wanted); | ||||
224 | } | ||||
225 | |||||
226 | # spent 20µs (5+15) within Exporter::Heavy::heavy_export_tags which was called:
# once (5µs+15µs) by Path::Class::Dir::BEGIN@14 at line 85 of Exporter.pm | ||||
227 | 1 | 6µs | 1 | 15µs | _push_tags((caller)[0], "EXPORT", \@_); # spent 15µs making 1 call to Exporter::Heavy::_push_tags |
228 | } | ||||
229 | |||||
230 | # spent 34µs (6+28) within Exporter::Heavy::heavy_export_ok_tags which was called:
# once (6µs+28µs) by DBI::BEGIN@179 at line 89 of Exporter.pm | ||||
231 | 1 | 6µs | 1 | 28µs | _push_tags((caller)[0], "EXPORT_OK", \@_); # spent 28µs making 1 call to Exporter::Heavy::_push_tags |
232 | } | ||||
233 | |||||
234 | 1 | 2µs | 1; | ||
# spent 12µs within Exporter::Heavy::CORE:match which was called 18 times, avg 689ns/call:
# 9 times (8µs+0s) by Exporter::Heavy::heavy_export at line 57, avg 900ns/call
# 3 times (2µs+0s) by Exporter::Heavy::heavy_export at line 63, avg 600ns/call
# 3 times (1µs+0s) by Exporter::Heavy::heavy_export at line 105, avg 433ns/call
# 3 times (1µs+0s) by Exporter::Heavy::__ANON__[/usr/share/perl/5.18/Exporter/Heavy.pm:44] at line 42, avg 400ns/call | |||||
# spent 260µs within Exporter::Heavy::CORE:subst which was called 1694 times, avg 154ns/call:
# 1037 times (83µs+0s) by Exporter::Heavy::_rebuild_cache at line 20, avg 80ns/call
# 647 times (170µs+0s) by Exporter::Heavy::heavy_export at line 180, avg 263ns/call
# 3 times (4µs+0s) by Exporter::Heavy::heavy_export at line 67, avg 1µs/call
# 3 times (1µs+0s) by Exporter::Heavy::heavy_export at line 105, avg 467ns/call
# 3 times (1µs+0s) by Exporter::Heavy::heavy_export at line 65, avg 367ns/call
# once (400ns+0s) by Exporter::Heavy::_rebuild_cache at line 16 |