← Index
NYTProf Performance Profile   « block view • line view • sub view »
For xt/tapper-mcp-scheduler-with-db-longrun.t
  Run on Tue May 22 17:18:39 2012
Reported on Tue May 22 17:24:04 2012

Filename/2home/ss5/perl5/perlbrew/perls/perl-5.12.3/lib/5.12.3/Class/Struct.pm
StatementsExecuted 369 statements in 1.52ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
111737µs798µsClass::Struct::::struct Class::Struct::struct
11165µs65µsClass::Struct::::BEGIN@5 Class::Struct::BEGIN@5
11113µs20µsClass::Struct::::BEGIN@7 Class::Struct::BEGIN@7
11112µs143µsClass::Struct::::import Class::Struct::import
1119µs85µsClass::Struct::::BEGIN@8 Class::Struct::BEGIN@8
1119µs66µsClass::Struct::::BEGIN@11 Class::Struct::BEGIN@11
1117µs24µsClass::Struct::::BEGIN@99 Class::Struct::BEGIN@99
1117µs15µsClass::Struct::::BEGIN@108 Class::Struct::BEGIN@108
1116µs14µsClass::Struct::::BEGIN@188 Class::Struct::BEGIN@188
1116µs6µsClass::Struct::Tie_ISA::::TIEARRAYClass::Struct::Tie_ISA::TIEARRAY
13112µs2µsClass::Struct::::CORE:match Class::Struct::CORE:match (opcode)
0000s0sClass::Struct::Tie_ISA::::DESTROYClass::Struct::Tie_ISA::DESTROY
0000s0sClass::Struct::Tie_ISA::::FETCHClass::Struct::Tie_ISA::FETCH
0000s0sClass::Struct::Tie_ISA::::FETCHSIZEClass::Struct::Tie_ISA::FETCHSIZE
0000s0sClass::Struct::Tie_ISA::::STOREClass::Struct::Tie_ISA::STORE
0000s0sClass::Struct::::_subclass_error Class::Struct::_subclass_error
0000s0sClass::Struct::::_usage_error Class::Struct::_usage_error
0000s0sClass::Struct::::printem Class::Struct::printem
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package Class::Struct;
2
3## See POD after __END__
4
5373µs165µs
# spent 65µs within Class::Struct::BEGIN@5 which was called: # once (65µs+0s) by File::stat::BEGIN@174 at line 5
use 5.006_001;
# spent 65µs making 1 call to Class::Struct::BEGIN@5
6
7321µs226µs
# spent 20µs (13+7) within Class::Struct::BEGIN@7 which was called: # once (13µs+7µs) by File::stat::BEGIN@174 at line 7
use strict;
# spent 20µs making 1 call to Class::Struct::BEGIN@7 # spent 7µs making 1 call to strict::import
8343µs2162µs
# spent 85µs (9+76) within Class::Struct::BEGIN@8 which was called: # once (9µs+76µs) by File::stat::BEGIN@174 at line 8
use warnings::register;
# spent 85µs making 1 call to Class::Struct::BEGIN@8 # spent 76µs making 1 call to warnings::register::import
91600nsour(@ISA, @EXPORT, $VERSION);
10
113343µs2123µs
# spent 66µs (9+57) within Class::Struct::BEGIN@11 which was called: # once (9µs+57µs) by File::stat::BEGIN@174 at line 11
use Carp;
# spent 66µs making 1 call to Class::Struct::BEGIN@11 # spent 57µs making 1 call to Exporter::import
12
131600nsrequire Exporter;
14110µs@ISA = qw(Exporter);
151500ns@EXPORT = qw(struct);
16
171400ns$VERSION = '0.63';
18
19## Tested on 5.002 and 5.003 without class membership tests:
2012µsmy $CHECK_CLASS_MEMBERSHIP = ($] >= 5.003_95);
21
221300nsmy $print = 0;
23sub printem {
24 if (@_) { $print = shift }
25 else { $print++ }
26}
27
28{
291800ns package Class::Struct::Tie_ISA;
30
31
# spent 6µs within Class::Struct::Tie_ISA::TIEARRAY which was called: # once (6µs+0s) by Class::Struct::struct at line 103
sub TIEARRAY {
321600ns my $class = shift;
3318µs return bless [], $class;
34 }
35
36 sub STORE {
37 my ($self, $index, $value) = @_;
38 Class::Struct::_subclass_error();
39 }
40
41 sub FETCH {
42 my ($self, $index) = @_;
43 $self->[$index];
44 }
45
46 sub FETCHSIZE {
47 my $self = shift;
48 return scalar(@$self);
49 }
50
51 sub DESTROY { }
52}
53
54
# spent 143µs (12+131) within Class::Struct::import which was called: # once (12µs+131µs) by File::stat::BEGIN@174 at line 174 of File/stat.pm
sub import {
551400ns my $self = shift;
56
5719µs132µs if ( @_ == 0 ) {
# spent 32µs making 1 call to Exporter::export_to_level
58 $self->export_to_level( 1, $self, @EXPORT );
59 } elsif ( @_ == 1 ) {
60 # This is admittedly a little bit silly:
61 # do we ever export anything else than 'struct'...?
62 $self->export_to_level( 1, $self, @_ );
63 } else {
64 goto &struct;
65 }
66}
67
68
# spent 798µs (737+61) within Class::Struct::struct which was called: # once (737µs+61µs) by IO::Dir::BEGIN@18 at line 176 of File/stat.pm
sub struct {
69
70 # Determine parameter list structure, one of:
71 # struct( class => [ element-list ])
72 # struct( class => { element-list })
73 # struct( element-list )
74 # Latter form assumes current package name as struct name.
75
761300ns my ($class, @decls);
7711µs my $base_type = ref $_[1];
781600ns if ( $base_type eq 'HASH' ) {
79 $class = shift;
80 @decls = %{shift()};
81 _usage_error() if @_;
82 }
83 elsif ( $base_type eq 'ARRAY' ) {
841400ns $class = shift;
8518µs @decls = @{shift()};
861300ns _usage_error() if @_;
87 }
88 else {
89 $base_type = 'ARRAY';
90 $class = (caller())[0];
91 @decls = @_;
92 }
93
9412µs _usage_error() if @decls % 2 == 1;
95
96 # Ensure we are not, and will not be, a subclass.
97
981600ns my $isa = do {
99350µs241µs
# spent 24µs (7+17) within Class::Struct::BEGIN@99 which was called: # once (7µs+17µs) by File::stat::BEGIN@174 at line 99
no strict 'refs';
# spent 24µs making 1 call to Class::Struct::BEGIN@99 # spent 17µs making 1 call to strict::unimport
10013µs \@{$class . '::ISA'};
101 };
1021400ns _subclass_error() if @$isa;
10315µs16µs tie @$isa, 'Class::Struct::Tie_ISA';
# spent 6µs making 1 call to Class::Struct::Tie_ISA::TIEARRAY
104
105 # Create constructor.
106
107 croak "function 'new' already defined in package $class"
1085380µs222µs
# spent 15µs (7+8) within Class::Struct::BEGIN@108 which was called: # once (7µs+8µs) by File::stat::BEGIN@174 at line 108
if do { no strict 'refs'; defined &{$class . "::new"} };
# spent 15µs making 1 call to Class::Struct::BEGIN@108 # spent 8µs making 1 call to strict::unimport
109
1101400ns my @methods = ();
1111500ns my %refs = ();
1121500ns my %arrays = ();
1131400ns my %hashes = ();
1141400ns my %classes = ();
1151200ns my $got_class = 0;
1161200ns my $out = '';
117
11811µs $out = "{\n package $class;\n use Carp;\n sub new {\n";
1191300ns $out .= " my (\$class, \%init) = \@_;\n";
1201400ns $out .= " \$class = __PACKAGE__ unless \@_;\n";
121
1221200ns my $cnt = 0;
1231200ns my $idx = 0;
1241200ns my( $cmt, $name, $type, $elem );
125
1261700ns if( $base_type eq 'HASH' ){
127 $out .= " my(\$r) = {};\n";
128 $cmt = '';
129 }
130 elsif( $base_type eq 'ARRAY' ){
131 $out .= " my(\$r) = [];\n";
132 }
13311µs while( $idx < @decls ){
134134µs $name = $decls[$idx];
135135µs $type = $decls[$idx+1];
136135µs push( @methods, $name );
137135µs if( $base_type eq 'HASH' ){
138 $elem = "{'${class}::$name'}";
139 }
140 elsif( $base_type eq 'ARRAY' ){
141135µs $elem = "[$cnt]";
142132µs ++$cnt;
143134µs $cmt = " # $name";
144 }
1451322µs132µs if( $type =~ /^\*(.)/ ){
# spent 2µs making 13 calls to Class::Struct::CORE:match, avg 192ns/call
146 $refs{$name}++;
147 $type = $1;
148 }
149138µs my $init = "defined(\$init{'$name'}) ? \$init{'$name'} :";
1501313µs if( $type eq '@' ){
151 $out .= " croak 'Initializer for $name must be array reference'\n";
152 $out .= " if defined(\$init{'$name'}) && ref(\$init{'$name'}) ne 'ARRAY';\n";
153 $out .= " \$r->$elem = $init [];$cmt\n";
154 $arrays{$name}++;
155 }
156 elsif( $type eq '%' ){
157 $out .= " croak 'Initializer for $name must be hash reference'\n";
158 $out .= " if defined(\$init{'$name'}) && ref(\$init{'$name'}) ne 'HASH';\n";
159 $out .= " \$r->$elem = $init {};$cmt\n";
160 $hashes{$name}++;
161 }
162 elsif ( $type eq '$') {
163 $out .= " \$r->$elem = $init undef;$cmt\n";
164 }
165 elsif( $type =~ /^\w+(?:::\w+)*$/ ){
166 $out .= " if (defined(\$init{'$name'})) {\n";
167 $out .= " if (ref \$init{'$name'} eq 'HASH')\n";
168 $out .= " { \$r->$elem = $type->new(\%{\$init{'$name'}}) } $cmt\n";
169 $out .= " elsif (UNIVERSAL::isa(\$init{'$name'}, '$type'))\n";
170 $out .= " { \$r->$elem = \$init{'$name'} } $cmt\n";
171 $out .= " else { croak 'Initializer for $name must be hash or $type reference' }\n";
172 $out .= " }\n";
173 $classes{$name} = $type;
174 $got_class = 1;
175 }
176 else{
177 croak "'$type' is not a valid struct element type";
178 }
179137µs $idx += 2;
180 }
1811300ns $out .= " bless \$r, \$class;\n }\n";
182
183 # Create accessor methods.
184
1851200ns my( $pre, $pst, $sel );
1861200ns $cnt = 0;
1871600ns foreach $name (@methods){
18829331µs222µs
# spent 14µs (6+8) within Class::Struct::BEGIN@188 which was called: # once (6µs+8µs) by File::stat::BEGIN@174 at line 188
if ( do { no strict 'refs'; defined &{$class . "::$name"} } ) {
# spent 14µs making 1 call to Class::Struct::BEGIN@188 # spent 8µs making 1 call to strict::unimport
189 warnings::warnif("function '$name' already defined, overrides struct accessor method");
190 }
191 else {
192134µs $pre = $pst = $cmt = $sel = '';
193132µs if( defined $refs{$name} ){
194 $pre = "\\(";
195 $pst = ")";
196 $cmt = " # returns ref";
197 }
198138µs $out .= " sub $name {$cmt\n my \$r = shift;\n";
199134µs if( $base_type eq 'ARRAY' ){
200134µs $elem = "[$cnt]";
201132µs ++$cnt;
202 }
203 elsif( $base_type eq 'HASH' ){
204 $elem = "{'${class}::$name'}";
205 }
206134µs if( defined $arrays{$name} ){
207 $out .= " my \$i;\n";
208 $out .= " \@_ ? (\$i = shift) : return \$r->$elem;\n";
209 $out .= " if (ref(\$i) eq 'ARRAY' && !\@_) { \$r->$elem = \$i; return \$r }\n";
210 $sel = "->[\$i]";
211 }
212 elsif( defined $hashes{$name} ){
213 $out .= " my \$i;\n";
214 $out .= " \@_ ? (\$i = shift) : return \$r->$elem;\n";
215 $out .= " if (ref(\$i) eq 'HASH' && !\@_) { \$r->$elem = \$i; return \$r }\n";
216 $sel = "->{\$i}";
217 }
218 elsif( defined $classes{$name} ){
219 if ( $CHECK_CLASS_MEMBERSHIP ) {
220 $out .= " croak '$name argument is wrong class' if \@_ && ! UNIVERSAL::isa(\$_[0], '$classes{$name}');\n";
221 }
222 }
223136µs $out .= " croak 'Too many args to $name' if \@_ > 1;\n";
2241315µs $out .= " \@_ ? ($pre\$r->$elem$sel = shift$pst) : $pre\$r->$elem$sel$pst;\n";
225133µs $out .= " }\n";
226 }
227 }
2281200ns $out .= "}\n1;\n";
229
2301200ns print $out if $print;
231169µs my $result = eval $out;
# spent 488µs executing statements in string eval
# includes 15µs spent executing 1 call to 15 subs defined therein.
23216µs carp $@ if $@;
233}
234
235sub _usage_error {
236 confess "struct usage error";
237}
238
239sub _subclass_error {
240 croak 'struct class cannot be a subclass (@ISA not allowed)';
241}
242
24316µs1; # for require
244
245
246__END__
 
# spent 2µs within Class::Struct::CORE:match which was called 13 times, avg 192ns/call: # 13 times (2µs+0s) by Class::Struct::struct at line 145, avg 192ns/call
sub Class::Struct::CORE:match; # opcode