← Index
NYTProf Performance Profile   « block view • line view • sub view »
For bin/dpath
  Run on Tue Jun 5 15:31:33 2012
Reported on Tue Jun 5 15:31:42 2012

Filename/home/ss5/perl5/perlbrew/perls/perl-5.14.1/lib/5.14.1/base.pm
StatementsExecuted 280 statements in 6.45ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
1010103.17ms3.62msbase::::importbase::import
1011150µs150µsbase::::has_fieldsbase::has_fields
1011114µs114µsbase::::has_attrbase::has_attr
711107µs107µsbase::::CORE:matchbase::CORE:match (opcode)
11148µs103µsbase::::BEGIN@3base::BEGIN@3
11127µs126µsbase::::BEGIN@4base::BEGIN@4
0000s0sbase::::__ANON__[:48]base::__ANON__[:48]
0000s0sbase::::__ANON__[:55]base::__ANON__[:55]
0000s0sbase::::get_attrbase::get_attr
0000s0sbase::::inherit_fieldsbase::inherit_fields
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package base;
2
32101µs2158µs
# spent 103µs (48+55) within base::BEGIN@3 which was called: # once (48µs+55µs) by Iterator::Util::BEGIN@20 at line 3
use strict 'vars';
# spent 103µs making 1 call to base::BEGIN@3 # spent 55µs making 1 call to strict::import
423.36ms2224µs
# spent 126µs (27+99) within base::BEGIN@4 which was called: # once (27µs+99µs) by Iterator::Util::BEGIN@20 at line 4
use vars qw($VERSION);
# spent 126µs making 1 call to base::BEGIN@4 # spent 99µs making 1 call to vars::import
513µs$VERSION = '2.18';
6157µs$VERSION = eval $VERSION;
# spent 10µs executing statements in string eval
7
8# constant.pm is slow
9sub SUCCESS () { 1 }
10
11sub PUBLIC () { 2**0 }
12sub PRIVATE () { 2**1 }
13sub INHERITED () { 2**2 }
14sub PROTECTED () { 2**3 }
15
16
1714µsmy $Fattr = \%fields::attr;
18
19
# spent 150µs within base::has_fields which was called 10 times, avg 15µs/call: # 10 times (150µs+0s) by base::import at line 101, avg 15µs/call
sub has_fields {
2030189µs my($base) = shift;
21 my $fglob = ${"$base\::"}{FIELDS};
22 return( ($fglob && 'GLOB' eq ref($fglob) && *$fglob{HASH}) ? 1 : 0 );
23}
24
25
# spent 114µs within base::has_attr which was called 10 times, avg 11µs/call: # 10 times (114µs+0s) by base::import at line 101, avg 11µs/call
sub has_attr {
2630138µs my($proto) = shift;
27 my($class) = ref $proto || $proto;
28 return exists $Fattr->{$class};
29}
30
31sub get_attr {
32 $Fattr->{$_[0]} = [1] unless $Fattr->{$_[0]};
33 return $Fattr->{$_[0]};
34}
35
36219µsif ($] < 5.009) {
37 *get_fields = sub {
38 # Shut up a possible typo warning.
39 () = \%{$_[0].'::FIELDS'};
40 my $f = \%{$_[0].'::FIELDS'};
41
42 # should be centralized in fields? perhaps
43 # fields::mk_FIELDS_be_OK. Peh. As long as %{ $package . '::FIELDS' }
44 # is used here anyway, it doesn't matter.
45 bless $f, 'pseudohash' if (ref($f) ne 'pseudohash');
46
47 return $f;
48 }
49}
50else {
51 *get_fields = sub {
52 # Shut up a possible typo warning.
53 () = \%{$_[0].'::FIELDS'};
54 return \%{$_[0].'::FIELDS'};
55 }
56}
57
58
# spent 3.62ms (3.17+449µs) within base::import which was called 10 times, avg 362µs/call: # once (443µs+49µs) by Iterator::X::Internal_Error::BEGIN@3 at line 3 of (eval 21)[Exception/Class.pm:180] # once (386µs+54µs) by Iterator::X::IO_Error::BEGIN@3 at line 3 of (eval 15)[Exception/Class.pm:180] # once (323µs+47µs) by Iterator::X::Exhausted::BEGIN@3 at line 3 of (eval 17)[Exception/Class.pm:180] # once (319µs+44µs) by Iterator::X::User_Code_Error::BEGIN@3 at line 3 of (eval 25)[Exception/Class.pm:180] # once (316µs+44µs) by Iterator::X::Am_Now_Exhausted::BEGIN@3 at line 3 of (eval 27)[Exception/Class.pm:180] # once (310µs+46µs) by Iterator::X::Parameter_Error::BEGIN@3 at line 3 of (eval 23)[Exception/Class.pm:180] # once (312µs+43µs) by Iterator::X::OptionError::BEGIN@3 at line 3 of (eval 19)[Exception/Class.pm:180] # once (275µs+40µs) by Iterator::Util::BEGIN@20 at line 20 of Iterator/Util.pm # once (256µs+41µs) by Iterator::X::BEGIN@3 at line 3 of (eval 13)[Exception/Class.pm:180] # once (235µs+41µs) by Exception::Class::Base::BEGIN@13 at line 13 of Exception/Class/Base.pm
sub import {
5980627µs my $class = shift;
60
61 return SUCCESS unless @_;
62
63 # List of base classes from which we will inherit %FIELDS.
64 my $fields_base;
65
66 my $inheritor = caller(0);
67
68 my @bases;
69 foreach my $base (@_) {
7050606µs if ( $inheritor eq $base ) {
71 warn "Class '$inheritor' tried to inherit from itself\n";
72 }
73
741077µs next if grep $_->isa($base), ($inheritor, @bases);
# spent 77µs making 10 calls to UNIVERSAL::isa, avg 8µs/call
75
76 # Following blocks help isolate $SIG{__DIE__} changes
77 {
783039µs my $sigdie;
79 {
80501.29ms local $SIG{__DIE__};
81 eval "require $base";
# spent 788µs executing statements in 7 string evals (merged) # spent 8µs executing statements in string eval # spent 8µs executing statements in string eval # spent 8µs executing statements in string eval
82 # Only ignore "Can't locate" errors from our eval require.
83 # Other fatal errors (syntax etc) must be reported.
847107µs die if $@ && $@ !~ /^Can't locate .*? at \(eval /;
# spent 107µs making 7 calls to base::CORE:match, avg 15µs/call
85 unless (%{"$base\::"}) {
86 require Carp;
87 local $" = " ";
88 Carp::croak(<<ERROR);
89Base class package "$base" is empty.
90 (Perhaps you need to 'use' the module which defines that package first,
91 or make that module available in \@INC (\@INC contains: @INC).
92ERROR
93 }
94 $sigdie = $SIG{__DIE__} || undef;
95 }
96 # Make sure a global $SIG{__DIE__} makes it out of the localization.
97 $SIG{__DIE__} = $sigdie if defined $sigdie;
98 }
99 push @bases, $base;
100
10120264µs if ( has_fields($base) || has_attr($base) ) {
# spent 150µs making 10 calls to base::has_fields, avg 15µs/call # spent 114µs making 10 calls to base::has_attr, avg 11µs/call
102 # No multiple fields inheritance *suck*
103 if ($fields_base) {
104 require Carp;
105 Carp::croak("Can't multiply inherit fields");
106 } else {
107 $fields_base = $base;
108 }
109 }
110 }
111 # Save this until the end so it's all or nothing if the above loop croaks.
112 push @{"$inheritor\::ISA"}, @bases;
113
114 if( defined $fields_base ) {
115 inherit_fields($inheritor, $fields_base);
116 }
117}
118
119
120sub inherit_fields {
121 my($derived, $base) = @_;
122
123 return SUCCESS unless $base;
124
125 my $battr = get_attr($base);
126 my $dattr = get_attr($derived);
127 my $dfields = get_fields($derived);
128 my $bfields = get_fields($base);
129
130 $dattr->[0] = @$battr;
131
132 if( keys %$dfields ) {
133 warn <<"END";
134$derived is inheriting from $base but already has its own fields!
135This will cause problems. Be sure you use base BEFORE declaring fields.
136END
137
138 }
139
140 # Iterate through the base's fields adding all the non-private
141 # ones to the derived class. Hang on to the original attribute
142 # (Public, Private, etc...) and add Inherited.
143 # This is all too complicated to do efficiently with add_fields().
144 while (my($k,$v) = each %$bfields) {
145 my $fno;
146 if ($fno = $dfields->{$k} and $fno != $v) {
147 require Carp;
148 Carp::croak ("Inherited fields can't override existing fields");
149 }
150
151 if( $battr->[$v] & PRIVATE ) {
152 $dattr->[$v] = PRIVATE | INHERITED;
153 }
154 else {
155 $dattr->[$v] = INHERITED | $battr->[$v];
156 $dfields->{$k} = $v;
157 }
158 }
159
160 foreach my $idx (1..$#{$battr}) {
161 next if defined $dattr->[$idx];
162 $dattr->[$idx] = $battr->[$idx] & INHERITED;
163 }
164}
165
166
167118µs1;
168
169__END__
 
# spent 107µs within base::CORE:match which was called 7 times, avg 15µs/call: # 7 times (107µs+0s) by base::import at line 84, avg 15µs/call
sub base::CORE:match; # opcode