← 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/local/share/perl/5.18.2/Class/Load.pm
StatementsExecuted 189 statements in 1.42ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
111679µs4.42msClass::Load::::BEGIN@11Class::Load::BEGIN@11
111540µs6.23msClass::Load::::BEGIN@10Class::Load::BEGIN@10
1021155µs50.1msClass::Load::::try_load_classClass::Load::try_load_class (recurses: max depth 1, inclusive time 62µs)
93177µs49.9msClass::Load::::load_classClass::Load::load_class (recurses: max depth 1, inclusive time 74µs)
11120µs284µsClass::Load::::load_optional_classClass::Load::load_optional_class
11112µs37µsClass::Load::::_nonexistent_fail_reClass::Load::_nonexistent_fail_re
11110µs37µsClass::Load::::BEGIN@12Class::Load::BEGIN@12
2218µs8µsClass::Load::::CORE:regcompClass::Load::CORE:regcomp (opcode)
1118µs12µsClass::Load::::_errorClass::Load::_error
1117µs11µsClass::Load::::BEGIN@8Class::Load::BEGIN@8
1117µs60µsClass::Load::::BEGIN@9Class::Load::BEGIN@9
1116µs16µsClass::Load::::BEGIN@7Class::Load::BEGIN@7
1116µs6µsClass::Load::::BEGIN@2Class::Load::BEGIN@2
1116µs32µsClass::Load::::BEGIN@18Class::Load::BEGIN@18
1114µs4µsClass::Load::::CORE:substClass::Load::CORE:subst (opcode)
1112µs2µsClass::Load::::CORE:qrClass::Load::CORE:qr (opcode)
111600ns600nsClass::Load::::CORE:matchClass::Load::CORE:match (opcode)
0000s0sClass::Load::::__ANON__[:154]Class::Load::__ANON__[:154]
0000s0sClass::Load::::__ANON__[:157]Class::Load::__ANON__[:157]
0000s0sClass::Load::::__ANON__[:182]Class::Load::__ANON__[:182]
0000s0sClass::Load::::__ANON__[:185]Class::Load::__ANON__[:185]
0000s0sClass::Load::::_croakClass::Load::_croak
0000s0sClass::Load::::_or_listClass::Load::_or_list
0000s0sClass::Load::::_version_fail_reClass::Load::_version_fail_re
0000s0sClass::Load::::load_first_existing_classClass::Load::load_first_existing_class
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package Class::Load;
2
# spent 6µs within Class::Load::BEGIN@2 which was called: # once (6µs+0s) by App::Cmd::BEGIN@13 at line 4
BEGIN {
314µs $Class::Load::AUTHORITY = 'cpan:SARTAK';
4123µs16µs}
# spent 6µs making 1 call to Class::Load::BEGIN@2
5# git description: v0.20-8-gc4c6e08
61900ns$Class::Load::VERSION = '0.21';
7231µs226µs
# spent 16µs (6+10) within Class::Load::BEGIN@7 which was called: # once (6µs+10µs) by App::Cmd::BEGIN@13 at line 7
use strict;
# spent 16µs making 1 call to Class::Load::BEGIN@7 # spent 10µs making 1 call to strict::import
8222µs215µs
# spent 11µs (7+4) within Class::Load::BEGIN@8 which was called: # once (7µs+4µs) by App::Cmd::BEGIN@13 at line 8
use warnings;
# spent 11µs making 1 call to Class::Load::BEGIN@8 # spent 4µs making 1 call to warnings::import
9223µs2114µs
# spent 60µs (7+54) within Class::Load::BEGIN@9 which was called: # once (7µs+54µs) by App::Cmd::BEGIN@13 at line 9
use base 'Exporter';
# spent 60µs making 1 call to Class::Load::BEGIN@9 # spent 54µs making 1 call to base::import
10281µs26.29ms
# spent 6.23ms (540µs+5.69) within Class::Load::BEGIN@10 which was called: # once (540µs+5.69ms) by App::Cmd::BEGIN@13 at line 10
use Data::OptList 'mkopt';
# spent 6.23ms making 1 call to Class::Load::BEGIN@10 # spent 61µs making 1 call to Sub::Install::__ANON__[Sub/Install.pm:270]
113122µs24.43ms
# spent 4.42ms (679µs+3.74) within Class::Load::BEGIN@11 which was called: # once (679µs+3.74ms) by App::Cmd::BEGIN@13 at line 11
use Module::Implementation 0.04;
# spent 4.42ms making 1 call to Class::Load::BEGIN@11 # spent 12µs making 1 call to UNIVERSAL::VERSION
1213µs121µs
# spent 37µs (10+27) within Class::Load::BEGIN@12 which was called: # once (10µs+27µs) by App::Cmd::BEGIN@13 at line 17
use Module::Runtime 0.012 qw(
# spent 21µs making 1 call to Module::Runtime::import
13 check_module_name
14 module_notional_filename
15 require_module
16 use_module
17228µs243µs);
# spent 37µs making 1 call to Class::Load::BEGIN@12 # spent 6µs making 1 call to UNIVERSAL::VERSION
182717µs258µs
# spent 32µs (6+26) within Class::Load::BEGIN@18 which was called: # once (6µs+26µs) by App::Cmd::BEGIN@13 at line 18
use Try::Tiny;
# spent 32µs making 1 call to Class::Load::BEGIN@18 # spent 26µs making 1 call to Exporter::import
19
20{
2123µs122µs my $loader = Module::Implementation::build_loader_sub(
# spent 22µs making 1 call to Module::Implementation::build_loader_sub
22 implementations => [ 'XS', 'PP' ],
23 symbols => ['is_class_loaded'],
24 );
25
2613µs1477µs $loader->();
27}
28
2911µsour @EXPORT_OK = qw/load_class load_optional_class try_load_class is_class_loaded load_first_existing_class/;
301900nsour %EXPORT_TAGS = (
31 all => \@EXPORT_OK,
32);
33
341100nsour $ERROR;
35
36
# spent 49.9ms (77µs+49.8) within Class::Load::load_class which was called 9 times, avg 5.55ms/call: # 3 times (39µs+47.4ms) by App::Cmd::_command at line 194 of App/Cmd.pm, avg 15.8ms/call # 3 times (26µs+2.42ms) by App::Cmd::_load_default_plugin at line 287 of App/Cmd.pm, avg 815µs/call # 3 times (12µs+-12µs) by App::Cmd::_setup_command at line 35 of App/Cmd.pm, avg 0s/call
sub load_class {
3794µs my $class = shift;
3894µs my $options = shift;
39
40950µs949.9ms my ($res, $e) = try_load_class($class, $options);
# spent 49.9ms making 9 calls to Class::Load::try_load_class, avg 5.55ms/call, recursion: max depth 1, sum of overlapping time 62µs
41923µs return $class if $res;
42
43 _croak($e);
44}
45
46sub load_first_existing_class {
47 my $classes = Data::OptList::mkopt(\@_)
48 or return;
49
50 foreach my $class (@{$classes}) {
51 check_module_name($class->[0]);
52 }
53
54 for my $class (@{$classes}) {
55 my ($name, $options) = @{$class};
56
57 # We need to be careful not to pass an undef $options to this sub,
58 # since the XS version will blow up if that happens.
59 return $name if is_class_loaded($name, ($options ? $options : ()));
60
61 my ($res, $e) = try_load_class($name, $options);
62
63 return $name if $res;
64
65 my $file = module_notional_filename($name);
66
67 next if $e =~ /^Can't locate \Q$file\E in \@INC/;
68 next
69 if $options
70 && defined $options->{-version}
71 && $e =~ _version_fail_re($name, $options->{-version});
72
73 _croak("Couldn't load class ($name) because: $e");
74 }
75
76 my @list = map {
77 $_->[0]
78 . ( $_->[1] && defined $_->[1]{-version}
79 ? " (version >= $_->[1]{-version})"
80 : q{} )
81 } @{$classes};
82
83 my $err
84 .= q{Can't locate }
85 . _or_list(@list)
86 . " in \@INC (\@INC contains: @INC).";
87 _croak($err);
88}
89
90sub _version_fail_re {
91 my $name = shift;
92 my $vers = shift;
93
94 return qr/\Q$name\E version \Q$vers\E required--this is only version/;
95}
96
97
# spent 37µs (12+25) within Class::Load::_nonexistent_fail_re which was called: # once (12µs+25µs) by Class::Load::load_optional_class at line 131
sub _nonexistent_fail_re {
981300ns my $name = shift;
99
1001800ns115µs my $file = module_notional_filename($name);
# spent 15µs making 1 call to Module::Runtime::module_notional_filename
101119µs210µs return qr/Can't locate \Q$file\E in \@INC/;
# spent 7µs making 1 call to Class::Load::CORE:regcomp # spent 2µs making 1 call to Class::Load::CORE:qr
102}
103
104sub _or_list {
105 return $_[0] if @_ == 1;
106
107 return join ' or ', @_ if @_ ==2;
108
109 my $last = pop;
110
111 my $list = join ', ', @_;
112 $list .= ', or ' . $last;
113
114 return $list;
115}
116
117
# spent 284µs (20+265) within Class::Load::load_optional_class which was called: # once (20µs+265µs) by App::Cmd::Setup::_make_app_class at line 111 of App/Cmd/Setup.pm
sub load_optional_class {
1181500ns my $class = shift;
1191300ns my $options = shift;
120
12112µs118µs check_module_name($class);
# spent 18µs making 1 call to Module::Runtime::check_module_name
122
12317µs1208µs my ($res, $e) = try_load_class($class, $options);
# spent 208µs making 1 call to Class::Load::try_load_class
1241200ns return 1 if $res;
125
1261200ns return 0
127 if $options
128 && defined $options->{-version}
129 && $e =~ _version_fail_re($class, $options->{-version});
130
131111µs339µs return 0
# spent 37µs making 1 call to Class::Load::_nonexistent_fail_re # spent 1µs making 1 call to Class::Load::CORE:regcomp # spent 600ns making 1 call to Class::Load::CORE:match
132 if $e =~ _nonexistent_fail_re($class);
133
134 _croak($e);
135}
136
137
# spent 50.1ms (155µs+49.9) within Class::Load::try_load_class which was called 10 times, avg 5.01ms/call: # 9 times (132µs+49.7ms) by Class::Load::load_class at line 40, avg 5.54ms/call # once (23µs+185µs) by Class::Load::load_optional_class at line 123
sub try_load_class {
138102µs my $class = shift;
139103µs my $options = shift;
140
1411011µs10131µs check_module_name($class);
# spent 131µs making 10 calls to Module::Runtime::check_module_name, avg 13µs/call
142
143103µs local $@;
144104µs undef $ERROR;
145
1461049µs1028µs if (is_class_loaded($class)) {
# spent 28µs making 10 calls to Class::Load::XS::is_class_loaded, avg 3µs/call
147 # We need to check this here rather than in is_class_loaded() because
148 # we want to return the error message for a failed version check, but
149 # is_class_loaded just returns true/false.
15038µs return 1 unless $options && defined $options->{-version};
151 return try {
152 $class->VERSION($options->{-version});
153 1;
154 }
155 catch {
156 _error($_);
157 };
158 }
159
160711µs7115µs my $file = module_notional_filename($class);
# spent 115µs making 7 calls to Module::Runtime::module_notional_filename, avg 16µs/call
161 # This says "our diagnostics of the package
162 # say perl's INC status about the file being loaded are
163 # wrong", so we delete it from %INC, so when we call require(),
164 # perl will *actually* try reloading the file.
165 #
166 # If the file is already in %INC, it won't retry,
167 # And on 5.8, it won't fail either!
168 #
169 # The extra benefit of this trick, is it helps even on
170 # 5.10, as instead of dying with "Compilation failed",
171 # it will die with the actual error, and that's a win-win.
17277µs delete $INC{$file};
173 return try {
174716µs local $SIG{__DIE__} = 'DEFAULT';
17577µs if ($options && defined $options->{-version}) {
176 use_module($class, $options->{-version});
177 }
178 else {
179710µs749.4ms require_module($class);
# spent 49.4ms making 7 calls to Module::Runtime::require_module, avg 7.06ms/call
180 }
181621µs 1;
182 }
183 catch {
18414µs112µs _error($_);
# spent 12µs making 1 call to Class::Load::_error
185764µs1449.7ms };
# spent 49.7ms making 7 calls to Try::Tiny::try, avg 7.10ms/call # spent 29µs making 7 calls to Try::Tiny::catch, avg 4µs/call
186}
187
188
# spent 12µs (8+4) within Class::Load::_error which was called: # once (8µs+4µs) by Class::Load::catch {...} at line 184
sub _error {
1891500ns my $e = shift;
190
19118µs14µs $e =~ s/ at .+?Runtime\.pm line [0-9]+\.$//;
# spent 4µs making 1 call to Class::Load::CORE:subst
1921700ns chomp $e;
193
1941400ns $ERROR = $e;
1951300ns return 0 unless wantarray;
19613µs return 0, $ERROR;
197}
198
199sub _croak {
200 require Carp;
201 local $Carp::CarpLevel = $Carp::CarpLevel + 2;
202 Carp::croak(shift);
203}
204
20515µs1;
206
207# ABSTRACT: a working (require "Class::Name") and more
208
209__END__
 
# spent 600ns within Class::Load::CORE:match which was called: # once (600ns+0s) by Class::Load::load_optional_class at line 131
sub Class::Load::CORE:match; # opcode
# spent 2µs within Class::Load::CORE:qr which was called: # once (2µs+0s) by Class::Load::_nonexistent_fail_re at line 101
sub Class::Load::CORE:qr; # opcode
# spent 8µs within Class::Load::CORE:regcomp which was called 2 times, avg 4µs/call: # once (7µs+0s) by Class::Load::_nonexistent_fail_re at line 101 # once (1µs+0s) by Class::Load::load_optional_class at line 131
sub Class::Load::CORE:regcomp; # opcode
# spent 4µs within Class::Load::CORE:subst which was called: # once (4µs+0s) by Class::Load::_error at line 191
sub Class::Load::CORE:subst; # opcode