Profile of Module/Implementation.pm

← Index
NYTProf Performance Profile «line view»
For -e
Run on Thu Jun 30 16:16:00 2016
Reported on Thu Jun 30 16:16:08 2016

Filename | /home/s1/perl5/perlbrew/perls/perl-5.22.1/lib/site_perl/5.22.1/Module/Implementation.pm
Statements | Executed 73 statements in 1.87ms

Subroutines
Calls | P | F | Exclusive Time | Inclusive Time | Subroutine
--- | --- | --- | --- | --- | ---
1 | 1 | 1 | 2.20ms | 2.38ms | Module::Implementation::::BEGIN@8Module::Implementation::BEGIN@8
1 | 1 | 1 | 1.48ms | 4.92ms | Module::Implementation::::BEGIN@9Module::Implementation::BEGIN@9
1 | 1 | 1 | 50µs | 55µs | Module::Implementation::::_copy_symbolsModule::Implementation::_copy_symbols
1 | 1 | 1 | 31µs | 1.39ms | Module::Implementation::::_load_implementationModule::Implementation::_load_implementation
1 | 1 | 1 | 26µs | 30µs | Module::Implementation::::_build_loaderModule::Implementation::_build_loader
1 | 1 | 1 | 24µs | 27µs | Module::Implementation::::BEGIN@5Module::Implementation::BEGIN@5
1 | 1 | 1 | 21µs | 1.46ms | Module::Implementation::::__ANON__[:52]Module::Implementation::__ANON__[:52]
1 | 1 | 1 | 15µs | 21µs | Module::Implementation::::BEGIN@6Module::Implementation::BEGIN@6
1 | 1 | 1 | 12µs | 28µs | Module::Implementation::::BEGIN@129Module::Implementation::BEGIN@129
1 | 1 | 1 | 11µs | 28µs | Module::Implementation::::BEGIN@128Module::Implementation::BEGIN@128
6 | 2 | 1 | 9µs | 9µs | Module::Implementation::::CORE:substModule::Implementation::CORE:subst (opcode)
1 | 1 | 1 | 9µs | 38µs | Module::Implementation::::build_loader_subModule::Implementation::build_loader_sub
1 | 1 | 1 | 8µs | 1.29ms | Module::Implementation::::try {...} Module::Implementation::try {...}
0 | 0 | 0 | 0s | 0s | Module::Implementation::::__ANON__[:78]Module::Implementation::__ANON__[:78]
0 | 0 | 0 | 0s | 0s | Module::Implementation::::__ANON__[:82]Module::Implementation::__ANON__[:82]
0 | 0 | 0 | 0s | 0s | Module::Implementation::::__ANON__[:95]Module::Implementation::__ANON__[:95]
0 | 0 | 0 | 0s | 0s | Module::Implementation::::__ANON__[:98]Module::Implementation::__ANON__[:98]
0 | 0 | 0 | 0s | 0s | Module::Implementation::::catch {...} Module::Implementation::catch {...}
0 | 0 | 0 | 0s | 0s | Module::Implementation::::implementation_forModule::Implementation::implementation_for

Call graph for these subroutines as a Graphviz dot language file.

