← Index
NYTProf Performance Profile   « block view • line view • sub view »
For -e
  Run on Wed Nov 17 21:39:01 2010
Reported on Wed Nov 17 22:05:48 2010

Filename/home/doy/perl5/perlbrew/perls/perl-5.10.1/lib/site_perl/5.10.1/namespace/clean.pm
StatementsExecuted 8340 statements in 103ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
461172.5ms623msnamespace::clean::::__ANON__[:52] namespace::clean::__ANON__[:52]
46464625.7ms192msnamespace::clean::::import namespace::clean::import
461113.4ms76.7msnamespace::clean::::get_functions namespace::clean::get_functions
46113.54ms20.4msnamespace::clean::::get_class_store namespace::clean::get_class_store
1111.76ms3.11msnamespace::clean::::BEGIN@15 namespace::clean::BEGIN@15
46111.71ms625msnamespace::clean::::__ANON__[:110] namespace::clean::__ANON__[:110]
1111.54ms8.96msnamespace::clean::::BEGIN@17 namespace::clean::BEGIN@17
4611504µs504µsnamespace::clean::::CORE:match namespace::clean::CORE:match (opcode)
11175µs352µsnamespace::clean::::BEGIN@14 namespace::clean::BEGIN@14
11171µs144µsnamespace::clean::::BEGIN@10 namespace::clean::BEGIN@10
11157µs134µsnamespace::clean::::BEGIN@159 namespace::clean::BEGIN@159
11153µs104µsnamespace::clean::::BEGIN@16 namespace::clean::BEGIN@16
11145µs45µsnamespace::clean::::BEGIN@2 namespace::clean::BEGIN@2
11137µs52µsnamespace::clean::::BEGIN@11 namespace::clean::BEGIN@11
11135µs147µsnamespace::clean::::BEGIN@13 namespace::clean::BEGIN@13
11116µs16µsnamespace::clean::::BEGIN@5 namespace::clean::BEGIN@5
0000s0snamespace::clean::::__ANON__[:83] namespace::clean::__ANON__[:83]
0000s0snamespace::clean::::clean_subroutines namespace::clean::clean_subroutines
0000s0snamespace::clean::deleted::KiokuDB::TypeMap::Entry::MOP::::does_rolenamespace::clean::deleted::KiokuDB::TypeMap::Entry::MOP::does_role
0000s0snamespace::clean::::unimport namespace::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 45µs within namespace::clean::BEGIN@2 which was called: # once (45µs+0s) by KiokuDB::Backend::BEGIN@9 at line 4
BEGIN {
3126µs $namespace::clean::AUTHORITY = 'cpan:PHAYLON';
4184µs145µs}
# spent 45µ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 KiokuDB::Backend::BEGIN@9 at line 7
BEGIN {
6118µs $namespace::clean::VERSION = '0.18';
7177µs116µs}
# spent 16µs making 1 call to namespace::clean::BEGIN@5
8# ABSTRACT: Keep imports and functions out of your namespace
9
10399µs2216µs
# spent 144µs (71+72) within namespace::clean::BEGIN@10 which was called: # once (71µs+72µs) by KiokuDB::Backend::BEGIN@9 at line 10
use warnings;
# spent 144µs making 1 call to namespace::clean::BEGIN@10 # spent 72µs making 1 call to warnings::import
113101µs268µs
# spent 52µs (37+15) within namespace::clean::BEGIN@11 which was called: # once (37µs+15µs) by KiokuDB::Backend::BEGIN@9 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
133108µs2260µs
# spent 147µs (35+112) within namespace::clean::BEGIN@13 which was called: # once (35µs+112µs) by KiokuDB::Backend::BEGIN@9 at line 13
use vars qw( $STORAGE_VAR );
# spent 147µs making 1 call to namespace::clean::BEGIN@13 # spent 113µs making 1 call to vars::import
143301µs3628µs
# spent 352µs (75+277) within namespace::clean::BEGIN@14 which was called: # once (75µs+277µs) by KiokuDB::Backend::BEGIN@9 at line 14
use Sub::Name 0.04 qw(subname);
# spent 352µs making 1 call to namespace::clean::BEGIN@14 # spent 152µs making 1 call to Exporter::import # spent 125µs making 1 call to UNIVERSAL::VERSION
153551µs33.43ms
# spent 3.11ms (1.76+1.34) within namespace::clean::BEGIN@15 which was called: # once (1.76ms+1.34ms) by KiokuDB::Backend::BEGIN@9 at line 15
use Sub::Identify 0.04 qw(sub_fullname);
# spent 3.11ms making 1 call to namespace::clean::BEGIN@15 # spent 243µs making 1 call to Exporter::import # spent 75µs making 1 call to UNIVERSAL::VERSION
163175µs2155µs
# spent 104µs (53+51) within namespace::clean::BEGIN@16 which was called: # once (53µs+51µs) by KiokuDB::Backend::BEGIN@9 at line 16
use Package::Stash 0.03;
# spent 104µs making 1 call to namespace::clean::BEGIN@16 # spent 51µs making 1 call to UNIVERSAL::VERSION
1733.04ms310.1ms
# spent 8.96ms (1.54+7.42) within namespace::clean::BEGIN@17 which was called: # once (1.54ms+7.42ms) by KiokuDB::Backend::BEGIN@9 at line 17
use B::Hooks::EndOfScope 0.07;
# spent 8.96ms making 1 call to namespace::clean::BEGIN@17 # spent 1.13ms making 1 call to Sub::Exporter::__ANON__[Sub/Exporter.pm:756] # spent 57µs making 1 call to UNIVERSAL::VERSION
18
1914µs$STORAGE_VAR = '__NAMESPACE_CLEAN_STORAGE';
20
21
22
# spent 623ms (72.5+551) 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 46 times, avg 13.5ms/call: # 46 times (72.5ms+551ms) 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 13.5ms/call
my $RemoveSubs = sub {
23
242302.82ms my $cleanee = shift;
25 my $store = shift;
26462.20ms my $cleanee_stash = Package::Stash->new($cleanee);
# spent 2.20ms making 46 calls to Package::Stash::new, avg 48µs/call
27462.12ms my $deleted_stash = Package::Stash->new("namespace::clean::deleted::$cleanee");
# spent 2.12ms making 46 calls to Package::Stash::new, avg 46µs/call
28 SYMBOL:
29 for my $f (@_) {
30339532.9ms my $variable = "&$f";
31 # ignore already removed symbols
32 next SYMBOL if $store->{exclude}{ $f };
33
3467966.8ms next SYMBOL unless $cleanee_stash->has_package_symbol($variable);
# spent 66.8ms making 679 calls to Package::Stash::has_package_symbol, avg 98µs/call
35
36135822.4ms6795.98ms if (ref(\$cleanee_stash->namespace->{$f}) eq 'GLOB') {
# spent 5.98ms making 679 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.
4267956.5ms my $sub = $cleanee_stash->get_package_symbol($variable);
# spent 56.5ms making 679 calls to Package::Stash::get_package_symbol, avg 83µs/call
43366µs135825.0ms if ( sub_fullname($sub) eq ($cleanee_stash->name . "::$f") ) {
# spent 18.2ms making 679 calls to Sub::Identify::sub_fullname, avg 27µs/call # spent 6.82ms making 679 calls to Package::Stash::name, avg 10µs/call
4419µs my $new_fq = $deleted_stash->name . "::$f";
# spent 9µs making 1 call to Package::Stash::name
45122µs subname($new_fq, $sub);
# spent 22µs making 1 call to Sub::Name::subname
461167µs $deleted_stash->add_package_symbol($variable, $sub);
# spent 167µs making 1 call to Package::Stash::add_package_symbol
47 }
48 }
49
50679392ms $cleanee_stash->remove_package_symbol($variable);
# spent 392ms making 679 calls to Package::Stash::remove_package_symbol, avg 577µs/call
51 }
52115µs};
53
54sub clean_subroutines {
55 my ($nc, $cleanee, @subs) = @_;
56 $RemoveSubs->($cleanee, {}, @subs);
57}
58
59
60
# spent 192ms (25.7+167) within namespace::clean::import which was called 46 times, avg 4.18ms/call: # once (1.02ms+7.08ms) by KiokuDB::Backend::BEGIN@9 at line 9 of KiokuDB/Backend.pm # once (1.04ms+7.00ms) by KiokuDB::LiveObjects::BEGIN@18 at line 18 of KiokuDB/LiveObjects.pm # once (923µs+6.22ms) by KiokuDB::Entry::BEGIN@8 at line 8 of KiokuDB/Entry.pm # once (761µs+5.10ms) by KiokuDB::TypeMap::Entry::Std::Intrinsic::BEGIN@6 at line 6 of KiokuDB/TypeMap/Entry/Std/Intrinsic.pm # once (664µs+4.23ms) by KiokuDB::Collapser::BEGIN@22 at line 22 of KiokuDB/Collapser.pm # once (617µs+4.18ms) by KiokuDB::BEGIN@23 at line 23 of KiokuDB.pm # once (588µs+4.04ms) by KiokuDB::Role::UUIDs::LibUUID::BEGIN@8 at line 8 of KiokuDB/Role/UUIDs/LibUUID.pm # once (576µs+3.98ms) by Data::Visitor::BEGIN@14 at line 14 of Data/Visitor.pm # once (599µs+3.94ms) by KiokuDB::Role::UUIDs::BEGIN@8 at line 8 of KiokuDB/Role/UUIDs.pm # once (603µs+3.92ms) by KiokuDB::Linker::BEGIN@20 at line 20 of KiokuDB/Linker.pm # once (588µs+3.84ms) by KiokuDB::TypeMap::Entry::Std::ID::BEGIN@4 at line 4 of KiokuDB/TypeMap/Entry/Std/ID.pm # once (574µs+3.78ms) by KiokuDB::TypeMap::BEGIN@12 at line 12 of KiokuDB/TypeMap.pm # once (559µs+3.61ms) by MooseX::Clone::Meta::Attribute::Trait::StrableClone::BEGIN@8 at line 8 of MooseX/Clone/Meta/Attribute/Trait/StorableClone.pm # once (550µs+3.59ms) by MooseX::Clone::Meta::Attribute::Trait::Copy::BEGIN@8 at line 8 of MooseX/Clone/Meta/Attribute/Trait/Copy.pm # once (550µs+3.59ms) by KiokuDB::TypeMap::Entry::MOP::BEGIN@19 at line 19 of KiokuDB/TypeMap/Entry/MOP.pm # once (543µs+3.58ms) by MooseX::Clone::Meta::Attribute::Trait::Clone::BEGIN@8 at line 8 of MooseX/Clone/Meta/Attribute/Trait/Clone.pm # once (546µs+3.52ms) by MooseX::Clone::BEGIN@15 at line 15 of MooseX/Clone.pm # once (569µs+3.48ms) by Devel::PartialDump::BEGIN@9 at line 9 of Devel/PartialDump.pm # once (550µs+3.47ms) by KiokuDB::Role::TypeMap::BEGIN@6 at line 6 of KiokuDB/Role/TypeMap.pm # once (525µs+3.49ms) by KiokuDB::TypeMap::Entry::Std::Compile::BEGIN@6 at line 6 of KiokuDB/TypeMap/Entry/Std/Compile.pm # once (522µs+3.48ms) by KiokuDB::Role::API::BEGIN@4 at line 4 of KiokuDB/Role/API.pm # once (529µs+3.46ms) by Data::Stream::Bulk::BEGIN@12 at line 12 of Data/Stream/Bulk.pm # once (569µs+3.41ms) by KiokuDB::TypeMap::Entry::Std::Expand::BEGIN@6 at line 6 of KiokuDB/TypeMap/Entry/Std/Expand.pm # once (545µs+3.43ms) by KiokuDB::TypeMap::Entry::Std::BEGIN@8 at line 8 of KiokuDB/TypeMap/Entry/Std.pm # once (525µs+3.44ms) by KiokuDB::Error::BEGIN@4 at line 4 of KiokuDB/Error.pm # once (523µs+3.39ms) by MooseX::Clone::Meta::Attribute::Trait::Clone::Base::BEGIN@6 at line 6 of MooseX/Clone/Meta/Attribute/Trait/Clone/Base.pm # once (523µs+3.39ms) by KiokuDB::TypeMap::Entry::BEGIN@6 at line 6 of KiokuDB/TypeMap/Entry.pm # once (522µs+3.34ms) by MooseX::Clone::Meta::Attribute::Trait::NoClone::BEGIN@6 at line 6 of MooseX/Clone/Meta/Attribute/Trait/NoClone.pm # once (522µs+3.33ms) by MooseX::Clone::Meta::Attribute::Trait::Clone::Std::BEGIN@4 at line 4 of MooseX/Clone/Meta/Attribute/Trait/Clone/Std.pm # once (501µs+3.23ms) by KiokuDB::TypeMap::Resolver::BEGIN@11 at line 11 of KiokuDB/TypeMap/Resolver.pm # once (514µs+3.20ms) by KiokuDB::Collapser::Buffer::BEGIN@7 at line 7 of KiokuDB/Collapser/Buffer.pm # once (511µs+3.18ms) by KiokuDB::LiveObjects::TXNScope::BEGIN@8 at line 8 of KiokuDB/LiveObjects/TXNScope.pm # once (506µs+3.10ms) by KiokuDB::TypeMap::Shadow::BEGIN@6 at line 6 of KiokuDB/TypeMap/Shadow.pm # once (480µs+3.12ms) by KiokuDB::LiveObjects::Scope::BEGIN@6 at line 6 of KiokuDB/LiveObjects/Scope.pm # once (479µs+3.10ms) by Data::Stream::Bulk::Cat::BEGIN@12 at line 12 of Data/Stream/Bulk/Cat.pm # once (480µs+3.10ms) by KiokuDB::TypeMap::Entry::Compiled::BEGIN@6 at line 6 of KiokuDB/TypeMap/Entry/Compiled.pm # once (474µs+3.10ms) by KiokuDB::Error::UnknownObjects::BEGIN@4 at line 4 of KiokuDB/Error/UnknownObjects.pm # once (480µs+3.06ms) by KiokuDB::Reference::BEGIN@6 at line 6 of KiokuDB/Reference.pm # once (491µs+3.04ms) by Data::Stream::Bulk::Filter::BEGIN@14 at line 14 of Data/Stream/Bulk/Filter.pm # once (484µs+3.03ms) by KiokuDB::Stream::Objects::BEGIN@6 at line 6 of KiokuDB/Stream/Objects.pm # once (473µs+3.04ms) by KiokuDB::TypeMap::Entry::Alias::BEGIN@6 at line 6 of KiokuDB/TypeMap/Entry/Alias.pm # once (473µs+3.03ms) by KiokuDB::Entry::Skip::BEGIN@6 at line 6 of KiokuDB/Entry/Skip.pm # once (468µs+3.03ms) by KiokuDB::Thunk::BEGIN@6 at line 6 of KiokuDB/Thunk.pm # once (489µs+3.01ms) by Data::Stream::Bulk::Nil::BEGIN@12 at line 12 of Data/Stream/Bulk/Nil.pm # once (473µs+3.01ms) by KiokuDB::Error::MissingObjects::BEGIN@4 at line 4 of KiokuDB/Error/MissingObjects.pm # once (202µs+919µs) by KiokuDB::LiveObjects::Guard::BEGIN@8 at line 8 of KiokuDB/LiveObjects/Guard.pm
sub import {
612301.15ms my ($pragma, @args) = @_;
62
63 my (%args, $is_explicit);
64
65 ARG:
66 while (@args) {
67
681842.06ms46504µs if ($args[0] =~ /^\-/) {
# spent 504µs making 46 calls to namespace::clean::CORE:match, avg 11µ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;
803225.67ms 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
884676.7ms my $functions = $pragma->get_functions($cleanee);
# spent 76.7ms making 46 calls to namespace::clean::get_functions, avg 1.67ms/call
894620.4ms my $store = $pragma->get_class_store($cleanee);
# spent 20.4ms making 46 calls to namespace::clean::get_class_store, avg 443µs/call
90461.54ms my $stash = Package::Stash->new($cleanee);
# spent 1.54ms making 46 calls to Package::Stash::new, avg 34µ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) {
101208314.6ms next if $except{ $f };
10267963.2ms next unless $stash->has_package_symbol("&$f");
# spent 63.2ms making 679 calls to Package::Stash::has_package_symbol, avg 93µs/call
103 $store->{remove}{ $f } = 1;
104 }
105
106 # register EOF handler on first call to import
107921.27ms unless ($store->{handler_is_installed}) {
108
# spent 625ms (1.71+623) 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 46 times, avg 13.6ms/call: # 46 times (1.71ms+623ms) 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 13.6ms/call
on_scope_end {
109461.74ms46623ms $RemoveSubs->($cleanee, $store, keys %{ $store->{remove} });
# spent 623ms making 46 calls to namespace::clean::__ANON__[namespace/clean.pm:52], avg 13.5ms/call
110464.21ms };
# spent 4.21ms making 46 calls to B::Hooks::EndOfScope::on_scope_end, avg 92µ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 20.4ms (3.54+16.9) within namespace::clean::get_class_store which was called 46 times, avg 443µs/call: # 46 times (3.54ms+16.9ms) by namespace::clean::import at line 89, avg 443µs/call
sub get_class_store {
1392303.00ms my ($pragma, $class) = @_;
140461.70ms my $stash = Package::Stash->new($class);
# spent 1.70ms making 46 calls to Package::Stash::new, avg 37µs/call
141 my $var = "%$STORAGE_VAR";
1429211.2ms $stash->add_package_symbol($var, {})
# spent 7.60ms making 46 calls to Package::Stash::add_package_symbol, avg 165µs/call # spent 3.62ms making 46 calls to Package::Stash::has_package_symbol, avg 79µs/call
143 unless $stash->has_package_symbol($var);
144463.94ms return $stash->get_package_symbol($var);
# spent 3.94ms making 46 calls to Package::Stash::get_package_symbol, avg 86µs/call
145}
146
147
148
# spent 76.7ms (13.4+63.3) within namespace::clean::get_functions which was called 46 times, avg 1.67ms/call: # 46 times (13.4ms+63.3ms) by namespace::clean::import at line 88, avg 1.67ms/call
sub get_functions {
14913811.0ms my ($pragma, $class) = @_;
150
151462.06ms my $stash = Package::Stash->new($class);
# spent 2.06ms making 46 calls to Package::Stash::new, avg 45µs/call
152 return {
15377161.3ms map { $_ => $stash->get_package_symbol("&$_") }
# spent 56.5ms making 725 calls to Package::Stash::get_package_symbol, avg 78µs/call # spent 4.82ms making 46 calls to Package::Stash::list_all_package_symbols, avg 105µs/call
154 $stash->list_all_package_symbols('CODE')
155 };
156}
157
158
1593106µs2210µs
# spent 134µs (57+77) within namespace::clean::BEGIN@159 which was called: # once (57µs+77µs) by KiokuDB::Backend::BEGIN@9 at line 159
no warnings;
# spent 134µs making 1 call to namespace::clean::BEGIN@159 # spent 77µs making 1 call to warnings::unimport
160113µs'Danger! Laws of Thermodynamics may not apply.'
161
162__END__
 
# spent 504µs within namespace::clean::CORE:match which was called 46 times, avg 11µs/call: # 46 times (504µs+0s) by namespace::clean::import at line 68, avg 11µs/call
sub namespace::clean::CORE:match; # opcode