← Index
NYTProf Performance Profile   « line view »
For flows_to_es.pl
  Run on Mon May 9 23:27:59 2016
Reported on Mon May 9 23:28:08 2016

Filename/usr/share/perl/5.18/base.pm
StatementsExecuted 388 statements in 1.92ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
1414132.63ms2.79msbase::::importbase::import
141150µs50µsbase::::has_fieldsbase::has_fields
141133µs33µsbase::::has_attrbase::has_attr
11113µs28µsbase::::BEGIN@3base::BEGIN@3
1118µs29µsbase::::BEGIN@4base::BEGIN@4
0000s0sbase::::__ANON__[:47]base::__ANON__[:47]
0000s0sbase::::__ANON__[:54]base::__ANON__[:54]
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
3230µs243µs
# spent 28µs (13+15) within base::BEGIN@3 which was called: # once (13µs+15µs) by Sub::Name::BEGIN@49 at line 3
use strict 'vars';
# spent 28µs making 1 call to base::BEGIN@3 # spent 15µs making 1 call to strict::import
42883µs250µs
# spent 29µs (8+21) within base::BEGIN@4 which was called: # once (8µs+21µs) by Sub::Name::BEGIN@49 at line 4
use vars qw($VERSION);
# spent 29µs making 1 call to base::BEGIN@4 # spent 21µs making 1 call to vars::import
51600ns$VERSION = '2.18';
6113µ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
161800nsmy $Fattr = \%fields::attr;
17
18
# spent 50µs within base::has_fields which was called 14 times, avg 4µs/call: # 14 times (50µs+0s) by base::import at line 100, avg 4µs/call
sub has_fields {
19149µs my($base) = shift;
201414µs my $fglob = ${"$base\::"}{FIELDS};
211454µs return( ($fglob && 'GLOB' eq ref($fglob) && *$fglob{HASH}) ? 1 : 0 );
22}
23
24
# spent 33µs within base::has_attr which was called 14 times, avg 2µs/call: # 14 times (33µs+0s) by base::import at line 100, avg 2µs/call
sub has_attr {
25145µs my($proto) = shift;
26145µs my($class) = ref $proto || $proto;
271435µs return exists $Fattr->{$class};
28}
29
30sub get_attr {
31 $Fattr->{$_[0]} = [1] unless $Fattr->{$_[0]};
32 return $Fattr->{$_[0]};
33}
34
3511µsif ($] < 5.009) {
36 *get_fields = sub {
37 # Shut up a possible typo warning.
38 () = \%{$_[0].'::FIELDS'};
39 my $f = \%{$_[0].'::FIELDS'};
40
41 # should be centralized in fields? perhaps
42 # fields::mk_FIELDS_be_OK. Peh. As long as %{ $package . '::FIELDS' }
43 # is used here anyway, it doesn't matter.
44 bless $f, 'pseudohash' if (ref($f) ne 'pseudohash');
45
46 return $f;
47 }
48}
49else {
50 *get_fields = sub {
51 # Shut up a possible typo warning.
52 () = \%{$_[0].'::FIELDS'};
53 return \%{$_[0].'::FIELDS'};
54 }
5514µs}
56
57
# spent 2.79ms (2.63+154µs) within base::import which was called 14 times, avg 199µs/call: # once (1.82ms+49µs) by Sub::Name::BEGIN@50 at line 50 of Sub/Name.pm # once (86µs+14µs) by JSON::MaybeXS::BEGIN@5 at line 5 of /opt/flows/lib/lib/perl5/JSON/MaybeXS.pm # once (68µs+9µs) by Class::Method::Modifiers::BEGIN@14 at line 14 of Class/Method/Modifiers.pm # once (66µs+7µs) by Variable::Magic::BEGIN@688 at line 688 of /opt/flows/lib/lib/perl5/x86_64-linux-gnu-thread-multi/Variable/Magic.pm # once (65µs+7µs) by Sub::Quote::BEGIN@10 at line 10 of Sub/Quote.pm # once (62µs+7µs) by Method::Generate::BuildAll::BEGIN@4 at line 4 of Method/Generate/BuildAll.pm # once (61µs+7µs) by Method::Generate::Accessor::BEGIN@5 at line 5 of Method/Generate/Accessor.pm # once (60µs+8µs) by Sub::Name::BEGIN@49 at line 49 of Sub/Name.pm # once (60µs+7µs) by Sub::Defer::BEGIN@4 at line 4 of Sub/Defer.pm # once (59µs+7µs) by Moo::Role::BEGIN@6 at line 6 of Moo/Role.pm # once (58µs+8µs) by Any::URI::Escape::BEGIN@14 at line 14 of /opt/flows/lib/lib/perl5/Any/URI/Escape.pm # once (57µs+8µs) by Method::Generate::Constructor::BEGIN@5 at line 5 of Method/Generate/Constructor.pm # once (56µs+7µs) by Moo::_Utils::BEGIN@15 at line 15 of Moo/_Utils.pm # once (56µs+7µs) by namespace::clean::_Util::BEGIN@15 at line 15 of /opt/flows/lib/lib/perl5/namespace/clean/_Util.pm
sub import {
58147µs my $class = shift;
59
60147µs return SUCCESS unless @_;
61
62 # List of base classes from which we will inherit %FIELDS.
63142µs my $fields_base;
64
651410µs my $inheritor = caller(0);
66
67142µs my @bases;
681414µs foreach my $base (@_) {
69144µs if ( $inheritor eq $base ) {
70 warn "Class '$inheritor' tried to inherit from itself\n";
71 }
72
7314163µs1428µs next if grep $_->isa($base), ($inheritor, @bases);
# spent 28µs making 14 calls to UNIVERSAL::isa, avg 2µs/call
74
75 # Following blocks help isolate $SIG{__DIE__} changes
76 {
77286µs my $sigdie;
78 {
792832µs local $SIG{__DIE__};
8014277µs eval "require $base";
# spent 98µs executing statements in string eval # spent 22µs executing statements in 9 string evals (merged) # spent 7µs executing statements in 3 string evals (merged) # spent 2µs executing statements in string eval
81 # Only ignore "Can't locate" errors from our eval require.
82 # Other fatal errors (syntax etc) must be reported.
83143µs die if $@ && $@ !~ /^Can't locate .*? at \(eval /;
841434µs unless (%{"$base\::"}) {
85 require Carp;
86 local $" = " ";
87 Carp::croak(<<ERROR);
88Base class package "$base" is empty.
89 (Perhaps you need to 'use' the module which defines that package first,
90 or make that module available in \@INC (\@INC contains: @INC).
91ERROR
92 }
931445µs $sigdie = $SIG{__DIE__} || undef;
94 }
95 # Make sure a global $SIG{__DIE__} makes it out of the localization.
96146µs $SIG{__DIE__} = $sigdie if defined $sigdie;
97 }
98149µs push @bases, $base;
99
1001451µs2884µs if ( has_fields($base) || has_attr($base) ) {
# spent 50µs making 14 calls to base::has_fields, avg 4µs/call # spent 33µs making 14 calls to base::has_attr, avg 2µs/call
101 # No multiple fields inheritance *suck*
102 if ($fields_base) {
103 require Carp;
104 Carp::croak("Can't multiply inherit fields");
105 } else {
106 $fields_base = $base;
107 }
108 }
109 }
110 # Save this until the end so it's all or nothing if the above loop croaks.
11114130µs push @{"$inheritor\::ISA"}, @bases;
112
1131462µs if( defined $fields_base ) {
114 inherit_fields($inheritor, $fields_base);
115 }
116}
117
118sub inherit_fields {
119 my($derived, $base) = @_;
120
121 return SUCCESS unless $base;
122
123 my $battr = get_attr($base);
124 my $dattr = get_attr($derived);
125 my $dfields = get_fields($derived);
126 my $bfields = get_fields($base);
127
128 $dattr->[0] = @$battr;
129
130 if( keys %$dfields ) {
131 warn <<"END";
132$derived is inheriting from $base but already has its own fields!
133This will cause problems. Be sure you use base BEFORE declaring fields.
134END
135
136 }
137
138 # Iterate through the base's fields adding all the non-private
139 # ones to the derived class. Hang on to the original attribute
140 # (Public, Private, etc...) and add Inherited.
141 # This is all too complicated to do efficiently with add_fields().
142 while (my($k,$v) = each %$bfields) {
143 my $fno;
144 if ($fno = $dfields->{$k} and $fno != $v) {
145 require Carp;
146 Carp::croak ("Inherited fields can't override existing fields");
147 }
148
149 if( $battr->[$v] & PRIVATE ) {
150 $dattr->[$v] = PRIVATE | INHERITED;
151 }
152 else {
153 $dattr->[$v] = INHERITED | $battr->[$v];
154 $dfields->{$k} = $v;
155 }
156 }
157
158 foreach my $idx (1..$#{$battr}) {
159 next if defined $dattr->[$idx];
160 $dattr->[$idx] = $battr->[$idx] & INHERITED;
161 }
162}
163
16414µs1;
165
166__END__