Line | State ments | Time on line | Calls | Time in subs | Code
--- | --- | --- | --- | --- | ---
1 |  |  |  |  | package Module::Implementation;
2 |  |  |  |  | # git description: v0.08-2-gd599347
3 | 1 | 600ns |  |  | $Module::Implementation::VERSION = '0.09';
4 |  |  |  |  |
5 | 2 | 35µs | 2 | 31µs | # spent 27µs (24+3) within Module::Implementation::BEGIN@5 which was called: # once (24µs+3µs) by Params::Validate::BEGIN@11 at line 5 use strict; # spent 27µs making 1 call to Module::Implementation::BEGIN@5 # spent 3µs making 1 call to strict::import
6 | 2 | 44µs | 2 | 28µs | # spent 21µs (15+6) within Module::Implementation::BEGIN@6 which was called: # once (15µs+6µs) by Params::Validate::BEGIN@11 at line 6 use warnings; # spent 21µs making 1 call to Module::Implementation::BEGIN@6 # spent 6µs making 1 call to warnings::import
7 |  |  |  |  |
8 | 3 | 409µs | 3 | 2.42ms | # spent 2.38ms (2.20+187µs) within Module::Implementation::BEGIN@8 which was called: # once (2.20ms+187µs) by Params::Validate::BEGIN@11 at line 8 use Module::Runtime 0.012 qw( require_module ); # spent 2.38ms making 1 call to Module::Implementation::BEGIN@8 # spent 20µs making 1 call to Module::Runtime::import # spent 14µs making 1 call to UNIVERSAL::VERSION
9 | 2 | 1.04ms | 2 | 4.97ms | # spent 4.92ms (1.48+3.44) within Module::Implementation::BEGIN@9 which was called: # once (1.48ms+3.44ms) by Params::Validate::BEGIN@11 at line 9 use Try::Tiny; # spent 4.92ms making 1 call to Module::Implementation::BEGIN@9 # spent 50µs making 1 call to Exporter::import
10 |  |  |  |  |
11 |  |  |  |  | # This is needed for the benefit of Test::CleanNamespaces, which in turn loads
12 |  |  |  |  | # Package::Stash, which in turn loads this module and expects a minimum
13 |  |  |  |  | # version.
14 | 1 | 1µs |  |  | unless ( exists $Module::Implementation::{VERSION}
15 |  |  |  |  | && ${ $Module::Implementation::{VERSION} } ) {
16 |  |  |  |  |
17 |  |  |  |  | $Module::Implementation::{VERSION} = \42;
18 |  |  |  |  | }
19 |  |  |  |  |
20 | 1 | 200ns |  |  | my %Implementation;
21 |  |  |  |  |
22 |  |  |  |  | # spent 38µs (9+30) within Module::Implementation::build_loader_sub which was called: # once (9µs+30µs) by DateTime::Duration::BEGIN@11 at line 46 of Params/Validate.pm sub build_loader_sub {
23 | 1 | 900ns |  |  | my $caller = caller();
24 |  |  |  |  |
25 | 1 | 6µs | 1 | 30µs | return _build_loader( $caller, @_ ); # spent 30µs making 1 call to Module::Implementation::_build_loader
26 |  |  |  |  | }
27 |  |  |  |  |
28 |  |  |  |  | # spent 30µs (26+3) within Module::Implementation::_build_loader which was called: # once (26µs+3µs) by Module::Implementation::build_loader_sub at line 25 sub _build_loader {
29 | 1 | 400ns |  |  | my $package = shift;
30 | 1 | 2µs |  |  | my %args = @_;
31 |  |  |  |  |
32 | 1 | 1µs |  |  | my @implementations = @{ $args{implementations} };
33 | 1 | 1µs |  |  | my @symbols = @{ $args{symbols} || [] };
34 |  |  |  |  |
35 | 1 | 200ns |  |  | my $implementation;
36 | 1 | 1µs |  |  | my $env_var = uc $package;
37 | 1 | 17µs | 1 | 4µs | $env_var =~ s/::/_/g; # spent 4µs making 1 call to Module::Implementation::CORE:subst
38 | 1 | 900ns |  |  | $env_var .= '_IMPLEMENTATION';
39 |  |  |  |  |
40 |  |  |  |  | # spent 1.46ms (21µs+1.44) within Module::Implementation::__ANON__[/home/s1/perl5/perlbrew/perls/perl-5.22.1/lib/site_perl/5.22.1/Module/Implementation.pm:52] which was called: # once (21µs+1.44ms) by DateTime::Duration::BEGIN@11 at line 61 of Params/Validate.pm return sub {
41 |  |  |  |  | my ( $implementation, $loaded ) = _load_implementation(
42 |  |  |  |  | $package,
43 | 1 | 5µs | 1 | 1.39ms | $ENV{$env_var}, # spent 1.39ms making 1 call to Module::Implementation::_load_implementation
44 |  |  |  |  | \@implementations,
45 |  |  |  |  | );
46 |  |  |  |  |
47 | 1 | 1µs |  |  | $Implementation{$package} = $implementation;
48 |  |  |  |  |
49 | 1 | 4µs | 1 | 55µs | _copy_symbols( $loaded, $package, \@symbols ); # spent 55µs making 1 call to Module::Implementation::_copy_symbols
50 |  |  |  |  |
51 | 1 | 5µs |  |  | return $loaded;
52 | 1 | 10µs |  |  | };
53 |  |  |  |  | }
54 |  |  |  |  |
55 |  |  |  |  | sub implementation_for {
56 |  |  |  |  | my $package = shift;
57 |  |  |  |  |
58 |  |  |  |  | return $Implementation{$package};
59 |  |  |  |  | }
60 |  |  |  |  |
61 |  |  |  |  | # spent 1.39ms (31µs+1.36) within Module::Implementation::_load_implementation which was called: # once (31µs+1.36ms) by Module::Implementation::__ANON__[/home/s1/perl5/perlbrew/perls/perl-5.22.1/lib/site_perl/5.22.1/Module/Implementation.pm:52] at line 43 sub _load_implementation {
62 | 1 | 400ns |  |  | my $package = shift;
63 | 1 | 1µs |  |  | my $env_value = shift;
64 | 1 | 200ns |  |  | my $implementations = shift;
65 |  |  |  |  |
66 | 1 | 500ns |  |  | if ($env_value) {
67 |  |  |  |  | die "$env_value is not a valid implementation for $package"
68 |  |  |  |  | unless grep { $_ eq $env_value } @{$implementations};
69 |  |  |  |  |
70 |  |  |  |  | my $requested = "${package}::$env_value";
71 |  |  |  |  |
72 |  |  |  |  | # Values from the %ENV hash are tainted. We know it's safe to untaint
73 |  |  |  |  | # this value because the value was one of our known implementations.
74 |  |  |  |  | ($requested) = $requested =~ /^(.+)$/;
75 |  |  |  |  |
76 |  |  |  |  | try {
77 |  |  |  |  | require_module($requested);
78 |  |  |  |  | }
79 |  |  |  |  | catch {
80 |  |  |  |  | require Carp;
81 |  |  |  |  | Carp::croak("Could not load $requested: $_");
82 |  |  |  |  | };
83 |  |  |  |  |
84 |  |  |  |  | return ( $env_value, $requested );
85 |  |  |  |  | }
86 |  |  |  |  | else {
87 | 1 | 100ns |  |  | my $err;
88 | 1 | 1µs |  |  | for my $possible ( @{$implementations} ) {
89 | 1 | 1µs |  |  | my $try = "${package}::$possible";
90 |  |  |  |  |
91 | 1 | 100ns |  |  | my $ok;
92 |  |  |  |  | # spent 1.29ms (8µs+1.28) within Module::Implementation::try {...} which was called: # once (8µs+1.28ms) by Try::Tiny::try at line 92 of Try/Tiny.pm try {
93 | 1 | 2µs | 1 | 1.28ms | require_module($try); # spent 1.28ms making 1 call to Module::Runtime::require_module
94 | 1 | 4µs |  |  | $ok = 1;
95 |  |  |  |  | }
96 |  |  |  |  | catch {
97 |  |  |  |  | $err .= $_ if defined $_;
98 | 1 | 17µs | 2 | 1.36ms | }; # spent 1.32ms making 1 call to Try::Tiny::try # spent 34µs making 1 call to Try::Tiny::catch
99 |  |  |  |  |
100 | 1 | 7µs |  |  | return ( $possible, $try ) if $ok;
101 |  |  |  |  | }
102 |  |  |  |  |
103 |  |  |  |  | require Carp;
104 |  |  |  |  | if ( defined $err && length $err ) {
105 |  |  |  |  | Carp::croak(
106 |  |  |  |  | "Could not find a suitable $package implementation: $err");
107 |  |  |  |  | }
108 |  |  |  |  | else {
109 |  |  |  |  | Carp::croak(
110 |  |  |  |  | 'Module::Runtime failed to load a module but did not throw a real error. This should never happen. Something is very broken'
111 |  |  |  |  | );
112 |  |  |  |  | }
113 |  |  |  |  | }
114 |  |  |  |  | }
115 |  |  |  |  |
116 |  |  |  |  | # spent 55µs (50+5) within Module::Implementation::_copy_symbols which was called: # once (50µs+5µs) by Module::Implementation::__ANON__[/home/s1/perl5/perlbrew/perls/perl-5.22.1/lib/site_perl/5.22.1/Module/Implementation.pm:52] at line 49 sub _copy_symbols {
117 | 1 | 500ns |  |  | my $from_package = shift;
118 | 1 | 300ns |  |  | my $to_package = shift;
119 | 1 | 300ns |  |  | my $symbols = shift;
120 |  |  |  |  |
121 | 1 | 6µs |  |  | for my $sym ( @{$symbols} ) {
122 | 5 | 20µs | 5 | 5µs | my $type = $sym =~ s/^([\$\@\%\&\*])// ? $1 : '&'; # spent 5µs making 5 calls to Module::Implementation::CORE:subst, avg 1µs/call
123 |  |  |  |  |
124 | 5 | 5µs |  |  | my $from = "${from_package}::$sym";
125 | 5 | 3µs |  |  | my $to = "${to_package}::$sym";
126 |  |  |  |  |
127 |  |  |  |  | {
128 | 7 | 44µs | 2 | 44µs | # spent 28µs (11+16) within Module::Implementation::BEGIN@128 which was called: # once (11µs+16µs) by Params::Validate::BEGIN@11 at line 128 no strict 'refs'; # spent 28µs making 1 call to Module::Implementation::BEGIN@128 # spent 16µs making 1 call to strict::unimport
129 | 2 | 142µs | 2 | 45µs | # spent 28µs (12+17) within Module::Implementation::BEGIN@129 which was called: # once (12µs+17µs) by Params::Validate::BEGIN@11 at line 129 no warnings 'once'; # spent 28µs making 1 call to Module::Implementation::BEGIN@129 # spent 17µs making 1 call to warnings::unimport
130 |  |  |  |  |
131 |  |  |  |  | # Copied from Exporter
132 |  |  |  |  | *{$to}
133 |  |  |  |  | = $type eq '&' ? \&{$from}
134 |  |  |  |  | : $type eq '$' ? \${$from}
135 |  |  |  |  | : $type eq '@' ? \@{$from}
136 |  |  |  |  | : $type eq '%' ? \%{$from}
137 | 5 | 18µs |  |  | : $type eq '*' ? *{$from}
138 |  |  |  |  | : die
139 |  |  |  |  | "Can't copy symbol from $from_package to $to_package: $type$sym";
140 |  |  |  |  | }
141 |  |  |  |  | }
142 |  |  |  |  | }
143 |  |  |  |  |
144 | 1 | 6µs |  |  | 1;
145 |  |  |  |  |
146 |  |  |  |  | # ABSTRACT: Loads one of several alternate underlying implementations for a module
147 |  |  |  |  |
148 |  |  |  |  | __END__
|  |  |  |  | # spent 9µs within Module::Implementation::CORE:subst which was called 6 times, avg 1µs/call: # 5 times (5µs+0s) by Module::Implementation::_copy_symbols at line 122, avg 1µs/call # once (4µs+0s) by Module::Implementation::_build_loader at line 37 sub Module::Implementation::CORE:subst; # opcode