← Index
NYTProf Performance Profile   « block view • line view • sub view »
For reply.pl
  Run on Thu Oct 21 22:40:13 2010
Reported on Thu Oct 21 22:44:40 2010

Filename/home/hinrik/perl5/perlbrew/perls/perl-5.13.5/lib/site_perl/5.13.5/namespace/clean.pm
StatementsExecuted 1286 statements in 6.47ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
7113.74ms30.6msnamespace::clean::::__ANON__[:52]namespace::clean::__ANON__[:52]
1111.39ms1.75msnamespace::clean::::BEGIN@16namespace::clean::BEGIN@16
7771.34ms9.78msnamespace::clean::::importnamespace::clean::import
711569µs3.88msnamespace::clean::::get_functionsnamespace::clean::get_functions
111426µs798µsnamespace::clean::::BEGIN@15namespace::clean::BEGIN@15
111393µs10.8msnamespace::clean::::BEGIN@17namespace::clean::BEGIN@17
111273µs4.32msnamespace::clean::::BEGIN@14namespace::clean::BEGIN@14
711179µs1.01msnamespace::clean::::get_class_storenamespace::clean::get_class_store
71172µs30.6msnamespace::clean::::__ANON__[:110]namespace::clean::__ANON__[:110]
11119µs19µsnamespace::clean::::BEGIN@2namespace::clean::BEGIN@2
71118µs18µsnamespace::clean::::CORE:matchnamespace::clean::CORE:match (opcode)
11114µs40µsnamespace::clean::::BEGIN@159namespace::clean::BEGIN@159
11111µs51µsnamespace::clean::::BEGIN@13namespace::clean::BEGIN@13
11110µs20µsnamespace::clean::::BEGIN@10namespace::clean::BEGIN@10
11110µs15µsnamespace::clean::::BEGIN@11namespace::clean::BEGIN@11
1114µs4µsnamespace::clean::::BEGIN@5namespace::clean::BEGIN@5
0000s0snamespace::clean::::__ANON__[:83]namespace::clean::__ANON__[:83]
0000s0snamespace::clean::::clean_subroutinesnamespace::clean::clean_subroutines
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 19µs within namespace::clean::BEGIN@2 which was called: # once (19µs+0s) by Hailo::BEGIN@15 at line 4
BEGIN {
316µs $namespace::clean::AUTHORITY = 'cpan:PHAYLON';
4121µs119µs}
# spent 19µs making 1 call to namespace::clean::BEGIN@2
5
# spent 4µs within namespace::clean::BEGIN@5 which was called: # once (4µs+0s) by Hailo::BEGIN@15 at line 7
BEGIN {
615µs $namespace::clean::VERSION = '0.18';
7116µs14µs}
# spent 4µs making 1 call to namespace::clean::BEGIN@5
8# ABSTRACT: Keep imports and functions out of your namespace
9
10223µs228µs
# spent 20µs (10+9) within namespace::clean::BEGIN@10 which was called: # once (10µs+9µs) by Hailo::BEGIN@15 at line 10
use warnings;
# spent 20µs making 1 call to namespace::clean::BEGIN@10 # spent 9µs making 1 call to warnings::import
11226µs220µs
# spent 15µs (10+5) within namespace::clean::BEGIN@11 which was called: # once (10µs+5µs) by Hailo::BEGIN@15 at line 11
use strict;
# spent 15µs making 1 call to namespace::clean::BEGIN@11 # spent 5µs making 1 call to strict::import
12
13232µs291µs
# spent 51µs (11+40) within namespace::clean::BEGIN@13 which was called: # once (11µs+40µs) by Hailo::BEGIN@15 at line 13
use vars qw( $STORAGE_VAR );
# spent 51µs making 1 call to namespace::clean::BEGIN@13 # spent 40µs making 1 call to vars::import
143172µs34.40ms
# spent 4.32ms (273µs+4.05) within namespace::clean::BEGIN@14 which was called: # once (273µs+4.05ms) by Hailo::BEGIN@15 at line 14
use Sub::Name 0.04 qw(subname);
# spent 4.32ms making 1 call to namespace::clean::BEGIN@14 # spent 63µs making 1 call to Exporter::import # spent 13µs making 1 call to UNIVERSAL::VERSION
153137µs3875µs
# spent 798µs (426+371) within namespace::clean::BEGIN@15 which was called: # once (426µs+371µs) by Hailo::BEGIN@15 at line 15
use Sub::Identify 0.04 qw(sub_fullname);
# spent 798µs making 1 call to namespace::clean::BEGIN@15 # spent 66µs making 1 call to Exporter::import # spent 12µs making 1 call to UNIVERSAL::VERSION
163161µs21.76ms
# spent 1.75ms (1.39+361µs) within namespace::clean::BEGIN@16 which was called: # once (1.39ms+361µs) by Hailo::BEGIN@15 at line 16
use Package::Stash 0.03;
# spent 1.75ms making 1 call to namespace::clean::BEGIN@16 # spent 12µs making 1 call to UNIVERSAL::VERSION
173766µs311.2ms
# spent 10.8ms (393µs+10.4) within namespace::clean::BEGIN@17 which was called: # once (393µs+10.4ms) by Hailo::BEGIN@15 at line 17
use B::Hooks::EndOfScope 0.07;
# spent 10.8ms making 1 call to namespace::clean::BEGIN@17 # spent 349µs making 1 call to Sub::Exporter::__ANON__[Sub/Exporter.pm:756] # spent 16µs making 1 call to UNIVERSAL::VERSION
18
1912µs$STORAGE_VAR = '__NAMESPACE_CLEAN_STORAGE';
20
21
22
# spent 30.6ms (3.74+26.8) within namespace::clean::__ANON__[/home/hinrik/perl5/perlbrew/perls/perl-5.13.5/lib/site_perl/5.13.5/namespace/clean.pm:52] which was called 7 times, avg 4.37ms/call: # 7 times (3.74ms+26.8ms) by namespace::clean::__ANON__[/home/hinrik/perl5/perlbrew/perls/perl-5.13.5/lib/site_perl/5.13.5/namespace/clean.pm:110] at line 109, avg 4.37ms/call
my $RemoveSubs = sub {
23
2435145µs my $cleanee = shift;
25 my $store = shift;
26788µs my $cleanee_stash = Package::Stash->new($cleanee);
# spent 88µs making 7 calls to Package::Stash::new, avg 13µs/call
277488µs my $deleted_stash = Package::Stash->new("namespace::clean::deleted::$cleanee");
# spent 488µs making 7 calls to Package::Stash::new, avg 70µs/call
28 SYMBOL:
29 for my $f (@_) {
305151.77ms my $variable = "&$f";
31 # ignore already removed symbols
32 next SYMBOL if $store->{exclude}{ $f };
33
341033.41ms next SYMBOL unless $cleanee_stash->has_package_symbol($variable);
# spent 3.41ms making 103 calls to Package::Stash::has_package_symbol, avg 33µs/call
35
362061.10ms103299µs if (ref(\$cleanee_stash->namespace->{$f}) eq 'GLOB') {
# spent 299µs making 103 calls to Package::Stash::namespace, avg 3µ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.
421032.73ms my $sub = $cleanee_stash->get_package_symbol($variable);
# spent 2.73ms making 103 calls to Package::Stash::get_package_symbol, avg 27µs/call
432061.10ms if ( sub_fullname($sub) eq ($cleanee_stash->name . "::$f") ) {
# spent 798µs making 103 calls to Sub::Identify::sub_fullname, avg 8µs/call # spent 298µs making 103 calls to Package::Stash::name, avg 3µ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
5010318.7ms $cleanee_stash->remove_package_symbol($variable);
# spent 18.7ms making 103 calls to Package::Stash::remove_package_symbol, avg 182µs/call
51 }
5214µs};
53
54sub clean_subroutines {
55 my ($nc, $cleanee, @subs) = @_;
56 $RemoveSubs->($cleanee, {}, @subs);
57}
58
59
60
# spent 9.78ms (1.34+8.44) within namespace::clean::import which was called 7 times, avg 1.40ms/call: # once (202µs+1.34ms) by Hailo::BEGIN@15 at line 15 of Hailo.pm # once (195µs+1.24ms) by Hailo::Role::Storage::BEGIN@11 at line 11 of Hailo/Role/Storage.pm # once (195µs+1.21ms) by Hailo::Role::Arguments::BEGIN@11 at line 11 of Hailo/Role/Arguments.pm # once (201µs+1.20ms) by Hailo::Role::Engine::BEGIN@11 at line 11 of Hailo/Role/Engine.pm # once (186µs+1.20ms) by Hailo::Role::Tokenizer::BEGIN@11 at line 11 of Hailo/Role/Tokenizer.pm # once (192µs+1.17ms) by Hailo::Tokenizer::Words::BEGIN@15 at line 15 of Hailo/Tokenizer/Words.pm # once (173µs+1.08ms) by Hailo::Storage::SQLite::BEGIN@12 at line 12 of Hailo/Storage/SQLite.pm
sub import {
613575µs my ($pragma, @args) = @_;
62
63 my (%args, $is_explicit);
64
65 ARG:
66 while (@args) {
67
6828102µs718µs if ($args[0] =~ /^\-/) {
# spent 18µs making 7 calls to namespace::clean::CORE:match, avg 3µ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;
8049253µ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
8873.88ms my $functions = $pragma->get_functions($cleanee);
# spent 3.88ms making 7 calls to namespace::clean::get_functions, avg 555µs/call
8971.01ms my $store = $pragma->get_class_store($cleanee);
# spent 1.01ms making 7 calls to namespace::clean::get_class_store, avg 144µs/call
90779µs my $stash = Package::Stash->new($cleanee);
# spent 79µs making 7 calls to Package::Stash::new, avg 11µ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) {
101316819µs next if $except{ $f };
1021033.23ms next unless $stash->has_package_symbol("&$f");
# spent 3.23ms making 103 calls to Package::Stash::has_package_symbol, avg 31µs/call
103 $store->{remove}{ $f } = 1;
104 }
105
106 # register EOF handler on first call to import
1071463µs unless ($store->{handler_is_installed}) {
108
# spent 30.6ms (72µs+30.6) within namespace::clean::__ANON__[/home/hinrik/perl5/perlbrew/perls/perl-5.13.5/lib/site_perl/5.13.5/namespace/clean.pm:110] which was called 7 times, avg 4.38ms/call: # 7 times (72µs+30.6ms) by B::Hooks::EndOfScope::__ANON__[/home/hinrik/perl5/perlbrew/perls/perl-5.13.5/lib/site_perl/5.13.5/B/Hooks/EndOfScope.pm:26] at line 26 of B/Hooks/EndOfScope.pm, avg 4.38ms/call
on_scope_end {
109772µs730.6ms $RemoveSubs->($cleanee, $store, keys %{ $store->{remove} });
# spent 30.6ms making 7 calls to namespace::clean::__ANON__[namespace/clean.pm:52], avg 4.37ms/call
1107229µs };
# spent 229µs making 7 calls to B::Hooks::EndOfScope::on_scope_end, avg 33µ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 1.01ms (179µs+827µs) within namespace::clean::get_class_store which was called 7 times, avg 144µs/call: # 7 times (179µs+827µs) by namespace::clean::import at line 89, avg 144µs/call
sub get_class_store {
13935154µs my ($pragma, $class) = @_;
140778µs my $stash = Package::Stash->new($class);
# spent 78µs making 7 calls to Package::Stash::new, avg 11µs/call
141 my $var = "%$STORAGE_VAR";
14214557µs $stash->add_package_symbol($var, {})
# spent 376µs making 7 calls to Package::Stash::add_package_symbol, avg 54µs/call # spent 181µs making 7 calls to Package::Stash::has_package_symbol, avg 26µs/call
143 unless $stash->has_package_symbol($var);
1447192µs return $stash->get_package_symbol($var);
# spent 192µs making 7 calls to Package::Stash::get_package_symbol, avg 27µs/call
145}
146
147
148
# spent 3.88ms (569µs+3.32) within namespace::clean::get_functions which was called 7 times, avg 555µs/call: # 7 times (569µs+3.32ms) by namespace::clean::import at line 88, avg 555µs/call
sub get_functions {
14921509µs my ($pragma, $class) = @_;
150
1517113µs my $stash = Package::Stash->new($class);
# spent 113µs making 7 calls to Package::Stash::new, avg 16µs/call
152 return {
1531173.20ms map { $_ => $stash->get_package_symbol("&$_") }
# spent 2.98ms making 110 calls to Package::Stash::get_package_symbol, avg 27µs/call # spent 226µs making 7 calls to Package::Stash::list_all_package_symbols, avg 32µs/call
154 $stash->list_all_package_symbols('CODE')
155 };
156}
157
158
159224µs266µs
# spent 40µs (14+26) within namespace::clean::BEGIN@159 which was called: # once (14µs+26µs) by Hailo::BEGIN@15 at line 159
no warnings;
# spent 40µs making 1 call to namespace::clean::BEGIN@159 # spent 26µs making 1 call to warnings::unimport
16014µs'Danger! Laws of Thermodynamics may not apply.'
161
162__END__
 
# spent 18µs within namespace::clean::CORE:match which was called 7 times, avg 3µs/call: # 7 times (18µs+0s) by namespace::clean::import at line 68, avg 3µs/call
sub namespace::clean::CORE:match; # opcode