Filename | /usr/lib/x86_64-linux-gnu/perl-base/constant.pm |
Statements | Executed 4132515 statements in 19.8s |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
4131258 | 15 | 2 | 3.55s | 3.55s | __ANON__[:192] | constant::
41 | 41 | 11 | 586µs | 746µs | import | constant::
41 | 1 | 1 | 48µs | 48µs | CORE:match (opcode) | constant::
41 | 1 | 1 | 44µs | 44µs | CORE:subst (opcode) | constant::
41 | 1 | 1 | 34µs | 34µs | CORE:regcomp (opcode) | constant::
1 | 1 | 1 | 11µs | 11µs | BEGIN@2 | constant::
1 | 1 | 1 | 8µs | 9µs | BEGIN@24 | constant::
1 | 1 | 1 | 5µs | 10µs | BEGIN@40 | constant::
1 | 1 | 1 | 4µs | 22µs | BEGIN@4 | constant::
1 | 1 | 1 | 4µs | 7µs | BEGIN@141 | constant::
1 | 1 | 1 | 4µs | 7µs | BEGIN@90 | constant::
1 | 1 | 1 | 4µs | 7µs | BEGIN@65 | constant::
1 | 1 | 1 | 4µs | 5µs | BEGIN@3 | constant::
3 | 3 | 1 | 3µs | 3µs | CORE:qr (opcode) | constant::
5 | 2 | 1 | 700ns | 700ns | _make_const (xsub) | constant::
0 | 0 | 0 | 0s | 0s | __ANON__[:174] | constant::
0 | 0 | 0 | 0s | 0s | __ANON__[:190] | constant::
0 | 0 | 0 | 0s | 0s | __ANON__[:41] | constant::
0 | 0 | 0 | 0s | 0s | __ANON__[:42] | constant::
0 | 0 | 0 | 0s | 0s | __ANON__[:43] | constant::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package constant; | ||||
2 | 2 | 30µs | 1 | 11µs | # spent 11µs within constant::BEGIN@2 which was called:
# once (11µs+0s) by File::Spec::Unix::BEGIN@115 at line 2 # spent 11µs making 1 call to constant::BEGIN@2 |
3 | 2 | 15µs | 2 | 6µs | # spent 5µs (4+1) within constant::BEGIN@3 which was called:
# once (4µs+1µs) by File::Spec::Unix::BEGIN@115 at line 3 # spent 5µs making 1 call to constant::BEGIN@3
# spent 1µs making 1 call to strict::import |
4 | 2 | 221µs | 2 | 40µs | # spent 22µs (4+18) within constant::BEGIN@4 which was called:
# once (4µs+18µs) by File::Spec::Unix::BEGIN@115 at line 4 # spent 22µs making 1 call to constant::BEGIN@4
# spent 18µs making 1 call to warnings::register::import |
5 | |||||
6 | 1 | 300ns | our $VERSION = '1.33'; | ||
7 | our %declared; | ||||
8 | |||||
9 | #======================================================================= | ||||
10 | |||||
11 | # Some names are evil choices. | ||||
12 | 1 | 4µs | my %keywords = map +($_, 1), qw{ BEGIN INIT CHECK END DESTROY AUTOLOAD }; | ||
13 | 1 | 1µs | $keywords{UNITCHECK}++ if $] > 5.009; | ||
14 | |||||
15 | 1 | 3µs | my %forced_into_main = map +($_, 1), | ||
16 | qw{ STDIN STDOUT STDERR ARGV ARGVOUT ENV INC SIG }; | ||||
17 | |||||
18 | 1 | 3µs | my %forbidden = (%keywords, %forced_into_main); | ||
19 | |||||
20 | 1 | 6µs | 1 | 2µs | my $normal_constant_name = qr/^_?[^\W_0-9]\w*\z/; # spent 2µs making 1 call to constant::CORE:qr |
21 | 1 | 2µs | 1 | 400ns | my $tolerable = qr/^[A-Za-z_]\w*\z/; # spent 400ns making 1 call to constant::CORE:qr |
22 | 1 | 1µs | 1 | 300ns | my $boolean = qr/^[01]?\z/; # spent 300ns making 1 call to constant::CORE:qr |
23 | |||||
24 | # spent 9µs (8+500ns) within constant::BEGIN@24 which was called:
# once (8µs+500ns) by File::Spec::Unix::BEGIN@115 at line 45 | ||||
25 | # We'd like to do use constant _CAN_PCS => $] > 5.009002 | ||||
26 | # but that's a bit tricky before we load the constant module :-) | ||||
27 | # By doing this, we save several run time checks for *every* call | ||||
28 | # to import. | ||||
29 | 1 | 300ns | my $const = $] > 5.009002; | ||
30 | 1 | 100ns | my $downgrade = $] < 5.015004; # && $] >= 5.008 | ||
31 | 1 | 400ns | my $constarray = exists &_make_const; | ||
32 | 1 | 1µs | if ($const) { | ||
33 | 1 | 4µs | 1 | 400ns | Internals::SvREADONLY($const, 1); # spent 400ns making 1 call to Internals::SvREADONLY |
34 | 1 | 1µs | 1 | 100ns | Internals::SvREADONLY($downgrade, 1); # spent 100ns making 1 call to Internals::SvREADONLY |
35 | 1 | 500ns | $constant::{_CAN_PCS} = \$const; | ||
36 | 1 | 300ns | $constant::{_DOWNGRADE} = \$downgrade; | ||
37 | 1 | 400ns | $constant::{_CAN_PCS_FOR_ARRAY} = \$constarray; | ||
38 | } | ||||
39 | else { | ||||
40 | 2 | 60µs | 2 | 15µs | # spent 10µs (5+5) within constant::BEGIN@40 which was called:
# once (5µs+5µs) by File::Spec::Unix::BEGIN@115 at line 40 # spent 10µs making 1 call to constant::BEGIN@40
# spent 5µs making 1 call to strict::unimport |
41 | *{"_CAN_PCS"} = sub () {$const}; | ||||
42 | *{"_DOWNGRADE"} = sub () { $downgrade }; | ||||
43 | *{"_CAN_PCS_FOR_ARRAY"} = sub () { $constarray }; | ||||
44 | } | ||||
45 | 1 | 44µs | 1 | 9µs | } # spent 9µs making 1 call to constant::BEGIN@24 |
46 | |||||
47 | #======================================================================= | ||||
48 | # import() - import symbols into user's namespace | ||||
49 | # | ||||
50 | # What we actually do is define a function in the caller's namespace | ||||
51 | # which returns the value. The function we create will normally | ||||
52 | # be inlined as a constant, thereby avoiding further sub calling | ||||
53 | # overhead. | ||||
54 | #======================================================================= | ||||
55 | # spent 746µs (586+160) within constant::import which was called 41 times, avg 18µs/call:
# once (25µs+10µs) by YAML::XS::BEGIN@108 at line 125 of YAML/XS.pm
# once (25µs+8µs) by Module::Load::Conditional::BEGIN@16 at line 16 of Module/Load/Conditional.pm
# once (24µs+7µs) by Getopt::Long::BEGIN@220 at line 220 of Getopt/Long.pm
# once (21µs+9µs) by File::Spec::Unix::BEGIN@115 at line 115 of File/Spec/Unix.pm
# once (22µs+8µs) by File::Temp::BEGIN@216 at line 216 of File/Temp.pm
# once (22µs+7µs) by Encode::BEGIN@7 at line 7 of Encode.pm
# once (22µs+7µs) by IPC::Cmd::BEGIN@7 at line 7 of IPC/Cmd.pm
# once (23µs+6µs) by Encode::Encoding::BEGIN@14 at line 14 of Encode/Encoding.pm
# once (20µs+6µs) by Encode::Alias::BEGIN@5 at line 5 of Encode/Alias.pm
# once (18µs+5µs) by IPC::Run::BEGIN@1066 at line 1066 of IPC/Run.pm
# once (18µs+5µs) by IPC::Open3::BEGIN@73 at line 73 of IPC/Open3.pm
# once (18µs+3µs) by IPC::Cmd::BEGIN@12 at line 12 of IPC/Cmd.pm
# once (16µs+3µs) by IPC::Open3::BEGIN@74 at line 74 of IPC/Open3.pm
# once (15µs+4µs) by File::Spec::Unix::BEGIN@209 at line 209 of File/Spec/Unix.pm
# once (14µs+2µs) by Getopt::Long::BEGIN@234 at line 234 of Getopt/Long.pm
# once (13µs+4µs) by File::Spec::Unix::BEGIN@124 at line 124 of File/Spec/Unix.pm
# once (13µs+4µs) by File::Spec::Unix::BEGIN@231 at line 231 of File/Spec/Unix.pm
# once (13µs+3µs) by Getopt::Long::BEGIN@230 at line 230 of Getopt/Long.pm
# once (13µs+3µs) by Module::Load::Conditional::BEGIN@17 at line 17 of Module/Load/Conditional.pm
# once (13µs+3µs) by File::Temp::BEGIN@219 at line 219 of File/Temp.pm
# once (12µs+3µs) by IPC::Cmd::BEGIN@8 at line 8 of IPC/Cmd.pm
# once (12µs+3µs) by File::Spec::Unix::BEGIN@133 at line 133 of File/Spec/Unix.pm
# once (11µs+3µs) by Module::Load::Conditional::BEGIN@18 at line 18 of Module/Load/Conditional.pm
# once (11µs+3µs) by Getopt::Long::BEGIN@232 at line 232 of Getopt/Long.pm
# once (11µs+3µs) by File::Temp::BEGIN@223 at line 223 of File/Temp.pm
# once (11µs+2µs) by IPC::Cmd::BEGIN@13 at line 13 of IPC/Cmd.pm
# once (11µs+2µs) by IPC::Cmd::BEGIN@10 at line 10 of IPC/Cmd.pm
# once (11µs+2µs) by File::Temp::BEGIN@227 at line 227 of File/Temp.pm
# once (11µs+2µs) by Getopt::Long::BEGIN@259 at line 259 of Getopt/Long.pm
# once (11µs+2µs) by File::Temp::BEGIN@229 at line 229 of File/Temp.pm
# once (11µs+2µs) by IPC::Cmd::BEGIN@11 at line 11 of IPC/Cmd.pm
# once (10µs+2µs) by Getopt::Long::BEGIN@249 at line 249 of Getopt/Long.pm
# once (10µs+3µs) by IPC::Cmd::BEGIN@9 at line 9 of IPC/Cmd.pm
# once (10µs+2µs) by Getopt::Long::BEGIN@238 at line 238 of Getopt/Long.pm
# once (10µs+2µs) by Getopt::Long::BEGIN@248 at line 248 of Getopt/Long.pm
# once (10µs+2µs) by Getopt::Long::BEGIN@240 at line 240 of Getopt/Long.pm
# once (10µs+2µs) by File::Temp::BEGIN@228 at line 228 of File/Temp.pm
# once (10µs+2µs) by Getopt::Long::BEGIN@237 at line 237 of Getopt/Long.pm
# once (10µs+2µs) by Getopt::Long::BEGIN@241 at line 241 of Getopt/Long.pm
# once (9µs+2µs) by Getopt::Long::BEGIN@235 at line 235 of Getopt/Long.pm
# once (9µs+2µs) by Getopt::Long::BEGIN@236 at line 236 of Getopt/Long.pm | ||||
56 | 41 | 8µs | my $class = shift; | ||
57 | 41 | 9µs | return unless @_; # Ignore 'use constant;' | ||
58 | 41 | 3µs | my $constants; | ||
59 | 41 | 11µs | my $multiple = ref $_[0]; | ||
60 | 41 | 12µs | my $caller = caller; | ||
61 | 41 | 5µs | my $flush_mro; | ||
62 | my $symtab; | ||||
63 | |||||
64 | 41 | 8µs | if (_CAN_PCS) { | ||
65 | 2 | 91µs | 2 | 10µs | # spent 7µs (4+3) within constant::BEGIN@65 which was called:
# once (4µs+3µs) by File::Spec::Unix::BEGIN@115 at line 65 # spent 7µs making 1 call to constant::BEGIN@65
# spent 3µs making 1 call to strict::unimport |
66 | 41 | 24µs | $symtab = \%{$caller . '::'}; | ||
67 | }; | ||||
68 | |||||
69 | 41 | 7µs | if ( $multiple ) { | ||
70 | if (ref $_[0] ne 'HASH') { | ||||
71 | require Carp; | ||||
72 | Carp::croak("Invalid reference type '".ref(shift)."' not 'HASH'"); | ||||
73 | } | ||||
74 | $constants = shift; | ||||
75 | } else { | ||||
76 | 41 | 6µs | unless (defined $_[0]) { | ||
77 | require Carp; | ||||
78 | Carp::croak("Can't use undef as constant name"); | ||||
79 | } | ||||
80 | 41 | 24µs | $constants->{+shift} = undef; | ||
81 | } | ||||
82 | |||||
83 | 41 | 27µs | foreach my $name ( keys %$constants ) { | ||
84 | 41 | 3µs | my $pkg; | ||
85 | 41 | 5µs | my $symtab = $symtab; | ||
86 | 41 | 4µs | my $orig_name = $name; | ||
87 | 41 | 105µs | 41 | 44µs | if ($name =~ s/(.*)(?:::|')(?=.)//s) { # spent 44µs making 41 calls to constant::CORE:subst, avg 1µs/call |
88 | $pkg = $1; | ||||
89 | if (_CAN_PCS && $pkg ne $caller) { | ||||
90 | 2 | 116µs | 2 | 9µs | # spent 7µs (4+2) within constant::BEGIN@90 which was called:
# once (4µs+2µs) by File::Spec::Unix::BEGIN@115 at line 90 # spent 7µs making 1 call to constant::BEGIN@90
# spent 2µs making 1 call to strict::unimport |
91 | $symtab = \%{$pkg . '::'}; | ||||
92 | } | ||||
93 | } | ||||
94 | else { | ||||
95 | 41 | 4µs | $pkg = $caller; | ||
96 | } | ||||
97 | |||||
98 | # Normal constant name | ||||
99 | 41 | 162µs | 82 | 82µs | if ($name =~ $normal_constant_name and !$forbidden{$name}) { # spent 48µs making 41 calls to constant::CORE:match, avg 1µs/call
# spent 34µs making 41 calls to constant::CORE:regcomp, avg 832ns/call |
100 | # Everything is okay | ||||
101 | |||||
102 | # Name forced into main, but we're not in main. Fatal. | ||||
103 | } elsif ($forced_into_main{$name} and $pkg ne 'main') { | ||||
104 | require Carp; | ||||
105 | Carp::croak("Constant name '$name' is forced into main::"); | ||||
106 | |||||
107 | # Starts with double underscore. Fatal. | ||||
108 | } elsif ($name =~ /^__/) { | ||||
109 | require Carp; | ||||
110 | Carp::croak("Constant name '$name' begins with '__'"); | ||||
111 | |||||
112 | # Maybe the name is tolerable | ||||
113 | } elsif ($name =~ $tolerable) { | ||||
114 | # Then we'll warn only if you've asked for warnings | ||||
115 | if (warnings::enabled()) { | ||||
116 | if ($keywords{$name}) { | ||||
117 | warnings::warn("Constant name '$name' is a Perl keyword"); | ||||
118 | } elsif ($forced_into_main{$name}) { | ||||
119 | warnings::warn("Constant name '$name' is " . | ||||
120 | "forced into package main::"); | ||||
121 | } | ||||
122 | } | ||||
123 | |||||
124 | # Looks like a boolean | ||||
125 | # use constant FRED == fred; | ||||
126 | } elsif ($name =~ $boolean) { | ||||
127 | require Carp; | ||||
128 | if (@_) { | ||||
129 | Carp::croak("Constant name '$name' is invalid"); | ||||
130 | } else { | ||||
131 | Carp::croak("Constant name looks like boolean value"); | ||||
132 | } | ||||
133 | |||||
134 | } else { | ||||
135 | # Must have bad characters | ||||
136 | require Carp; | ||||
137 | Carp::croak("Constant name '$name' has invalid characters"); | ||||
138 | } | ||||
139 | |||||
140 | { | ||||
141 | 43 | 273µs | 2 | 9µs | # spent 7µs (4+2) within constant::BEGIN@141 which was called:
# once (4µs+2µs) by File::Spec::Unix::BEGIN@115 at line 141 # spent 7µs making 1 call to constant::BEGIN@141
# spent 2µs making 1 call to strict::unimport |
142 | 41 | 9µs | my $full_name = "${pkg}::$name"; | ||
143 | 41 | 28µs | $declared{$full_name}++; | ||
144 | 41 | 17µs | if ($multiple || @_ == 1) { | ||
145 | 39 | 9µs | my $scalar = $multiple ? $constants->{$orig_name} : $_[0]; | ||
146 | |||||
147 | if (_DOWNGRADE) { # for 5.8 to 5.14 | ||||
148 | # Work around perl bug #31991: Sub names (actually glob | ||||
149 | # names in general) ignore the UTF8 flag. So we have to | ||||
150 | # turn it off to get the "right" symbol table entry. | ||||
151 | utf8::is_utf8 $name and utf8::encode $name; | ||||
152 | } | ||||
153 | |||||
154 | # The constant serves to optimise this entire block out on | ||||
155 | # 5.8 and earlier. | ||||
156 | 39 | 6µs | if (_CAN_PCS) { | ||
157 | # Use a reference as a proxy for a constant subroutine. | ||||
158 | # If this is not a glob yet, it saves space. If it is | ||||
159 | # a glob, we must still create it this way to get the | ||||
160 | # right internal flags set, as constants are distinct | ||||
161 | # from subroutines created with sub(){...}. | ||||
162 | # The check in Perl_ck_rvconst knows that inlinable | ||||
163 | # constants from cv_const_sv are read only. So we have to: | ||||
164 | 39 | 55µs | 39 | 16µs | Internals::SvREADONLY($scalar, 1); # spent 16µs making 39 calls to Internals::SvREADONLY, avg 413ns/call |
165 | 39 | 15µs | if (!exists $symtab->{$name}) { | ||
166 | 39 | 15µs | $symtab->{$name} = \$scalar; | ||
167 | 39 | 12µs | ++$flush_mro->{$pkg}; | ||
168 | } | ||||
169 | else { | ||||
170 | local $constant::{_dummy} = \$scalar; | ||||
171 | *$full_name = \&{"_dummy"}; | ||||
172 | } | ||||
173 | } else { | ||||
174 | *$full_name = sub () { $scalar }; | ||||
175 | } | ||||
176 | } elsif (@_) { | ||||
177 | 1 | 700ns | my @list = @_; | ||
178 | 1 | 300ns | if (_CAN_PCS_FOR_ARRAY) { | ||
179 | 1 | 6µs | 4 | 600ns | _make_const($list[$_]) for 0..$#list; # spent 600ns making 4 calls to constant::_make_const, avg 150ns/call |
180 | 1 | 1µs | 1 | 100ns | _make_const(@list); # spent 100ns making 1 call to constant::_make_const |
181 | 1 | 500ns | if (!exists $symtab->{$name}) { | ||
182 | 1 | 500ns | $symtab->{$name} = \@list; | ||
183 | 1 | 300ns | $flush_mro->{$pkg}++; | ||
184 | } | ||||
185 | else { | ||||
186 | local $constant::{_dummy} = \@list; | ||||
187 | *$full_name = \&{"_dummy"}; | ||||
188 | } | ||||
189 | } | ||||
190 | else { *$full_name = sub () { @list }; } | ||||
191 | } else { | ||||
192 | 4131259 | 19.8s | # spent 3.55s within constant::__ANON__[/usr/lib/x86_64-linux-gnu/perl-base/constant.pm:192] which was called 4131258 times, avg 860ns/call:
# 1868195 times (1.29s+0s) by IPC::Run::reap_nb at line 3450 of IPC/Run.pm, avg 692ns/call
# 666621 times (293ms+0s) by IPC::Run::_select_loop at line 3095 of IPC/Run.pm, avg 440ns/call
# 532144 times (1.45s+0s) by IPC::Run::_close at line 1276 of IPC/Run.pm, avg 3µs/call
# 133036 times (117ms+0s) by IPC::Run::harness at line 1804 of IPC/Run.pm, avg 878ns/call
# 133036 times (100ms+0s) by IPC::Run::start at line 2900 of IPC/Run.pm, avg 753ns/call
# 133036 times (71.9ms+0s) by IPC::Run::IO::_new_internal at line 131 of IPC/Run/IO.pm, avg 540ns/call
# 133036 times (52.0ms+0s) by IPC::Run::start at line 2849 of IPC/Run.pm, avg 391ns/call
# 133036 times (51.0ms+0s) by IPC::Run::_pipe_nb at line 1400 of IPC/Run.pm, avg 383ns/call
# 133036 times (47.0ms+0s) by IPC::Run::start at line 2815 of IPC/Run.pm, avg 353ns/call
# 133036 times (42.7ms+0s) by IPC::Run::_search_path at line 1170 of IPC/Run.pm, avg 321ns/call
# 133036 times (30.4ms+0s) by IPC::Run::_search_path at line 1177 of IPC/Run.pm, avg 228ns/call
# 7 times (4µs+0s) by IPC::Run::_search_path at line 1223 of IPC/Run.pm, avg 643ns/call
# once (1µs+0s) by IPC::Run::IO::BEGIN@76 at line 78 of IPC/Run/IO.pm
# once (700ns+0s) by IPC::Run::BEGIN@1068 at line 1069 of IPC/Run.pm
# once (200ns+0s) by IPC::Run::_search_path at line 1211 of IPC/Run.pm | ||
193 | } | ||||
194 | } | ||||
195 | } | ||||
196 | # Flush the cache exactly once if we make any direct symbol table changes. | ||||
197 | 41 | 87µs | if (_CAN_PCS && $flush_mro) { | ||
198 | 40 | 73µs | 40 | 18µs | mro::method_changed_in($_) for keys %$flush_mro; # spent 18µs making 40 calls to mro::method_changed_in, avg 437ns/call |
199 | } | ||||
200 | } | ||||
201 | |||||
202 | 1 | 7µs | 1; | ||
203 | |||||
204 | __END__ | ||||
# spent 48µs within constant::CORE:match which was called 41 times, avg 1µs/call:
# 41 times (48µs+0s) by constant::import at line 99, avg 1µs/call | |||||
sub constant::CORE:qr; # opcode | |||||
# spent 34µs within constant::CORE:regcomp which was called 41 times, avg 832ns/call:
# 41 times (34µs+0s) by constant::import at line 99, avg 832ns/call | |||||
# spent 44µs within constant::CORE:subst which was called 41 times, avg 1µs/call:
# 41 times (44µs+0s) by constant::import at line 87, avg 1µs/call | |||||
sub constant::_make_const; # xsub |