← Index
NYTProf Performance Profile   « line view »
For t/optimization.t
  Run on Thu Jan 8 22:47:42 2015
Reported on Thu Jan 8 22:48:06 2015

Filename/home/ss5/perl5/perlbrew/perls/tapper-perl/lib/site_perl/5.16.3/Exception/Class.pm
StatementsExecuted 264 statements in 1.85ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
1111.19ms6.41msException::Class::::BEGIN@10Exception::Class::BEGIN@10
811895µs1.77msException::Class::::_make_subclassException::Class::_make_subclass
111116µs1.90msException::Class::::importException::Class::import
11118µs18µsException::Class::::BEGIN@6Exception::Class::BEGIN@6
11112µs12µsException::Class::::CORE:sortException::Class::CORE:sort (opcode)
81111µs11µsException::Class::::CORE:substException::Class::CORE:subst (opcode)
11111µs41µsException::Class::::BEGIN@11Exception::Class::BEGIN@11
11110µs24µsException::Class::::BEGIN@176Exception::Class::BEGIN@176
11110µs23µsException::Class::::BEGIN@168Exception::Class::BEGIN@168
1119µs22µsException::Class::::BEGIN@46Exception::Class::BEGIN@46
1119µs22µsException::Class::::BEGIN@79Exception::Class::BEGIN@79
1119µs23µsException::Class::::BEGIN@8Exception::Class::BEGIN@8
2118µs8µsException::Class::::CORE:substcontException::Class::CORE:substcont (opcode)
1114µs4µsException::Class::::BEGIN@14Exception::Class::BEGIN@14
0000s0sException::Class::::ClassesException::Class::Classes
0000s0sException::Class::::__ANON__[:170]Exception::Class::__ANON__[:170]
0000s0sException::Class::::_make_parentsException::Class::_make_parents
0000s0sException::Class::::caughtException::Class::caught
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package Exception::Class;
2{
321µs $Exception::Class::VERSION = '1.37';
4}
5
6251µs118µs
# spent 18µs within Exception::Class::BEGIN@6 which was called: # once (18µs+0s) by Iterator::BEGIN@22 at line 6
use 5.008001;
# spent 18µs making 1 call to Exception::Class::BEGIN@6
7
8228µs237µs
# spent 23µs (9+14) within Exception::Class::BEGIN@8 which was called: # once (9µs+14µs) by Iterator::BEGIN@22 at line 8
use strict;
# spent 23µs making 1 call to Exception::Class::BEGIN@8 # spent 14µs making 1 call to strict::import
9
102122µs16.41ms
# spent 6.41ms (1.19+5.23) within Exception::Class::BEGIN@10 which was called: # once (1.19ms+5.23ms) by Iterator::BEGIN@22 at line 10
use Exception::Class::Base;
# spent 6.41ms making 1 call to Exception::Class::BEGIN@10
11241µs272µs
# spent 41µs (11+31) within Exception::Class::BEGIN@11 which was called: # once (11µs+31µs) by Iterator::BEGIN@22 at line 11
use Scalar::Util qw(blessed);
# spent 41µs making 1 call to Exception::Class::BEGIN@11 # spent 31µs making 1 call to Exporter::import
12
131100nsour $BASE_EXC_CLASS;
141121µs14µs
# spent 4µs within Exception::Class::BEGIN@14 which was called: # once (4µs+0s) by Iterator::BEGIN@22 at line 14
BEGIN { $BASE_EXC_CLASS ||= 'Exception::Class::Base'; }
# spent 4µs making 1 call to Exception::Class::BEGIN@14
15
161300nsour %CLASSES;
17
18
# spent 1.90ms (116µs+1.78) within Exception::Class::import which was called: # once (116µs+1.78ms) by Iterator::BEGIN@22 at line 23 of Iterator.pm
sub import {
191500ns my $class = shift;
20
211900ns local $Exception::Class::Caller = caller();
22
231300ns my %c;
24
251100ns my %needs_parent;
2615µs while ( my $subclass = shift ) {
2783µs my $def = ref $_[0] ? shift : {};
2889µs $def->{isa}
29 = $def->{isa}
30 ? ( ref $def->{isa} ? $def->{isa} : [ $def->{isa} ] )
31 : [];
32
3386µs $c{$subclass} = $def;
34 }
35
36 # We need to sort by length because if we check for keys in the
37 # Foo::Bar:: stash, this creates a "Bar::" key in the Foo:: stash!
38MAKE_CLASSES:
39122µs112µs foreach my $subclass ( sort { length $a <=> length $b } keys %c ) {
# spent 12µs making 1 call to Exception::Class::CORE:sort
4084µs my $def = $c{$subclass};
41
42 # We already made this one.
4383µs next if $CLASSES{$subclass};
44
45 {
4610163µs235µs
# spent 22µs (9+13) within Exception::Class::BEGIN@46 which was called: # once (9µs+13µs) by Iterator::BEGIN@22 at line 46
no strict 'refs';
# spent 22µs making 1 call to Exception::Class::BEGIN@46 # spent 13µs making 1 call to strict::unimport
4788µs foreach my $parent ( @{ $def->{isa} } ) {
48714µs unless ( keys %{"$parent\::"} ) {
49 $needs_parent{$subclass} = {
50 parents => $def->{isa},
51 def => $def
52 };
53 next MAKE_CLASSES;
54 }
55 }
56 }
57
58 $class->_make_subclass(
59830µs81.77ms subclass => $subclass,
# spent 1.77ms making 8 calls to Exception::Class::_make_subclass, avg 221µs/call
60 def => $def || {},
61 );
62 }
63
6417µs foreach my $subclass ( keys %needs_parent ) {
65
66 # This will be used to spot circular references.
67 my %seen;
68 $class->_make_parents( \%needs_parent, $subclass, \%seen );
69 }
70}
71
72sub _make_parents {
73 my $class = shift;
74 my $needs = shift;
75 my $subclass = shift;
76 my $seen = shift;
77 my $child = shift; # Just for error messages.
78
792380µs234µs
# spent 22µs (9+12) within Exception::Class::BEGIN@79 which was called: # once (9µs+12µs) by Iterator::BEGIN@22 at line 79
no strict 'refs';
# spent 22µs making 1 call to Exception::Class::BEGIN@79 # spent 12µs making 1 call to strict::unimport
80
81 # What if someone makes a typo in specifying their 'isa' param?
82 # This should catch it. Either it's been made because it didn't
83 # have missing parents OR it's in our hash as needing a parent.
84 # If neither of these is true then the _only_ place it is
85 # mentioned is in the 'isa' param for some other class, which is
86 # not a good enough reason to make a new class.
87 die
88 "Class $subclass appears to be a typo as it is only specified in the 'isa' param for $child\n"
89 unless exists $needs->{$subclass}
90 || $CLASSES{$subclass}
91 || keys %{"$subclass\::"};
92
93 foreach my $c ( @{ $needs->{$subclass}{parents} } ) {
94
95 # It's been made
96 next if $CLASSES{$c} || keys %{"$c\::"};
97
98 die "There appears to be some circularity involving $subclass\n"
99 if $seen->{$subclass};
100
101 $seen->{$subclass} = 1;
102
103 $class->_make_parents( $needs, $c, $seen, $subclass );
104 }
105
106 return if $CLASSES{$subclass} || keys %{"$subclass\::"};
107
108 $class->_make_subclass(
109 subclass => $subclass,
110 def => $needs->{$subclass}{def}
111 );
112}
113
114
# spent 1.77ms (895µs+872µs) within Exception::Class::_make_subclass which was called 8 times, avg 221µs/call: # 8 times (895µs+872µs) by Exception::Class::import at line 59, avg 221µs/call
sub _make_subclass {
11584µs my $class = shift;
116812µs my %p = @_;
117
11883µs my $subclass = $p{subclass};
11982µs my $def = $p{def};
120
12181µs my $isa;
122812µs if ( $def->{isa} ) {
123 $isa = ref $def->{isa} ? join ' ', @{ $def->{isa} } : $def->{isa};
124 }
12582µs $isa ||= $BASE_EXC_CLASS;
126
12782µs my $version_name = 'VERSION';
128
12988µs my $code = <<"EOPERL";
130package $subclass;
131
132use base qw($isa);
133
134our \$$version_name = '1.1';
135
1361;
137
138EOPERL
139
14084µs if ( $def->{description} ) {
141854µs1019µs ( my $desc = $def->{description} ) =~ s/([\\\'])/\\$1/g;
# spent 11µs making 8 calls to Exception::Class::CORE:subst, avg 1µs/call # spent 8µs making 2 calls to Exception::Class::CORE:substcont, avg 4µs/call
14288µs $code .= <<"EOPERL";
143sub description
144{
145 return '$desc';
146}
147EOPERL
148 }
149
15082µs my @fields;
15185µs if ( my $fields = $def->{fields} ) {
152315µs34µs @fields = UNIVERSAL::isa( $fields, 'ARRAY' ) ? @$fields : $fields;
# spent 4µs making 3 calls to UNIVERSAL::isa, avg 2µs/call
153
154 $code
155 .= "sub Fields { return (\$_[0]->SUPER::Fields, "
15639µs . join( ", ", map { "'$_'" } @fields )
157 . ") }\n\n";
158
15932µs foreach my $field (@fields) {
16038µs $code .= sprintf( "sub %s { \$_[0]->{%s} }\n", $field, $field );
161 }
162 }
163
16483µs if ( my $alias = $def->{alias} ) {
165 die "Cannot make alias without caller"
166 unless defined $Exception::Class::Caller;
167
168284µs236µs
# spent 23µs (10+13) within Exception::Class::BEGIN@168 which was called: # once (10µs+13µs) by Iterator::BEGIN@22 at line 168
no strict 'refs';
# spent 23µs making 1 call to Exception::Class::BEGIN@168 # spent 13µs making 1 call to strict::unimport
169 *{"$Exception::Class::Caller\::$alias"}
170 = sub { $subclass->throw(@_) };
171 }
172
17382µs if ( my $defaults = $def->{defaults} ) {
174 $code
175 .= "sub _defaults { return shift->SUPER::_defaults, our \%_DEFAULTS }\n";
1762183µs239µs
# spent 24µs (10+15) within Exception::Class::BEGIN@176 which was called: # once (10µs+15µs) by Iterator::BEGIN@22 at line 176
no strict 'refs';
# spent 24µs making 1 call to Exception::Class::BEGIN@176 # spent 15µs making 1 call to strict::unimport
177 *{"$subclass\::_DEFAULTS"} = {%$defaults};
178 }
179
1808362µs eval $code;
# spent 80µs executing statements in string eval
# includes 12µs spent executing 1 call to 4 subs defined therein. # spent 80µs executing statements in string eval
# includes 12µs spent executing 1 call to 4 subs defined therein. # spent 76µs executing statements in string eval
# includes 12µs spent executing 1 call to 4 subs defined therein. # spent 42µs executing statements in string eval
# includes 12µs spent executing 1 call to 2 subs defined therein. # spent 42µs executing statements in string eval
# includes 12µs spent executing 1 call to 2 subs defined therein. # spent 41µs executing statements in string eval
# includes 12µs spent executing 1 call to 2 subs defined therein. # spent 40µs executing statements in string eval
# includes 12µs spent executing 1 call to 2 subs defined therein. # spent 40µs executing statements in string eval
# includes 12µs spent executing 1 call to 2 subs defined therein.
181
18282µs die $@ if $@;
183
184844µs $CLASSES{$subclass} = 1;
185}
186
187sub caught {
188 my $e = $@;
189
190 return $e unless $_[1];
191
192 return unless blessed($e) && $e->isa( $_[1] );
193 return $e;
194}
195
196sub Classes { sort keys %Exception::Class::CLASSES }
197
19813µs1;
199
200# ABSTRACT: A module that allows you to declare real exception classes in Perl
201
202__END__
 
# spent 12µs within Exception::Class::CORE:sort which was called: # once (12µs+0s) by Exception::Class::import at line 39
sub Exception::Class::CORE:sort; # opcode
# spent 11µs within Exception::Class::CORE:subst which was called 8 times, avg 1µs/call: # 8 times (11µs+0s) by Exception::Class::_make_subclass at line 141, avg 1µs/call
sub Exception::Class::CORE:subst; # opcode
# spent 8µs within Exception::Class::CORE:substcont which was called 2 times, avg 4µs/call: # 2 times (8µs+0s) by Exception::Class::_make_subclass at line 141, avg 4µs/call
sub Exception::Class::CORE:substcont; # opcode