← Index
NYTProf Performance Profile   « line view »
For examples/Atom-timer.pl
  Run on Mon Aug 12 14:45:28 2013
Reported on Mon Aug 12 14:46:14 2013

Filename/Users/dde/perl5/perlbrew/perls/5.18.0t/lib/5.18.0/base.pm
StatementsExecuted 1723 statements in 3.81ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
5555547.61ms21.3msbase::::importbase::import (recurses: max depth 2, inclusive time 4.86ms)
6711167µs167µsbase::::has_fieldsbase::has_fields
6711118µs118µsbase::::has_attrbase::has_attr
1119µs17µsbase::::BEGIN@3base::BEGIN@3
1116µs20µ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
3220µs225µs
# spent 17µs (9+8) within base::BEGIN@3 which was called: # once (9µs+8µs) by Class::Load::BEGIN@7 at line 3
use strict 'vars';
# spent 17µs making 1 call to base::BEGIN@3 # spent 8µs making 1 call to strict::import
42709µs235µs
# spent 20µs (6+15) within base::BEGIN@4 which was called: # once (6µs+15µs) by Class::Load::BEGIN@7 at line 4
use vars qw($VERSION);
# spent 20µs making 1 call to base::BEGIN@4 # spent 15µs making 1 call to vars::import
51400ns$VERSION = '2.18';
6110µs$VERSION = eval $VERSION;
# spent 2µ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
171500nsmy $Fattr = \%fields::attr;
18
19
# spent 167µs within base::has_fields which was called 67 times, avg 2µs/call: # 67 times (167µs+0s) by base::import at line 101, avg 2µs/call
sub has_fields {
206722µs my($base) = shift;
216745µs my $fglob = ${"$base\::"}{FIELDS};
2267147µs return( ($fglob && 'GLOB' eq ref($fglob) && *$fglob{HASH}) ? 1 : 0 );
23}
24
25
# spent 118µs within base::has_attr which was called 67 times, avg 2µs/call: # 67 times (118µs+0s) by base::import at line 101, avg 2µs/call
sub has_attr {
266714µs my($proto) = shift;
276715µs my($class) = ref $proto || $proto;
2867107µs return exists $Fattr->{$class};
29}
30
31sub get_attr {
32 $Fattr->{$_[0]} = [1] unless $Fattr->{$_[0]};
33 return $Fattr->{$_[0]};
34}
35
361700nsif ($] < 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 }
5612µs}
57
58
# spent 21.3ms (7.61+13.6) within base::import which was called 55 times, avg 386µs/call: # once (563µs+7.07ms) by Moose::Meta::Attribute::BEGIN@27 at line 27 of Moose/Meta/Attribute.pm # once (584µs+4.09ms) by Class::MOP::Class::BEGIN@26 at line 28 of Class/MOP/Class.pm # once (443µs+1.69ms) by Moose::Meta::Method::Overridden::BEGIN@12 at line 12 of Moose/Meta/Method/Overridden.pm # once (471µs+1.43ms) by Class::MOP::Method::Accessor::BEGIN@17 at line 17 of Class/MOP/Method/Accessor.pm # once (726µs+735µs) by Class::MOP::Method::Meta::BEGIN@18 at line 18 of Class/MOP/Method/Meta.pm # once (584µs+166µs) by Class::MOP::Method::Constructor::BEGIN@17 at line 17 of Class/MOP/Method/Constructor.pm # once (217µs+64µs) by Class::MOP::Mixin::AttributeCore::BEGIN@14 at line 14 of Class/MOP/Mixin/AttributeCore.pm # once (106µs+19µs) by Moose::Meta::Role::BEGIN@27 at line 29 of Moose/Meta/Role.pm # once (92µs+6µs) by Moose::Meta::Role::Method::Required::BEGIN@17 at line 17 of Moose/Meta/Role/Method/Required.pm # once (80µs+12µs) by Moose::Meta::Method::Constructor::BEGIN@18 at line 19 of Moose/Meta/Method/Constructor.pm # once (77µs+12µs) by Class::MOP::Attribute::BEGIN@19 at line 19 of Class/MOP/Attribute.pm # once (75µs+12µs) by Moose::Meta::Role::Attribute::BEGIN@16 at line 16 of Moose/Meta/Role/Attribute.pm # once (74µs+12µs) by Moose::Meta::Method::Meta::BEGIN@13 at line 14 of Moose/Meta/Method/Meta.pm # once (71µs+12µs) by Moose::Meta::Method::Accessor::BEGIN@15 at line 16 of Moose/Meta/Method/Accessor.pm # once (69µs+12µs) by Moose::Meta::Method::Delegation::BEGIN@16 at line 17 of Moose/Meta/Method/Delegation.pm # once (68µs+11µs) by Moose::Meta::Method::Destructor::BEGIN@17 at line 18 of Moose/Meta/Method/Destructor.pm # once (50µs+15µs) by Moose::Meta::Role::Method::Conflicting::BEGIN@15 at line 15 of Moose/Meta/Role/Method/Conflicting.pm # once (50µs+8µs) by Variable::Magic::BEGIN@636 at line 636 of Variable/Magic.pm # once (49µs+6µs) by Moose::Meta::Method::Augmented::BEGIN@12 at line 12 of Moose/Meta/Method/Augmented.pm # once (49µs+5µs) by Class::MOP::Method::Wrapped::BEGIN@16 at line 16 of Class/MOP/Method/Wrapped.pm # once (47µs+6µs) by Moose::Meta::Instance::BEGIN@15 at line 15 of Moose/Meta/Instance.pm # once (47µs+6µs) by Class::Load::BEGIN@7 at line 7 of Class/Load.pm # once (46µs+6µs) by Moose::Meta::Class::Immutable::Trait::BEGIN@15 at line 15 of Moose/Meta/Class/Immutable/Trait.pm # once (47µs+5µs) by Moose::Meta::Role::Method::BEGIN@13 at line 13 of Moose/Meta/Role/Method.pm # once (46µs+6µs) by Moose::Meta::TypeConstraint::Enum::BEGIN@16 at line 16 of Moose/Meta/TypeConstraint/Enum.pm # once (46µs+6µs) by Moose::Meta::TypeConstraint::Registry::BEGIN@16 at line 16 of Moose/Meta/TypeConstraint/Registry.pm # once (46µs+5µs) by Moose::Meta::Role::Composite::BEGIN@16 at line 16 of Moose/Meta/Role/Composite.pm # once (45µs+6µs) by Moose::Error::Default::BEGIN@17 at line 17 of Moose/Error/Default.pm # once (45µs+5µs) by Class::MOP::Mixin::HasAttributes::BEGIN@15 at line 15 of Class/MOP/Mixin/HasAttributes.pm # once (44µs+5µs) by Moose::Meta::Class::BEGIN@31 at line 31 of Moose/Meta/Class.pm # once (44µs+6µs) by Moose::Meta::Role::Application::ToInstance::BEGIN@16 at line 16 of Moose/Meta/Role/Application/ToInstance.pm # once (44µs+5µs) by Sub::Name::BEGIN@49 at line 49 of Sub/Name.pm # once (44µs+5µs) by Class::MOP::Instance::BEGIN@15 at line 15 of Class/MOP/Instance.pm # once (43µs+5µs) by Moose::Meta::Role::Application::RoleSummation::BEGIN@17 at line 17 of Moose/Meta/Role/Application/RoleSummation.pm # once (43µs+5µs) by Moose::Meta::TypeConstraint::Union::BEGIN@19 at line 19 of Moose/Meta/TypeConstraint/Union.pm # once (42µs+5µs) by Moose::Meta::TypeConstraint::Class::BEGIN@17 at line 17 of Moose/Meta/TypeConstraint/Class.pm # once (42µs+5µs) by Moose::Meta::TypeCoercion::Union::BEGIN@16 at line 16 of Moose/Meta/TypeCoercion/Union.pm # once (42µs+5µs) by Moose::Meta::Role::Application::ToRole::BEGIN@15 at line 15 of Moose/Meta/Role/Application/ToRole.pm # once (42µs+5µs) by Try::Tiny::BEGIN@14 at line 14 of Try/Tiny.pm # once (42µs+5µs) by Moose::Meta::TypeConstraint::Role::BEGIN@17 at line 17 of Moose/Meta/TypeConstraint/Role.pm # once (41µs+5µs) by Moose::Meta::TypeConstraint::DuckType::BEGIN@20 at line 20 of Moose/Meta/TypeConstraint/DuckType.pm # once (41µs+6µs) by Moose::Meta::TypeConstraint::BEGIN@26 at line 26 of Moose/Meta/TypeConstraint.pm # once (41µs+5µs) by Moose::Meta::TypeConstraint::Parameterizable::BEGIN@13 at line 13 of Moose/Meta/TypeConstraint/Parameterizable.pm # once (40µs+6µs) by Moose::Meta::TypeConstraint::Parameterized::BEGIN@17 at line 17 of Moose/Meta/TypeConstraint/Parameterized.pm # once (40µs+5µs) by Class::MOP::Method::Overload::BEGIN@15 at line 15 of Class/MOP/Method/Overload.pm # once (40µs+5µs) by Moose::Meta::Role::Application::ToClass::BEGIN@17 at line 17 of Moose/Meta/Role/Application/ToClass.pm # once (40µs+5µs) by Class::MOP::Mixin::HasMethods::BEGIN@21 at line 21 of Class/MOP/Mixin/HasMethods.pm # once (38µs+5µs) by Sub::Name::BEGIN@50 at line 50 of Sub/Name.pm # once (50µs+-50µs) by Moose::Meta::Method::BEGIN@14 at line 14 of Moose/Meta/Method.pm # once (46µs+-46µs) by Class::MOP::Package::BEGIN@18 at line 18 of Class/MOP/Package.pm # once (49µs+-49µs) by Class::MOP::Method::Inlined::BEGIN@15 at line 15 of Class/MOP/Method/Inlined.pm # once (1.14ms+-1.14ms) by Class::MOP::Module::BEGIN@16 at line 16 of Class/MOP/Module.pm # once (47µs+-47µs) by Class::MOP::Method::Generated::BEGIN@16 at line 16 of Class/MOP/Method/Generated.pm # once (44µs+-44µs) by Moose::Meta::Mixin::AttributeCore::BEGIN@12 at line 12 of Moose/Meta/Mixin/AttributeCore.pm # once (523µs+-523µs) by Class::MOP::Method::BEGIN@16 at line 16 of Class/MOP/Method.pm
sub import {
595516µs my $class = shift;
60
615512µs return SUCCESS unless @_;
62
63 # List of base classes from which we will inherit %FIELDS.
64551µs my $fields_base;
65
665521µs my $inheritor = caller(0);
67
68556µs my @bases;
695526µs foreach my $base (@_) {
706711µs if ( $inheritor eq $base ) {
71 warn "Class '$inheritor' tried to inherit from itself\n";
72 }
73
7467532µs81120µs next if grep $_->isa($base), ($inheritor, @bases);
# spent 120µs making 81 calls to UNIVERSAL::isa, avg 1µs/call
75
76 # Following blocks help isolate $SIG{__DIE__} changes
77 {
781348µs my $sigdie;
79 {
8013484µs local $SIG{__DIE__};
8167968µs eval "require $base";
# spent 91µs executing statements in 8 string evals (merged) # spent 77µs executing statements in 9 string evals (merged) # spent 74µs executing statements in 5 string evals (merged) # spent 73µs executing statements in 2 string evals (merged) # spent 70µs executing statements in 2 string evals (merged) # spent 70µs executing statements in 2 string evals (merged) # spent 68µs executing statements in 3 string evals (merged) # spent 66µs executing statements in 3 string evals (merged) # spent 66µs executing statements in string eval # spent 14µs executing statements in 7 string evals (merged) # spent 8µs executing statements in 4 string evals (merged) # spent 8µs executing statements in 4 string evals (merged) # spent 4µs executing statements in 2 string evals (merged) # spent 4µs executing statements in 2 string evals (merged) # spent 4µs executing statements in 2 string evals (merged) # spent 2µs executing statements in string eval # spent 2µs executing statements in string eval # spent 2µs executing statements in string eval # spent 2µs executing statements in string eval # spent 2µs executing statements in string eval # spent 2µs executing statements in string eval # spent 2µs executing statements in string eval # spent 2µs executing statements in string eval # spent 2µs executing statements in string eval # spent 2µs executing statements in string eval # spent 2µ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.
84677µs die if $@ && $@ !~ /^Can't locate .*? at \(eval /;
8567112µs 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 }
9467124µs $sigdie = $SIG{__DIE__} || undef;
95 }
96 # Make sure a global $SIG{__DIE__} makes it out of the localization.
976714µs $SIG{__DIE__} = $sigdie if defined $sigdie;
98 }
996730µs push @bases, $base;
100
10167156µs134285µs if ( has_fields($base) || has_attr($base) ) {
# spent 167µs making 67 calls to base::has_fields, avg 2µs/call # spent 118µs making 67 calls to base::has_attr, avg 2µ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.
11255400µs push @{"$inheritor\::ISA"}, @bases;
113
11455183µs 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
16714µs1;
168
169__END__