← Index
NYTProf Performance Profile   « block view • line view • sub view »
For bin/hailo
  Run on Thu Oct 21 22:50:37 2010
Reported on Thu Oct 21 22:52:08 2010

Filename/home/hinrik/perl5/perlbrew/perls/perl-5.13.5/lib/site_perl/5.13.5/namespace/clean.pm
StatementsExecuted 1632 statements in 7.98ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
9114.72ms37.9msnamespace::clean::::__ANON__[:52]namespace::clean::__ANON__[:52]
9991.68ms12.3msnamespace::clean::::importnamespace::clean::import
1111.42ms1.77msnamespace::clean::::BEGIN@16namespace::clean::BEGIN@16
911720µs4.87msnamespace::clean::::get_functionsnamespace::clean::get_functions
111454µs812µsnamespace::clean::::BEGIN@15namespace::clean::BEGIN@15
111380µs2.61msnamespace::clean::::BEGIN@17namespace::clean::BEGIN@17
111239µs866µsnamespace::clean::::BEGIN@14namespace::clean::BEGIN@14
911225µs1.28msnamespace::clean::::get_class_storenamespace::clean::get_class_store
91190µs38.0msnamespace::clean::::__ANON__[:110]namespace::clean::__ANON__[:110]
91126µs26µsnamespace::clean::::CORE:matchnamespace::clean::CORE:match (opcode)
11118µs18µsnamespace::clean::::BEGIN@2namespace::clean::BEGIN@2
11116µs59µsnamespace::clean::::BEGIN@13namespace::clean::BEGIN@13
11116µs50µsnamespace::clean::::BEGIN@159namespace::clean::BEGIN@159
11112µs18µsnamespace::clean::::BEGIN@11namespace::clean::BEGIN@11
11111µs21µsnamespace::clean::::BEGIN@10namespace::clean::BEGIN@10
1115µs5µ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 18µs within namespace::clean::BEGIN@2 which was called: # once (18µs+0s) by Hailo::Command::BEGIN@7 at line 4
BEGIN {
316µs $namespace::clean::AUTHORITY = 'cpan:PHAYLON';
4122µs118µs}
# spent 18µs making 1 call to namespace::clean::BEGIN@2
5
# spent 5µs within namespace::clean::BEGIN@5 which was called: # once (5µs+0s) by Hailo::Command::BEGIN@7 at line 7
BEGIN {
616µs $namespace::clean::VERSION = '0.18';
7117µs15µs}
# spent 5µs making 1 call to namespace::clean::BEGIN@5
8# ABSTRACT: Keep imports and functions out of your namespace
9
10224µs231µs
# spent 21µs (11+10) within namespace::clean::BEGIN@10 which was called: # once (11µs+10µs) by Hailo::Command::BEGIN@7 at line 10
use warnings;
# spent 21µs making 1 call to namespace::clean::BEGIN@10 # spent 10µs making 1 call to warnings::import
11227µs224µs
# spent 18µs (12+6) within namespace::clean::BEGIN@11 which was called: # once (12µs+6µs) by Hailo::Command::BEGIN@7 at line 11
use strict;
# spent 18µs making 1 call to namespace::clean::BEGIN@11 # spent 6µs making 1 call to strict::import
12
13231µs2101µs
# spent 59µs (16+42) within namespace::clean::BEGIN@13 which was called: # once (16µs+42µs) by Hailo::Command::BEGIN@7 at line 13
use vars qw( $STORAGE_VAR );
# spent 59µs making 1 call to namespace::clean::BEGIN@13 # spent 42µs making 1 call to vars::import
143153µs3947µs
# spent 866µs (239+626) within namespace::clean::BEGIN@14 which was called: # once (239µs+626µs) by Hailo::Command::BEGIN@7 at line 14
use Sub::Name 0.04 qw(subname);
# spent 866µs making 1 call to namespace::clean::BEGIN@14 # spent 69µs making 1 call to Exporter::import # spent 12µs making 1 call to UNIVERSAL::VERSION
153146µs3897µs
# spent 812µs (454+358) within namespace::clean::BEGIN@15 which was called: # once (454µs+358µs) by Hailo::Command::BEGIN@7 at line 15
use Sub::Identify 0.04 qw(sub_fullname);
# spent 812µs making 1 call to namespace::clean::BEGIN@15 # spent 68µs making 1 call to Exporter::import # spent 16µs making 1 call to UNIVERSAL::VERSION
163160µs21.78ms
# spent 1.77ms (1.42+354µs) within namespace::clean::BEGIN@16 which was called: # once (1.42ms+354µs) by Hailo::Command::BEGIN@7 at line 16
use Package::Stash 0.03;
# spent 1.77ms making 1 call to namespace::clean::BEGIN@16 # spent 13µs making 1 call to UNIVERSAL::VERSION
173947µs32.98ms
# spent 2.61ms (380µs+2.23) within namespace::clean::BEGIN@17 which was called: # once (380µs+2.23ms) by Hailo::Command::BEGIN@7 at line 17
use B::Hooks::EndOfScope 0.07;
# spent 2.61ms making 1 call to namespace::clean::BEGIN@17 # spent 362µs making 1 call to Sub::Exporter::__ANON__[Sub/Exporter.pm:756] # spent 14µs making 1 call to UNIVERSAL::VERSION
18
1912µs$STORAGE_VAR = '__NAMESPACE_CLEAN_STORAGE';
20
21
22
# spent 37.9ms (4.72+33.2) 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 9 times, avg 4.21ms/call: # 9 times (4.72ms+33.2ms) 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.21ms/call
my $RemoveSubs = sub {
23
2445182µs my $cleanee = shift;
25 my $store = shift;
269113µs my $cleanee_stash = Package::Stash->new($cleanee);
# spent 113µs making 9 calls to Package::Stash::new, avg 13µs/call
279133µs my $deleted_stash = Package::Stash->new("namespace::clean::deleted::$cleanee");
# spent 133µs making 9 calls to Package::Stash::new, avg 15µs/call
28 SYMBOL:
29 for my $f (@_) {
306552.27ms my $variable = "&$f";
31 # ignore already removed symbols
32 next SYMBOL if $store->{exclude}{ $f };
33
341314.23ms next SYMBOL unless $cleanee_stash->has_package_symbol($variable);
# spent 4.23ms making 131 calls to Package::Stash::has_package_symbol, avg 32µs/call
35
362621.37ms131384µs if (ref(\$cleanee_stash->namespace->{$f}) eq 'GLOB') {
# spent 384µs making 131 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.
421313.46ms my $sub = $cleanee_stash->get_package_symbol($variable);
# spent 3.46ms making 131 calls to Package::Stash::get_package_symbol, avg 26µs/call
432621.37ms if ( sub_fullname($sub) eq ($cleanee_stash->name . "::$f") ) {
# spent 988µs making 131 calls to Sub::Identify::sub_fullname, avg 8µs/call # spent 383µs making 131 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
5013123.5ms $cleanee_stash->remove_package_symbol($variable);
# spent 23.5ms making 131 calls to Package::Stash::remove_package_symbol, avg 179µs/call
51 }
5214µs};
53
54sub clean_subroutines {
55 my ($nc, $cleanee, @subs) = @_;
56 $RemoveSubs->($cleanee, {}, @subs);
57}
58
59
60
# spent 12.3ms (1.68+10.6) within namespace::clean::import which was called 9 times, avg 1.37ms/call: # once (199µs+1.26ms) by Hailo::BEGIN@9 at line 9 of lib/Hailo.pm # once (192µs+1.22ms) by Hailo::Role::Arguments::BEGIN@5 at line 5 of lib/Hailo/Role/Arguments.pm # once (192µs+1.21ms) by Hailo::Role::Engine::BEGIN@5 at line 5 of lib/Hailo/Role/Engine.pm # once (188µs+1.19ms) by hailo::BEGIN@9 at line 9 of bin/hailo # once (182µs+1.19ms) by Hailo::Role::Tokenizer::BEGIN@5 at line 5 of lib/Hailo/Role/Tokenizer.pm # once (182µs+1.17ms) by Hailo::Role::Storage::BEGIN@5 at line 5 of lib/Hailo/Role/Storage.pm # once (193µs+1.16ms) by Hailo::Tokenizer::Words::BEGIN@9 at line 9 of lib/Hailo/Tokenizer/Words.pm # once (173µs+1.12ms) by Hailo::Storage::SQLite::BEGIN@6 at line 6 of lib/Hailo/Storage/SQLite.pm # once (175µs+1.11ms) by Hailo::Command::BEGIN@7 at line 7 of lib/Hailo/Command.pm
sub import {
614591µs my ($pragma, @args) = @_;
62
63 my (%args, $is_explicit);
64
65 ARG:
66 while (@args) {
67
6836142µs926µs if ($args[0] =~ /^\-/) {
# spent 26µs making 9 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;
8063316µ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
8894.87ms my $functions = $pragma->get_functions($cleanee);
# spent 4.87ms making 9 calls to namespace::clean::get_functions, avg 541µs/call
8991.28ms my $store = $pragma->get_class_store($cleanee);
# spent 1.28ms making 9 calls to namespace::clean::get_class_store, avg 142µs/call
909100µs my $stash = Package::Stash->new($cleanee);
# spent 100µs making 9 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) {
1014021.02ms next if $except{ $f };
1021314.04ms next unless $stash->has_package_symbol("&$f");
# spent 4.04ms making 131 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
1071879µs unless ($store->{handler_is_installed}) {
108
# spent 38.0ms (90µs+37.9) 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 9 times, avg 4.22ms/call: # 9 times (90µs+37.9ms) 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.22ms/call
on_scope_end {
109989µs937.9ms $RemoveSubs->($cleanee, $store, keys %{ $store->{remove} });
# spent 37.9ms making 9 calls to namespace::clean::__ANON__[namespace/clean.pm:52], avg 4.21ms/call
1109301µs };
# spent 301µs making 9 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.28ms (225µs+1.06) within namespace::clean::get_class_store which was called 9 times, avg 142µs/call: # 9 times (225µs+1.06ms) by namespace::clean::import at line 89, avg 142µs/call
sub get_class_store {
13945201µs my ($pragma, $class) = @_;
1409102µs my $stash = Package::Stash->new($class);
# spent 102µs making 9 calls to Package::Stash::new, avg 11µs/call
141 my $var = "%$STORAGE_VAR";
14218709µs $stash->add_package_symbol($var, {})
# spent 466µs making 9 calls to Package::Stash::add_package_symbol, avg 52µs/call # spent 243µs making 9 calls to Package::Stash::has_package_symbol, avg 27µs/call
143 unless $stash->has_package_symbol($var);
1449245µs return $stash->get_package_symbol($var);
# spent 245µs making 9 calls to Package::Stash::get_package_symbol, avg 27µs/call
145}
146
147
148
# spent 4.87ms (720µs+4.15) within namespace::clean::get_functions which was called 9 times, avg 541µs/call: # 9 times (720µs+4.15ms) by namespace::clean::import at line 88, avg 541µs/call
sub get_functions {
14927638µs my ($pragma, $class) = @_;
150
1519142µs my $stash = Package::Stash->new($class);
# spent 142µs making 9 calls to Package::Stash::new, avg 16µs/call
152 return {
1531494.01ms map { $_ => $stash->get_package_symbol("&$_") }
# spent 3.74ms making 140 calls to Package::Stash::get_package_symbol, avg 27µs/call # spent 271µs making 9 calls to Package::Stash::list_all_package_symbols, avg 30µs/call
154 $stash->list_all_package_symbols('CODE')
155 };
156}
157
158
159227µs285µs
# spent 50µs (16+35) within namespace::clean::BEGIN@159 which was called: # once (16µs+35µs) by Hailo::Command::BEGIN@7 at line 159
no warnings;
# spent 50µs making 1 call to namespace::clean::BEGIN@159 # spent 35µs making 1 call to warnings::unimport
16014µs'Danger! Laws of Thermodynamics may not apply.'
161
162__END__
 
# spent 26µs within namespace::clean::CORE:match which was called 9 times, avg 3µs/call: # 9 times (26µs+0s) by namespace::clean::import at line 68, avg 3µs/call
sub namespace::clean::CORE:match; # opcode