← Index
NYTProf Performance Profile   « block view • line view • sub view »
For -e
  Run on Wed Nov 17 22:00:36 2010
Reported on Wed Nov 17 22:13:43 2010

Filename/home/doy/coding/src/namespace-clean/namespace-clean-0.18/blib/lib/namespace/clean.pm
StatementsExecuted 11531 statements in 291ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
5421136ms294msnamespace::clean::::__ANON__[:59]namespace::clean::__ANON__[:59]
5553.33ms11.3msnamespace::clean::::importnamespace::clean::import
49112.26ms265msnamespace::clean::::clean_subroutinesnamespace::clean::clean_subroutines
1111.89ms3.19msnamespace::clean::::BEGIN@15namespace::clean::BEGIN@15
1111.76ms9.36msnamespace::clean::::BEGIN@17namespace::clean::BEGIN@17
5111.41ms3.97msnamespace::clean::::get_functionsnamespace::clean::get_functions
511388µs916µsnamespace::clean::::get_class_storenamespace::clean::get_class_store
511190µs31.8msnamespace::clean::::__ANON__[:117]namespace::clean::__ANON__[:117]
11183µs379µsnamespace::clean::::BEGIN@14namespace::clean::BEGIN@14
11169µs151µsnamespace::clean::::BEGIN@16namespace::clean::BEGIN@16
11156µs132µsnamespace::clean::::BEGIN@166namespace::clean::BEGIN@166
11152µs52µsnamespace::clean::::BEGIN@2namespace::clean::BEGIN@2
41139µs39µsnamespace::clean::::CORE:matchnamespace::clean::CORE:match (opcode)
11139µs111µsnamespace::clean::::BEGIN@10namespace::clean::BEGIN@10
11138µs53µsnamespace::clean::::BEGIN@11namespace::clean::BEGIN@11
11134µs149µsnamespace::clean::::BEGIN@13namespace::clean::BEGIN@13
11117µs17µsnamespace::clean::::BEGIN@5namespace::clean::BEGIN@5
0000s0snamespace::clean::::__ANON__[:90]namespace::clean::__ANON__[:90]
0000s0snamespace::clean::::unimportnamespace::clean::unimport
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package namespace::clean;
2
# spent 52µs within namespace::clean::BEGIN@2 which was called: # once (52µs+0s) by MooseX::Types::Base::BEGIN@16 at line 4
BEGIN {
3131µs $namespace::clean::AUTHORITY = 'cpan:PHAYLON';
4189µs152µs}
# spent 52µs making 1 call to namespace::clean::BEGIN@2
5
# spent 17µs within namespace::clean::BEGIN@5 which was called: # once (17µs+0s) by MooseX::Types::Base::BEGIN@16 at line 7
BEGIN {
6120µs $namespace::clean::VERSION = '0.18';
7170µs117µs}
# spent 17µs making 1 call to namespace::clean::BEGIN@5
8# ABSTRACT: Keep imports and functions out of your namespace
9
10396µs2184µs
# spent 111µs (39+72) within namespace::clean::BEGIN@10 which was called: # once (39µs+72µs) by MooseX::Types::Base::BEGIN@16 at line 10
use warnings;
# spent 111µs making 1 call to namespace::clean::BEGIN@10 # spent 72µs making 1 call to warnings::import
113101µs268µs
# spent 53µs (38+15) within namespace::clean::BEGIN@11 which was called: # once (38µs+15µs) by MooseX::Types::Base::BEGIN@16 at line 11
use strict;
# spent 53µs making 1 call to namespace::clean::BEGIN@11 # spent 15µs making 1 call to strict::import
12
133128µs2264µs
# spent 149µs (34+115) within namespace::clean::BEGIN@13 which was called: # once (34µs+115µs) by MooseX::Types::Base::BEGIN@16 at line 13
use vars qw( $STORAGE_VAR );
# spent 149µs making 1 call to namespace::clean::BEGIN@13 # spent 115µs making 1 call to vars::import
143305µs3675µs
# spent 379µs (83+296) within namespace::clean::BEGIN@14 which was called: # once (83µs+296µs) by MooseX::Types::Base::BEGIN@16 at line 14
use Sub::Name 0.04 qw(subname);
# spent 379µs making 1 call to namespace::clean::BEGIN@14 # spent 169µs making 1 call to Exporter::import # spent 127µs making 1 call to UNIVERSAL::VERSION
153752µs33.51ms
# spent 3.19ms (1.89+1.31) within namespace::clean::BEGIN@15 which was called: # once (1.89ms+1.31ms) by MooseX::Types::Base::BEGIN@16 at line 15
use Sub::Identify 0.04 qw(sub_fullname);
# spent 3.19ms making 1 call to namespace::clean::BEGIN@15 # spent 239µs making 1 call to Exporter::import # spent 73µs making 1 call to UNIVERSAL::VERSION
163185µs3233µs
# spent 151µs (69+82) within namespace::clean::BEGIN@16 which was called: # once (69µs+82µs) by MooseX::Types::Base::BEGIN@16 at line 16
use Package::Stash 0.03;
# spent 151µs making 1 call to namespace::clean::BEGIN@16 # spent 50µs making 1 call to UNIVERSAL::VERSION # spent 32µs making 1 call to Package::DeprecationManager::__ANON__[Package/DeprecationManager.pm:61]
1733.45ms310.6ms
# spent 9.36ms (1.76+7.60) within namespace::clean::BEGIN@17 which was called: # once (1.76ms+7.60ms) by MooseX::Types::Base::BEGIN@16 at line 17
use B::Hooks::EndOfScope 0.07;
# spent 9.36ms making 1 call to namespace::clean::BEGIN@17 # spent 1.19ms making 1 call to Sub::Exporter::__ANON__[Sub/Exporter.pm:756] # spent 56µs making 1 call to UNIVERSAL::VERSION
18
1914µs$STORAGE_VAR = '__NAMESPACE_CLEAN_STORAGE';
20
21
22
# spent 294ms (136+159) within namespace::clean::__ANON__[/home/doy/coding/src/namespace-clean/namespace-clean-0.18/blib/lib/namespace/clean.pm:59] which was called 54 times, avg 5.45ms/call: # 49 times (121ms+142ms) by namespace::clean::clean_subroutines at line 63, avg 5.36ms/call # 5 times (14.7ms+16.9ms) by namespace::clean::__ANON__[/home/doy/coding/src/namespace-clean/namespace-clean-0.18/blib/lib/namespace/clean.pm:117] at line 116, avg 6.31ms/call
my $RemoveSubs = sub {
23
2454234µs my $cleanee = shift;
2554172µs my $store = shift;
26541.95ms54924µs my $cleanee_stash = Package::Stash->new($cleanee);
# spent 924µs making 54 calls to Package::Stash::XS::new, avg 17µs/call
27542.35ms541.40ms my $deleted_stash = Package::Stash->new("namespace::clean::deleted::$cleanee");
# spent 1.40ms making 54 calls to Package::Stash::XS::new, avg 26µs/call
28 SYMBOL:
29541.28ms for my $f (@_) {
308252.68ms my $variable = "&$f";
31 # ignore already removed symbols
328252.80ms next SYMBOL if $store->{exclude}{ $f };
33
3482528.6ms165023.1ms next SYMBOL unless $cleanee_stash->has_symbol($variable);
# spent 19.5ms making 825 calls to Package::Stash::XS::has_symbol, avg 24µs/call # spent 3.64ms making 825 calls to Package::Stash::XS::namespace, avg 4µs/call
35
3682518.0ms8254.10ms if (ref(\$cleanee_stash->namespace->{$f}) eq 'GLOB') {
# spent 4.10ms making 825 calls to Package::Stash::XS::namespace, avg 5µs/call
37 # convince the Perl debugger to work
38 # it assumes that sub_fullname($sub) can always be used to find the CV again
39 # since we are deleting the glob where the subroutine was originally
40 # defined, that assumption no longer holds, so we need to move it
41 # elsewhere and point the CV's name to the new glob.
4282527.2ms165021.5ms my $sub = $cleanee_stash->get_symbol($variable);
# spent 18.0ms making 825 calls to Package::Stash::XS::get_symbol, avg 22µs/call # spent 3.49ms making 825 calls to Package::Stash::XS::namespace, avg 4µs/call
4382521.8ms165024.1ms if ( sub_fullname($sub) eq ($cleanee_stash->name . "::$f") ) {
# spent 19.9ms making 825 calls to Sub::Identify::sub_fullname, avg 24µs/call # spent 4.17ms making 825 calls to Package::Stash::XS::name, avg 5µs/call
44 my $new_fq = $deleted_stash->name . "::$f";
45 subname($new_fq, $sub);
46 $deleted_stash->add_symbol($variable, $sub);
47 }
48 }
49
50 my ($scalar, $array, $hash, $io) = map {
51825105ms660081.6ms $cleanee_stash->get_symbol($_ . $f)
# spent 67.7ms making 3300 calls to Package::Stash::XS::get_symbol, avg 21µs/call # spent 13.9ms making 3300 calls to Package::Stash::XS::namespace, avg 4µs/call
52 } '$', '@', '%', '';
5382531.9ms165026.2ms $cleanee_stash->remove_glob($f);
# spent 22.9ms making 825 calls to Package::Stash::XS::remove_glob, avg 28µs/call # spent 3.30ms making 825 calls to Package::Stash::XS::namespace, avg 4µs/call
5482521.6ms for my $var (['$', $scalar], ['@', $array], ['%', $hash], ['', $io]) {
5533007.21ms next unless defined $var->[1];
56 $cleanee_stash->add_symbol($var->[0] . $f, $var->[1]);
57 }
58 }
59118µs};
60
61
# spent 265ms (2.26+263) within namespace::clean::clean_subroutines which was called 49 times, avg 5.41ms/call: # 49 times (2.26ms+263ms) by namespace::autoclean::__ANON__[/home/doy/perl5/perlbrew/perls/perl-5.10.1/lib/site_perl/5.10.1/namespace/autoclean.pm:57] at line 56 of namespace/autoclean.pm, avg 5.41ms/call
sub clean_subroutines {
6249816µs my ($nc, $cleanee, @subs) = @_;
63491.35ms49263ms $RemoveSubs->($cleanee, {}, @subs);
# spent 263ms making 49 calls to namespace::clean::__ANON__[namespace/clean.pm:59], avg 5.36ms/call
64}
65
66
67
# spent 11.3ms (3.33+7.95) within namespace::clean::import which was called 5 times, avg 2.26ms/call: # once (1.42ms+3.40ms) by MooseX::Types::Base::BEGIN@16 at line 16 of MooseX/Types/Base.pm # once (926µs+2.24ms) by MooseX::Types::BEGIN@20 at line 20 of MooseX/Types.pm # once (539µs+1.26ms) by MooseX::Types::Moose::BEGIN@16 at line 16 of MooseX/Types/Moose.pm # once (266µs+606µs) by MooseX::Types::CheckedUtilExports::BEGIN@18 at line 18 of MooseX/Types/CheckedUtilExports.pm # once (175µs+444µs) by namespace::autoclean::BEGIN@16 at line 16 of namespace/autoclean.pm
sub import {
68533µs my ($pragma, @args) = @_;
69
70514µs my (%args, $is_explicit);
71
72 ARG:
73525µs while (@args) {
74
754122µs439µs if ($args[0] =~ /^\-/) {
# spent 39µs making 4 calls to namespace::clean::CORE:match, avg 10µs/call
76416µs my $key = shift @args;
77411µs my $value = shift @args;
78424µs $args{ $key } = $value;
79 }
80 else {
81 $is_explicit++;
82 last ARG;
83 }
84 }
85
86540µs my $cleanee = exists $args{ -cleanee } ? $args{ -cleanee } : scalar caller;
87512µs if ($is_explicit) {
88 on_scope_end {
89 $RemoveSubs->($cleanee, {}, @args);
90 };
91 }
92 else {
93
94 # calling class, all current functions and our storage
955158µs53.97ms my $functions = $pragma->get_functions($cleanee);
# spent 3.97ms making 5 calls to namespace::clean::get_functions, avg 795µs/call
96581µs5916µs my $store = $pragma->get_class_store($cleanee);
# spent 916µs making 5 calls to namespace::clean::get_class_store, avg 183µs/call
975176µs565µs my $stash = Package::Stash->new($cleanee);
# spent 65µs making 5 calls to Package::Stash::XS::new, avg 13µs/call
98
99 # except parameter can be array ref or single value
100 my %except = map {( $_ => 1 )} (
101 $args{ -except }
102 ? ( ref $args{ -except } eq 'ARRAY' ? @{ $args{ -except } } : $args{ -except } )
103592µs : ()
104 );
105
106 # register symbols for removal, if they have a CODE entry
1075112µs for my $f (keys %$functions) {
10894242µs next if $except{ $f };
109923.55ms1842.90ms next unless $stash->has_symbol("&$f");
# spent 2.42ms making 92 calls to Package::Stash::XS::has_symbol, avg 26µs/call # spent 482µs making 92 calls to Package::Stash::XS::namespace, avg 5µs/call
11092783µs $store->{remove}{ $f } = 1;
111 }
112
113 # register EOF handler on first call to import
114527µs unless ($store->{handler_is_installed}) {
115
# spent 31.8ms (190µs+31.6) within namespace::clean::__ANON__[/home/doy/coding/src/namespace-clean/namespace-clean-0.18/blib/lib/namespace/clean.pm:117] which was called 5 times, avg 6.35ms/call: # 5 times (190µs+31.6ms) by B::Hooks::EndOfScope::__ANON__[/home/doy/perl5/perlbrew/perls/perl-5.10.1/lib/site_perl/5.10.1/B/Hooks/EndOfScope.pm:26] at line 26 of B/Hooks/EndOfScope.pm, avg 6.35ms/call
on_scope_end {
1165180µs531.6ms $RemoveSubs->($cleanee, $store, keys %{ $store->{remove} });
# spent 31.6ms making 5 calls to namespace::clean::__ANON__[namespace/clean.pm:59], avg 6.31ms/call
1175133µs5536µs };
# spent 536µs making 5 calls to B::Hooks::EndOfScope::on_scope_end, avg 107µs/call
118526µs $store->{handler_is_installed} = 1;
119 }
120
1215170µs return 1;
122 }
123}
124
125
126sub unimport {
127 my ($pragma, %args) = @_;
128
129 # the calling class, the current functions and our storage
130 my $cleanee = exists $args{ -cleanee } ? $args{ -cleanee } : scalar caller;
131 my $functions = $pragma->get_functions($cleanee);
132 my $store = $pragma->get_class_store($cleanee);
133
134 # register all unknown previous functions as excluded
135 for my $f (keys %$functions) {
136 next if $store->{remove}{ $f }
137 or $store->{exclude}{ $f };
138 $store->{exclude}{ $f } = 1;
139 }
140
141 return 1;
142}
143
144
145
# spent 916µs (388+528) within namespace::clean::get_class_store which was called 5 times, avg 183µs/call: # 5 times (388µs+528µs) by namespace::clean::import at line 96, avg 183µs/call
sub get_class_store {
146528µs my ($pragma, $class) = @_;
1475158µs572µs my $stash = Package::Stash->new($class);
# spent 72µs making 5 calls to Package::Stash::XS::new, avg 14µs/call
148526µs my $var = "%$STORAGE_VAR";
1495457µs20370µs $stash->add_symbol($var, {})
# spent 193µs making 5 calls to Package::Stash::XS::add_symbol, avg 39µs/call # spent 130µs making 5 calls to Package::Stash::XS::has_symbol, avg 26µs/call # spent 24µs making 5 calls to Package::Stash::XS::namespace, avg 5µs/call # spent 24µs making 5 calls to Package::Stash::XS::name, avg 5µs/call
150 unless $stash->has_symbol($var);
1515257µs10158µs return $stash->get_symbol($var);
# spent 134µs making 5 calls to Package::Stash::XS::get_symbol, avg 27µs/call # spent 24µs making 5 calls to Package::Stash::XS::namespace, avg 5µs/call
152}
153
154
155
# spent 3.97ms (1.41+2.56) within namespace::clean::get_functions which was called 5 times, avg 795µs/call: # 5 times (1.41ms+2.56ms) by namespace::clean::import at line 95, avg 795µs/call
sub get_functions {
156521µs my ($pragma, $class) = @_;
157
1585185µs5102µs my $stash = Package::Stash->new($class);
# spent 102µs making 5 calls to Package::Stash::XS::new, avg 20µs/call
159 return {
16053.80ms1982.96ms map { $_ => $stash->get_symbol("&$_") }
# spent 2.21ms making 94 calls to Package::Stash::XS::get_symbol, avg 24µs/call # spent 500µs making 99 calls to Package::Stash::XS::namespace, avg 5µs/call # spent 250µs making 5 calls to Package::Stash::XS::list_all_symbols, avg 50µs/call
161 $stash->list_all_symbols('CODE')
162 };
163}
164
165
1663119µs2208µs
# spent 132µs (56+76) within namespace::clean::BEGIN@166 which was called: # once (56µs+76µs) by MooseX::Types::Base::BEGIN@16 at line 166
no warnings;
# spent 132µs making 1 call to namespace::clean::BEGIN@166 # spent 76µs making 1 call to warnings::unimport
167113µs'Danger! Laws of Thermodynamics may not apply.'
168
169__END__
 
# spent 39µs within namespace::clean::CORE:match which was called 4 times, avg 10µs/call: # 4 times (39µs+0s) by namespace::clean::import at line 75, avg 10µs/call
sub namespace::clean::CORE:match; # opcode