← Index
NYTProf Performance Profile   « line view »
For script/ponapi
  Run on Wed Feb 10 15:51:26 2016
Reported on Thu Feb 11 09:43:09 2016

Filename/usr/share/perl/5.18/constant.pm
StatementsExecuted 1881 statements in 3.68ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
6666242.05ms2.67msconstant::::importconstant::import
9311222µs222µsconstant::::CORE:matchconstant::CORE:match (opcode)
9311164µs164µsconstant::::CORE:regcompconstant::CORE:regcomp (opcode)
11113µs13µsconstant::::BEGIN@24constant::BEGIN@24
11112µs12µsconstant::::BEGIN@2constant::BEGIN@2
1118µs16µsconstant::::BEGIN@28constant::BEGIN@28
1116µs14µsconstant::::BEGIN@116constant::BEGIN@116
1116µs33µsconstant::::BEGIN@6constant::BEGIN@6
1116µs14µsconstant::::BEGIN@54constant::BEGIN@54
1116µs72µsconstant::::BEGIN@4constant::BEGIN@4
1115µs14µsconstant::::BEGIN@3constant::BEGIN@3
3313µs3µsconstant::::CORE:qrconstant::CORE:qr (opcode)
0000s0sconstant::::__ANON__[:140]constant::__ANON__[:140]
0000s0sconstant::::__ANON__[:144]constant::__ANON__[:144]
0000s0sconstant::::__ANON__[:146]constant::__ANON__[:146]
0000s0sconstant::::__ANON__[:30]constant::__ANON__[:30]
0000s0sconstant::::__ANON__[:33]constant::__ANON__[:33]
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package constant;
2243µs112µs
# spent 12µs within constant::BEGIN@2 which was called: # once (12µs+0s) by Try::Tiny::ScopeGuard::BEGIN@144 at line 2
use 5.008;
# spent 12µs making 1 call to constant::BEGIN@2
3218µs223µs
# spent 14µs (5+9) within constant::BEGIN@3 which was called: # once (5µs+9µs) by Try::Tiny::ScopeGuard::BEGIN@144 at line 3
use strict;
# spent 14µs making 1 call to constant::BEGIN@3 # spent 9µs making 1 call to strict::import
4223µs2138µs
# spent 72µs (6+66) within constant::BEGIN@4 which was called: # once (6µs+66µs) by Try::Tiny::ScopeGuard::BEGIN@144 at line 4
use warnings::register;
# spent 72µs making 1 call to constant::BEGIN@4 # spent 66µs making 1 call to warnings::register::import
5
62109µs260µs
# spent 33µs (6+27) within constant::BEGIN@6 which was called: # once (6µs+27µs) by Try::Tiny::ScopeGuard::BEGIN@144 at line 6
use vars qw($VERSION %declared);
# spent 33µs making 1 call to constant::BEGIN@6 # spent 27µs making 1 call to vars::import
71400ns$VERSION = '1.27';
8
9#=======================================================================
10
11# Some names are evil choices.
1214µsmy %keywords = map +($_, 1), qw{ BEGIN INIT CHECK END DESTROY AUTOLOAD };
1311µs$keywords{UNITCHECK}++ if $] > 5.009;
14
1515µsmy %forced_into_main = map +($_, 1),
16 qw{ STDIN STDOUT STDERR ARGV ARGVOUT ENV INC SIG };
17
1814µsmy %forbidden = (%keywords, %forced_into_main);
19
2016µs12µsmy $normal_constant_name = qr/^_?[^\W_0-9]\w*\z/;
# spent 2µs making 1 call to constant::CORE:qr
2113µs1700nsmy $tolerable = qr/^[A-Za-z_]\w*\z/;
# spent 700ns making 1 call to constant::CORE:qr
2212µs1500nsmy $boolean = qr/^[01]?\z/;
# spent 500ns making 1 call to constant::CORE:qr
23
24
# spent 13µs within constant::BEGIN@24 which was called: # once (13µs+0s) by Try::Tiny::ScopeGuard::BEGIN@144 at line 34
BEGIN {
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 1 run time check for *every* call to import.
28260µs225µs
# spent 16µs (8+9) within constant::BEGIN@28 which was called: # once (8µs+9µs) by Try::Tiny::ScopeGuard::BEGIN@144 at line 28
no strict 'refs';
# spent 16µs making 1 call to constant::BEGIN@28 # spent 9µs making 1 call to strict::unimport
291700ns my $const = $] > 5.009002;
3017µs *_CAN_PCS = sub () {$const};
31
321400ns my $downgrade = $] < 5.015004; # && $] >= 5.008
3317µs *_DOWNGRADE = sub () { $downgrade };
34186µs113µs}
# spent 13µs making 1 call to constant::BEGIN@24
35
36#=======================================================================
37# import() - import symbols into user's namespace
38#
39# What we actually do is define a function in the caller's namespace
40# which returns the value. The function we create will normally
41# be inlined as a constant, thereby avoiding further sub calling
42# overhead.
43#=======================================================================
44
# spent 2.67ms (2.05+620µs) within constant::import which was called 66 times, avg 40µs/call: # once (92µs+47µs) by Time::Piece::BEGIN@34 at line 34 of Time/Piece.pm # once (100µs+40µs) by Time::Seconds::BEGIN@23 at line 23 of Time/Seconds.pm # once (120µs+7µs) by Try::Tiny::ScopeGuard::BEGIN@144 at line 144 of Try/Tiny.pm # once (81µs+34µs) by PONAPI::Server::BEGIN@22 at line 23 of lib/PONAPI/Server.pm # once (89µs+22µs) by POSIX::strftime::Compiler::BEGIN@14 at line 15 of POSIX/strftime/Compiler.pm # once (37µs+67µs) by Time::Seconds::BEGIN@36 at line 36 of Time/Seconds.pm # once (51µs+15µs) by Time::Seconds::BEGIN@25 at line 25 of Time/Seconds.pm # once (50µs+13µs) by Apache::LogFormat::Compiler::BEGIN@8 at line 9 of Apache/LogFormat/Compiler.pm # once (52µs+10µs) by Time::Seconds::BEGIN@26 at line 26 of Time/Seconds.pm # once (47µs+14µs) by Hash::MultiValue::BEGIN@12 at line 12 of Hash/MultiValue.pm # once (41µs+12µs) by PONAPI::Constants::BEGIN@8 at line 15 of lib/PONAPI/Constants.pm # once (44µs+8µs) by Time::Seconds::BEGIN@24 at line 24 of Time/Seconds.pm # once (32µs+13µs) by YAML::XS::BEGIN@101 at line 118 of YAML/XS.pm # once (34µs+11µs) by HTTP::Parser::XS::BEGIN@16 at line 17 of HTTP/Parser/XS.pm # once (32µs+12µs) by DBD::SQLite::BEGIN@20 at line 20 of DBD/SQLite.pm # once (36µs+7µs) by Time::Seconds::BEGIN@27 at line 27 of Time/Seconds.pm # once (32µs+9µs) by Moose::Meta::Role::Application::ToInstance::BEGIN@20 at line 20 of Moose/Meta/Role/Application/ToInstance.pm # once (31µs+9µs) by Time::Seconds::BEGIN@37 at line 37 of Time/Seconds.pm # once (30µs+9µs) by Data::Dumper::BEGIN@271 at line 271 of Data/Dumper.pm # once (30µs+10µs) by Time::Seconds::BEGIN@28 at line 28 of Time/Seconds.pm # once (31µs+8µs) by HTTP::Server::PSGI::BEGIN@31 at line 31 of HTTP/Server/PSGI.pm # once (31µs+7µs) by Time::Local::BEGIN@27 at line 27 of Time/Local.pm # once (28µs+9µs) by Test::PONAPI::Repository::MockDB::Table::Articles::BEGIN@9 at line 9 of lib/Test/PONAPI/Repository/MockDB/Table/Articles.pm # once (29µs+7µs) by File::stat::BEGIN@154 at line 154 of File/stat.pm # once (30µs+6µs) by Time::Seconds::BEGIN@29 at line 29 of Time/Seconds.pm # once (28µs+8µs) by Time::Seconds::BEGIN@31 at line 31 of Time/Seconds.pm # once (27µs+8µs) by Getopt::Long::BEGIN@215 at line 215 of Getopt/Long.pm # once (27µs+8µs) by File::Temp::BEGIN@221 at line 221 of File/Temp.pm # once (29µs+6µs) by Time::Seconds::BEGIN@30 at line 30 of Time/Seconds.pm # once (27µs+7µs) by Time::Seconds::BEGIN@33 at line 33 of Time/Seconds.pm # once (27µs+8µs) by Class::MOP::Method::Meta::BEGIN@10 at line 10 of Class/MOP/Method/Meta.pm # once (27µs+7µs) by Eval::Closure::BEGIN@20 at line 20 of Eval/Closure.pm # once (27µs+8µs) by Time::Piece::BEGIN@35 at line 35 of Time/Piece.pm # once (26µs+7µs) by Plack::Util::BEGIN@13 at line 13 of Plack/Util.pm # once (26µs+8µs) by App::Cmd::BEGIN@346 at line 346 of App/Cmd.pm # once (26µs+7µs) by Class::MOP::Mixin::HasOverloads::BEGIN@50 at line 50 of Class/MOP/Mixin/HasOverloads.pm # once (26µs+6µs) by Time::Piece::BEGIN@44 at line 44 of Time/Piece.pm # once (23µs+7µs) by Time::Seconds::BEGIN@32 at line 32 of Time/Seconds.pm # once (25µs+4µs) by Time::Piece::BEGIN@37 at line 37 of Time/Piece.pm # once (24µs+5µs) by Time::Piece::BEGIN@36 at line 36 of Time/Piece.pm # once (24µs+5µs) by Time::Piece::BEGIN@38 at line 38 of Time/Piece.pm # once (22µs+6µs) by Time::Piece::BEGIN@39 at line 39 of Time/Piece.pm # once (22µs+5µs) by Time::Piece::BEGIN@43 at line 43 of Time/Piece.pm # once (22µs+4µs) by Time::Piece::BEGIN@42 at line 42 of Time/Piece.pm # once (21µs+6µs) by Time::Piece::BEGIN@41 at line 41 of Time/Piece.pm # once (21µs+5µs) by Time::Piece::BEGIN@40 at line 40 of Time/Piece.pm # once (18µs+5µs) by HTTP::Server::PSGI::BEGIN@32 at line 32 of HTTP/Server/PSGI.pm # once (16µs+7µs) by Getopt::Long::BEGIN@230 at line 230 of Getopt/Long.pm # once (17µs+4µs) by Getopt::Long::BEGIN@225 at line 225 of Getopt/Long.pm # once (17µs+4µs) by File::Temp::BEGIN@224 at line 224 of File/Temp.pm # once (17µs+4µs) by Time::Local::BEGIN@28 at line 28 of Time/Local.pm # once (17µs+4µs) by File::Temp::BEGIN@228 at line 228 of File/Temp.pm # once (16µs+4µs) by Getopt::Long::BEGIN@227 at line 227 of Getopt/Long.pm # once (16µs+4µs) by Getopt::Long::BEGIN@244 at line 244 of Getopt/Long.pm # once (16µs+4µs) by Time::Local::BEGIN@29 at line 29 of Time/Local.pm # once (16µs+4µs) by File::Temp::BEGIN@232 at line 232 of File/Temp.pm # once (16µs+4µs) by Getopt::Long::BEGIN@229 at line 229 of Getopt/Long.pm # once (16µs+4µs) by Getopt::Long::BEGIN@232 at line 232 of Getopt/Long.pm # once (16µs+4µs) by File::Temp::BEGIN@233 at line 233 of File/Temp.pm # once (16µs+3µs) by File::Temp::BEGIN@234 at line 234 of File/Temp.pm # once (15µs+4µs) by Getopt::Long::BEGIN@231 at line 231 of Getopt/Long.pm # once (15µs+3µs) by Getopt::Long::BEGIN@254 at line 254 of Getopt/Long.pm # once (15µs+3µs) by Getopt::Long::BEGIN@235 at line 235 of Getopt/Long.pm # once (15µs+3µs) by Getopt::Long::BEGIN@233 at line 233 of Getopt/Long.pm # once (14µs+3µs) by Getopt::Long::BEGIN@236 at line 236 of Getopt/Long.pm # once (14µs+4µs) by Getopt::Long::BEGIN@243 at line 243 of Getopt/Long.pm
sub import {
456635µs my $class = shift;
466634µs return unless @_; # Ignore 'use constant;'
476612µs my $constants;
486642µs my $multiple = ref $_[0];
496641µs my $pkg = caller;
506612µs my $flush_mro;
51665µs my $symtab;
52
536626µs if (_CAN_PCS) {
542219µs223µs
# spent 14µs (6+8) within constant::BEGIN@54 which was called: # once (6µs+8µs) by Try::Tiny::ScopeGuard::BEGIN@144 at line 54
no strict 'refs';
# spent 14µs making 1 call to constant::BEGIN@54 # spent 8µs making 1 call to strict::unimport
5566100µs $symtab = \%{$pkg . '::'};
56 };
57
586627µs if ( $multiple ) {
5954µs if (ref $_[0] ne 'HASH') {
60 require Carp;
61 Carp::croak("Invalid reference type '".ref(shift)."' not 'HASH'");
62 }
6351µs $constants = shift;
64 } else {
656120µs unless (defined $_[0]) {
66 require Carp;
67 Carp::croak("Can't use undef as constant name");
68 }
696196µs $constants->{+shift} = undef;
70 }
71
7266127µs foreach my $name ( keys %$constants ) {
73 # Normal constant name
7493814µs186387µs if ($name =~ $normal_constant_name and !$forbidden{$name}) {
# spent 222µs making 93 calls to constant::CORE:match, avg 2µs/call # spent 164µs making 93 calls to constant::CORE:regcomp, avg 2µs/call
75 # Everything is okay
76
77 # Name forced into main, but we're not in main. Fatal.
78 } elsif ($forced_into_main{$name} and $pkg ne 'main') {
79 require Carp;
80 Carp::croak("Constant name '$name' is forced into main::");
81
82 # Starts with double underscore. Fatal.
83 } elsif ($name =~ /^__/) {
84 require Carp;
85 Carp::croak("Constant name '$name' begins with '__'");
86
87 # Maybe the name is tolerable
88 } elsif ($name =~ $tolerable) {
89 # Then we'll warn only if you've asked for warnings
90 if (warnings::enabled()) {
91 if ($keywords{$name}) {
92 warnings::warn("Constant name '$name' is a Perl keyword");
93 } elsif ($forced_into_main{$name}) {
94 warnings::warn("Constant name '$name' is " .
95 "forced into package main::");
96 }
97 }
98
99 # Looks like a boolean
100 # use constant FRED == fred;
101 } elsif ($name =~ $boolean) {
102 require Carp;
103 if (@_) {
104 Carp::croak("Constant name '$name' is invalid");
105 } else {
106 Carp::croak("Constant name looks like boolean value");
107 }
108
109 } else {
110 # Must have bad characters
111 require Carp;
112 Carp::croak("Constant name '$name' has invalid characters");
113 }
114
115 {
11695274µs221µs
# spent 14µs (6+7) within constant::BEGIN@116 which was called: # once (6µs+7µs) by Try::Tiny::ScopeGuard::BEGIN@144 at line 116
no strict 'refs';
# spent 14µs making 1 call to constant::BEGIN@116 # spent 7µs making 1 call to strict::unimport
1179369µs my $full_name = "${pkg}::$name";
11893121µs $declared{$full_name}++;
1199346µs if ($multiple || @_ == 1) {
1209333µs my $scalar = $multiple ? $constants->{$name} : $_[0];
121
122 if (_DOWNGRADE) { # for 5.8 to 5.14
123 # Work around perl bug #31991: Sub names (actually glob
124 # names in general) ignore the UTF8 flag. So we have to
125 # turn it off to get the "right" symbol table entry.
126 utf8::is_utf8 $name and utf8::encode $name;
127 }
128
129 # The constant serves to optimise this entire block out on
130 # 5.8 and earlier.
1319361µs if (_CAN_PCS && $symtab && !exists $symtab->{$name}) {
132 # No typeglob yet, so we can use a reference as space-
133 # efficient proxy for a constant subroutine
134 # The check in Perl_ck_rvconst knows that inlinable
135 # constants from cv_const_sv are read only. So we have to:
13693358µs9377µs Internals::SvREADONLY($scalar, 1);
# spent 77µs making 93 calls to Internals::SvREADONLY, avg 826ns/call
1379368µs $symtab->{$name} = \$scalar;
1389331µs ++$flush_mro;
139 } else {
140 *$full_name = sub () { $scalar };
141 }
142 } elsif (@_) {
143 my @list = @_;
144 *$full_name = sub () { @list };
145 } else {
146 *$full_name = sub () { };
147 }
148 }
149 }
150 # Flush the cache exactly once if we make any direct symbol table changes.
15166619µs66157µs mro::method_changed_in($pkg) if _CAN_PCS && $flush_mro;
# spent 157µs making 66 calls to mro::method_changed_in, avg 2µs/call
152}
153
15415µs1;
155
156__END__
 
# spent 222µs within constant::CORE:match which was called 93 times, avg 2µs/call: # 93 times (222µs+0s) by constant::import at line 74, avg 2µs/call
sub constant::CORE:match; # opcode
# spent 3µs within constant::CORE:qr which was called 3 times, avg 1µs/call: # once (2µs+0s) by Try::Tiny::ScopeGuard::BEGIN@144 at line 20 # once (700ns+0s) by Try::Tiny::ScopeGuard::BEGIN@144 at line 21 # once (500ns+0s) by Try::Tiny::ScopeGuard::BEGIN@144 at line 22
sub constant::CORE:qr; # opcode
# spent 164µs within constant::CORE:regcomp which was called 93 times, avg 2µs/call: # 93 times (164µs+0s) by constant::import at line 74, avg 2µs/call
sub constant::CORE:regcomp; # opcode