← Index
NYTProf Performance Profile   « block view • line view • sub view »
For -e
  Run on Wed Nov 17 21:45:08 2010
Reported on Wed Nov 17 22:11:20 2010

Filename/home/doy/perl5/perlbrew/perls/perl-5.10.1/lib/site_perl/5.10.1/namespace/clean.pm
StatementsExecuted 6581 statements in 81.4ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
542187.1ms746msnamespace::clean::::__ANON__[:52]namespace::clean::__ANON__[:52]
5553.15ms24.1msnamespace::clean::::importnamespace::clean::import
49112.13ms667msnamespace::clean::::clean_subroutinesnamespace::clean::clean_subroutines
1111.79ms3.10msnamespace::clean::::BEGIN@15namespace::clean::BEGIN@15
5111.73ms9.82msnamespace::clean::::get_functionsnamespace::clean::get_functions
1111.66ms9.05msnamespace::clean::::BEGIN@17namespace::clean::BEGIN@17
511402µs2.11msnamespace::clean::::get_class_storenamespace::clean::get_class_store
511186µs81.3msnamespace::clean::::__ANON__[:110]namespace::clean::__ANON__[:110]
11175µs387µsnamespace::clean::::BEGIN@14namespace::clean::BEGIN@14
11159µs137µsnamespace::clean::::BEGIN@159namespace::clean::BEGIN@159
11153µs104µsnamespace::clean::::BEGIN@16namespace::clean::BEGIN@16
11146µs46µsnamespace::clean::::BEGIN@2namespace::clean::BEGIN@2
11141µs111µsnamespace::clean::::BEGIN@10namespace::clean::BEGIN@10
41137µs37µsnamespace::clean::::CORE:matchnamespace::clean::CORE:match (opcode)
11136µs52µsnamespace::clean::::BEGIN@11namespace::clean::BEGIN@11
11135µs149µsnamespace::clean::::BEGIN@13namespace::clean::BEGIN@13
11116µs16µsnamespace::clean::::BEGIN@5namespace::clean::BEGIN@5
0000s0snamespace::clean::::__ANON__[:83]namespace::clean::__ANON__[:83]
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 46µs within namespace::clean::BEGIN@2 which was called: # once (46µs+0s) by MooseX::Types::Base::BEGIN@16 at line 4
BEGIN {
3126µs $namespace::clean::AUTHORITY = 'cpan:PHAYLON';
4186µs146µs}
# spent 46µs making 1 call to namespace::clean::BEGIN@2
5
# spent 16µs within namespace::clean::BEGIN@5 which was called: # once (16µs+0s) by MooseX::Types::Base::BEGIN@16 at line 7
BEGIN {
6117µs $namespace::clean::VERSION = '0.18';
7179µs116µs}
# spent 16µs making 1 call to namespace::clean::BEGIN@5
8# ABSTRACT: Keep imports and functions out of your namespace
9
10398µs2182µs
# spent 111µs (41+71) within namespace::clean::BEGIN@10 which was called: # once (41µs+71µs) by MooseX::Types::Base::BEGIN@16 at line 10
use warnings;
# spent 111µs making 1 call to namespace::clean::BEGIN@10 # spent 70µs making 1 call to warnings::import
113101µs267µs
# spent 52µs (36+15) within namespace::clean::BEGIN@11 which was called: # once (36µs+15µs) by MooseX::Types::Base::BEGIN@16 at line 11
use strict;
# spent 52µs making 1 call to namespace::clean::BEGIN@11 # spent 15µs making 1 call to strict::import
12
133111µs2264µs
# spent 149µs (35+114) within namespace::clean::BEGIN@13 which was called: # once (35µs+114µ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 114µs making 1 call to vars::import
143295µs3700µs
# spent 387µs (75+312) within namespace::clean::BEGIN@14 which was called: # once (75µs+312µs) by MooseX::Types::Base::BEGIN@16 at line 14
use Sub::Name 0.04 qw(subname);
# spent 387µs making 1 call to namespace::clean::BEGIN@14 # spent 188µs making 1 call to Exporter::import # spent 124µs making 1 call to UNIVERSAL::VERSION
153551µs33.41ms
# spent 3.10ms (1.79+1.31) within namespace::clean::BEGIN@15 which was called: # once (1.79ms+1.31ms) by MooseX::Types::Base::BEGIN@16 at line 15
use Sub::Identify 0.04 qw(sub_fullname);
# spent 3.10ms making 1 call to namespace::clean::BEGIN@15 # spent 256µs making 1 call to Exporter::import # spent 55µs making 1 call to UNIVERSAL::VERSION
163177µs2156µs
# spent 104µs (53+52) within namespace::clean::BEGIN@16 which was called: # once (53µs+52µs) by MooseX::Types::Base::BEGIN@16 at line 16
use Package::Stash 0.03;
# spent 104µs making 1 call to namespace::clean::BEGIN@16 # spent 52µs making 1 call to UNIVERSAL::VERSION
1733.08ms310.2ms
# spent 9.05ms (1.66+7.39) within namespace::clean::BEGIN@17 which was called: # once (1.66ms+7.39ms) by MooseX::Types::Base::BEGIN@16 at line 17
use B::Hooks::EndOfScope 0.07;
# spent 9.05ms making 1 call to namespace::clean::BEGIN@17 # spent 1.10ms 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 746ms (87.1+659) within namespace::clean::__ANON__[/home/doy/perl5/perlbrew/perls/perl-5.10.1/lib/site_perl/5.10.1/namespace/clean.pm:52] which was called 54 times, avg 13.8ms/call: # 49 times (77.7ms+588ms) by namespace::clean::clean_subroutines at line 56, avg 13.6ms/call # 5 times (9.44ms+71.7ms) by namespace::clean::__ANON__[/home/doy/perl5/perlbrew/perls/perl-5.10.1/lib/site_perl/5.10.1/namespace/clean.pm:110] at line 109, avg 16.2ms/call
my $RemoveSubs = sub {
23
242703.17ms my $cleanee = shift;
25 my $store = shift;
26542.35ms my $cleanee_stash = Package::Stash->new($cleanee);
# spent 2.35ms making 54 calls to Package::Stash::new, avg 44µs/call
27542.51ms my $deleted_stash = Package::Stash->new("namespace::clean::deleted::$cleanee");
# spent 2.51ms making 54 calls to Package::Stash::new, avg 46µs/call
28 SYMBOL:
29 for my $f (@_) {
30412540.2ms my $variable = "&$f";
31 # ignore already removed symbols
32 next SYMBOL if $store->{exclude}{ $f };
33
3482582.2ms next SYMBOL unless $cleanee_stash->has_package_symbol($variable);
# spent 82.2ms making 825 calls to Package::Stash::has_package_symbol, avg 100µs/call
35
36165026.3ms8257.31ms if (ref(\$cleanee_stash->namespace->{$f}) eq 'GLOB') {
# spent 7.31ms making 825 calls to Package::Stash::namespace, avg 9µ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.
4282565.7ms my $sub = $cleanee_stash->get_package_symbol($variable);
# spent 65.7ms making 825 calls to Package::Stash::get_package_symbol, avg 80µs/call
43165030.0ms if ( sub_fullname($sub) eq ($cleanee_stash->name . "::$f") ) {
# spent 21.8ms making 825 calls to Sub::Identify::sub_fullname, avg 26µs/call # spent 8.28ms making 825 calls to Package::Stash::name, avg 10µs/call
44 my $new_fq = $deleted_stash->name . "::$f";
45 subname($new_fq, $sub);
46 $deleted_stash->add_package_symbol($variable, $sub);
47 }
48 }
49
50825469ms $cleanee_stash->remove_package_symbol($variable);
# spent 469ms making 825 calls to Package::Stash::remove_package_symbol, avg 569µs/call
51 }
52116µs};
53
54
# spent 667ms (2.13+665) within namespace::clean::clean_subroutines which was called 49 times, avg 13.6ms/call: # 49 times (2.13ms+665ms) 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 13.6ms/call
sub clean_subroutines {
55982.05ms my ($nc, $cleanee, @subs) = @_;
5649665ms $RemoveSubs->($cleanee, {}, @subs);
# spent 665ms making 49 calls to namespace::clean::__ANON__[namespace/clean.pm:52], avg 13.6ms/call
57}
58
59
60
# spent 24.1ms (3.15+21.0) within namespace::clean::import which was called 5 times, avg 4.82ms/call: # once (1.00ms+7.37ms) by MooseX::Types::BEGIN@20 at line 20 of MooseX/Types.pm # once (1.09ms+7.15ms) by MooseX::Types::Base::BEGIN@16 at line 16 of MooseX/Types/Base.pm # once (593µs+3.83ms) by MooseX::Types::Moose::BEGIN@16 at line 16 of MooseX/Types/Moose.pm # once (284µs+1.46ms) by MooseX::Types::CheckedUtilExports::BEGIN@18 at line 18 of MooseX/Types/CheckedUtilExports.pm # once (186µs+1.14ms) by namespace::autoclean::BEGIN@16 at line 16 of namespace/autoclean.pm
sub import {
6125124µs my ($pragma, @args) = @_;
62
63 my (%args, $is_explicit);
64
65 ARG:
66 while (@args) {
67
6816180µs437µs if ($args[0] =~ /^\-/) {
# spent 37µs making 4 calls to namespace::clean::CORE:match, avg 9µs/call
69 my $key = shift @args;
70 my $value = shift @args;
71 $args{ $key } = $value;
72 }
73 else {
74 $is_explicit++;
75 last ARG;
76 }
77 }
78
79 my $cleanee = exists $args{ -cleanee } ? $args{ -cleanee } : scalar caller;
8035627µs if ($is_explicit) {
81 on_scope_end {
82 $RemoveSubs->($cleanee, {}, @args);
83 };
84 }
85 else {
86
87 # calling class, all current functions and our storage
8859.82ms my $functions = $pragma->get_functions($cleanee);
# spent 9.82ms making 5 calls to namespace::clean::get_functions, avg 1.96ms/call
8952.11ms my $store = $pragma->get_class_store($cleanee);
# spent 2.11ms making 5 calls to namespace::clean::get_class_store, avg 423µs/call
905161µs my $stash = Package::Stash->new($cleanee);
# spent 161µs making 5 calls to Package::Stash::new, avg 32µs/call
91
92 # except parameter can be array ref or single value
93 my %except = map {( $_ => 1 )} (
94 $args{ -except }
95 ? ( ref $args{ -except } eq 'ARRAY' ? @{ $args{ -except } } : $args{ -except } )
96 : ()
97 );
98
99 # register symbols for removal, if they have a CODE entry
100 for my $f (keys %$functions) {
1012781.94ms next if $except{ $f };
102928.36ms next unless $stash->has_package_symbol("&$f");
# spent 8.36ms making 92 calls to Package::Stash::has_package_symbol, avg 91µs/call
103 $store->{remove}{ $f } = 1;
104 }
105
106 # register EOF handler on first call to import
10710151µs unless ($store->{handler_is_installed}) {
108
# spent 81.3ms (186µs+81.1) within namespace::clean::__ANON__[/home/doy/perl5/perlbrew/perls/perl-5.10.1/lib/site_perl/5.10.1/namespace/clean.pm:110] which was called 5 times, avg 16.3ms/call: # 5 times (186µs+81.1ms) 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 16.3ms/call
on_scope_end {
1095182µs581.1ms $RemoveSubs->($cleanee, $store, keys %{ $store->{remove} });
# spent 81.1ms making 5 calls to namespace::clean::__ANON__[namespace/clean.pm:52], avg 16.2ms/call
1105465µs };
# spent 465µs making 5 calls to B::Hooks::EndOfScope::on_scope_end, avg 93µs/call
111 $store->{handler_is_installed} = 1;
112 }
113
114 return 1;
115 }
116}
117
118
119sub unimport {
120 my ($pragma, %args) = @_;
121
122 # the calling class, the current functions and our storage
123 my $cleanee = exists $args{ -cleanee } ? $args{ -cleanee } : scalar caller;
124 my $functions = $pragma->get_functions($cleanee);
125 my $store = $pragma->get_class_store($cleanee);
126
127 # register all unknown previous functions as excluded
128 for my $f (keys %$functions) {
129 next if $store->{remove}{ $f }
130 or $store->{exclude}{ $f };
131 $store->{exclude}{ $f } = 1;
132 }
133
134 return 1;
135}
136
137
138
# spent 2.11ms (402µs+1.71) within namespace::clean::get_class_store which was called 5 times, avg 423µs/call: # 5 times (402µs+1.71ms) by namespace::clean::import at line 89, avg 423µs/call
sub get_class_store {
13925321µs my ($pragma, $class) = @_;
1405171µs my $stash = Package::Stash->new($class);
# spent 171µs making 5 calls to Package::Stash::new, avg 34µs/call
141 my $var = "%$STORAGE_VAR";
142101.15ms $stash->add_package_symbol($var, {})
# spent 759µs making 5 calls to Package::Stash::add_package_symbol, avg 152µs/call # spent 388µs making 5 calls to Package::Stash::has_package_symbol, avg 78µs/call
143 unless $stash->has_package_symbol($var);
1445394µs return $stash->get_package_symbol($var);
# spent 394µs making 5 calls to Package::Stash::get_package_symbol, avg 79µs/call
145}
146
147
148
# spent 9.82ms (1.73+8.08) within namespace::clean::get_functions which was called 5 times, avg 1.96ms/call: # 5 times (1.73ms+8.08ms) by namespace::clean::import at line 88, avg 1.96ms/call
sub get_functions {
149151.43ms my ($pragma, $class) = @_;
150
1515220µs my $stash = Package::Stash->new($class);
# spent 220µs making 5 calls to Package::Stash::new, avg 44µs/call
152 return {
153997.86ms map { $_ => $stash->get_package_symbol("&$_") }
# spent 7.21ms making 94 calls to Package::Stash::get_package_symbol, avg 77µs/call # spent 650µs making 5 calls to Package::Stash::list_all_package_symbols, avg 130µs/call
154 $stash->list_all_package_symbols('CODE')
155 };
156}
157
158
1593110µs2215µs
# spent 137µs (59+78) within namespace::clean::BEGIN@159 which was called: # once (59µs+78µs) by MooseX::Types::Base::BEGIN@16 at line 159
no warnings;
# spent 137µs making 1 call to namespace::clean::BEGIN@159 # spent 78µs making 1 call to warnings::unimport
160113µs'Danger! Laws of Thermodynamics may not apply.'
161
162__END__
 
# spent 37µs within namespace::clean::CORE:match which was called 4 times, avg 9µs/call: # 4 times (37µs+0s) by namespace::clean::import at line 68, avg 9µs/call
sub namespace::clean::CORE:match; # opcode