← Index
NYTProf Performance Profile   « block view • line view • sub view »
For mentat.storage.mongo.pl
  Run on Tue Jun 24 09:58:41 2014
Reported on Tue Jun 24 09:59:28 2014

Filename/usr/local/share/perl/5.14.2/Try/Tiny.pm
StatementsExecuted 19083 statements in 18.7ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
706141010.7ms188msTry::Tiny::::try Try::Tiny::try (recurses: max depth 3, inclusive time 161ms)
70614102.19ms2.19msTry::Tiny::::catch Try::Tiny::catch
1112.07ms2.28msTry::Tiny::::BEGIN@14 Try::Tiny::BEGIN@14
11176µs1.32msTry::Tiny::::BEGIN@20 Try::Tiny::BEGIN@20
11127µs27µsTry::Tiny::::BEGIN@8 Try::Tiny::BEGIN@8
11120µs94µsTry::Tiny::ScopeGuard::::BEGIN@146Try::Tiny::ScopeGuard::BEGIN@146
11119µs104µsTry::Tiny::::BEGIN@17 Try::Tiny::BEGIN@17
11117µs17µsTry::Tiny::::BEGIN@2 Try::Tiny::BEGIN@2
11115µs21µsTry::Tiny::::BEGIN@11 Try::Tiny::BEGIN@11
11114µs26µsTry::Tiny::::BEGIN@12 Try::Tiny::BEGIN@12
0000s0sTry::Tiny::ScopeGuard::::DESTROYTry::Tiny::ScopeGuard::DESTROY
0000s0sTry::Tiny::ScopeGuard::::_newTry::Tiny::ScopeGuard::_new
0000s0sTry::Tiny::::__ANON__[:20] Try::Tiny::__ANON__[:20]
0000s0sTry::Tiny::::finally Try::Tiny::finally
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package Try::Tiny;
2
# spent 17µs within Try::Tiny::BEGIN@2 which was called: # once (17µs+0s) by Module::Implementation::BEGIN@13 at line 4
BEGIN {
3110µs $Try::Tiny::AUTHORITY = 'cpan:NUFFIN';
4163µs117µs}
# spent 17µs making 1 call to Try::Tiny::BEGIN@2
5{
623µs $Try::Tiny::VERSION = '0.18';
7}
8289µs127µs
# spent 27µs within Try::Tiny::BEGIN@8 which was called: # once (27µs+0s) by Module::Implementation::BEGIN@13 at line 8
use 5.006;
# spent 27µs making 1 call to Try::Tiny::BEGIN@8
9# ABSTRACT: minimal try/catch with proper preservation of $@
10
11245µs228µs
# spent 21µs (15+7) within Try::Tiny::BEGIN@11 which was called: # once (15µs+7µs) by Module::Implementation::BEGIN@13 at line 11
use strict;
# spent 21µs making 1 call to Try::Tiny::BEGIN@11 # spent 7µs making 1 call to strict::import
12266µs237µs
# spent 26µs (14+12) within Try::Tiny::BEGIN@12 which was called: # once (14µs+12µs) by Module::Implementation::BEGIN@13 at line 12
use warnings;
# spent 26µs making 1 call to Try::Tiny::BEGIN@12 # spent 12µs making 1 call to warnings::import
13
142288µs22.39ms
# spent 2.28ms (2.07+211µs) within Try::Tiny::BEGIN@14 which was called: # once (2.07ms+211µs) by Module::Implementation::BEGIN@13 at line 14
use base 'Exporter';
# spent 2.28ms making 1 call to Try::Tiny::BEGIN@14 # spent 110µs making 1 call to base::import
1514µsour @EXPORT = our @EXPORT_OK = qw(try catch finally);
16
172108µs2189µs
# spent 104µs (19+85) within Try::Tiny::BEGIN@17 which was called: # once (19µs+85µs) by Module::Implementation::BEGIN@13 at line 17
use Carp;
# spent 104µs making 1 call to Try::Tiny::BEGIN@17 # spent 85µs making 1 call to Exporter::import
1812µs$Carp::Internal{+__PACKAGE__}++;
19
201913µs11.32ms
# spent 1.32ms (76µs+1.24) within Try::Tiny::BEGIN@20 which was called: # once (76µs+1.24ms) by Module::Implementation::BEGIN@13 at line 20
BEGIN { eval "use Sub::Name; 1" or *{subname} = sub {1} }
# spent 1.32ms making 1 call to Try::Tiny::BEGIN@20
# spent 226µs executing statements in string eval
# includes 564µs spent executing 1 call to 1 sub defined therein.
21
22# Need to prototype as @ not $$ because of the way Perl evaluates the prototype.
23# Keeping it at $$ means you only ever get 1 sub because we need to eval in a list
24# context & not a scalar one
25
26
# spent 188ms (10.7+177) within Try::Tiny::try which was called 706 times, avg 266µs/call: # 252 times (3.50ms+27.1ms) by Class::MOP::Attribute::_process_accessors at line 401 of Class/MOP/Attribute.pm, avg 122µs/call # 181 times (2.62ms+113ms) by Class::MOP::Class::_post_add_attribute at line 896 of Class/MOP/Class.pm, avg 639µs/call # 83 times (1.38ms+-1.38ms) by Class::MOP::Method::Accessor::_generate_reader_method_inline at line 157 of Class/MOP/Method/Accessor.pm, avg 0s/call # 64 times (999µs+-999µs) by Moose::Meta::Method::Accessor::_compile_code at line 47 of Moose/Meta/Method/Accessor.pm, avg 0s/call # 52 times (913µs+-913µs) by Class::MOP::Method::Accessor::_generate_accessor_method_inline at line 123 of Class/MOP/Method/Accessor.pm, avg 0s/call # 35 times (560µs+25.4ms) by Class::MOP::Method::Constructor::_generate_constructor_method_inline at line 115 of Class/MOP/Method/Constructor.pm, avg 742µs/call # 18 times (271µs+-271µs) by Class::MOP::Method::Accessor::_generate_predicate_method_inline at line 212 of Class/MOP/Method/Accessor.pm, avg 0s/call # 5 times (85µs+96µs) by Moose::Object::DESTROY at line 102 of Moose/Object.pm, avg 36µs/call # 4 times (135µs+11.6ms) by Class::Load::try_load_class at line 183 of Class/Load.pm, avg 2.93ms/call # 3 times (102µs+2.66ms) by Module::Implementation::_load_implementation at line 93 of Module/Implementation.pm, avg 919µs/call # 3 times (48µs+498µs) by Moose::Meta::Method::Destructor::_initialize_body at line 106 of Moose/Meta/Method/Destructor.pm, avg 182µs/call # 3 times (43µs+-43µs) by Class::MOP::Method::Accessor::_generate_writer_method_inline at line 187 of Class/MOP/Method/Accessor.pm, avg 0s/call # 2 times (36µs+-36µs) by Class::MOP::Method::Accessor::_generate_clearer_method_inline at line 237 of Class/MOP/Method/Accessor.pm, avg 0s/call # once (38µs+175µs) by DateTime::set_time_zone at line 2017 of DateTime.pm
sub try (&;@) {
27706406µs my ( $try, @code_refs ) = @_;
28
29 # we need to save this here, the eval block will be in scalar context due
30 # to $failed
31706167µs my $wantarray = wantarray;
32
33 # work around perl bug by explicitly initializing these, due to the likelyhood
34 # this will be used in global destruction (perl rt#119311)
35706193µs my ( $catch, @finally ) = ();
36
37 # find labeled blocks in the argument list.
38 # catch and finally tag the blocks by blessing a scalar reference to them.
39706506µs foreach my $code_ref (@code_refs) {
40
41706833µs if ( ref($code_ref) eq 'Try::Tiny::Catch' ) {
42706117µs croak 'A try() may not be followed by multiple catch() blocks'
43 if $catch;
441412455µs $catch = ${$code_ref};
45 } elsif ( ref($code_ref) eq 'Try::Tiny::Finally' ) {
46 push @finally, ${$code_ref};
47 } else {
48 croak(
49 'try() encountered an unexpected argument ('
50 . ( defined $code_ref ? $code_ref : 'undef' )
51 . ') - perhaps a missing semi-colon before or'
52 );
53 }
54 }
55
56 # FIXME consider using local $SIG{__DIE__} to accumulate all errors. It's
57 # not perfect, but we could provide a list of additional errors for
58 # $catch->();
59
60 # name the blocks if we have Sub::Name installed
61706277µs my $caller = caller;
627063.22ms7061.96ms subname("${caller}::try {...} " => $try);
# spent 1.96ms making 706 calls to Sub::Name::subname, avg 3µs/call
637062.36ms7061.26ms subname("${caller}::catch {...} " => $catch) if $catch;
# spent 1.26ms making 706 calls to Sub::Name::subname, avg 2µs/call
64706434µs subname("${caller}::finally {...} " => $_) foreach @finally;
65
66 # save the value of $@ so we can set $@ back to it in the beginning of the eval
67 # and restore $@ after the eval finishes
68706183µs my $prev_error = $@;
69
70706130µs my ( @ret, $error );
71
72 # failed will be true if the eval dies, because 1 will not be returned
73 # from the eval body
74706414µs my $failed = not eval {
75706104µs $@ = $prev_error;
76
77 # evaluate the try block in the correct context
78706778µs if ( $wantarray ) {
7938µs311.4ms @ret = $try->();
# spent 11.4ms making 3 calls to Class::Load::try {...} , avg 3.79ms/call
80 } elsif ( defined $wantarray ) {
81261311µs261110ms $ret[0] = $try->();
# spent 64.0ms making 158 calls to Class::MOP::Method::Accessor::try {...} , avg 405µs/call # spent 25.2ms making 35 calls to Class::MOP::Method::Constructor::try {...} , avg 721µs/call # spent 20.0ms making 64 calls to Moose::Meta::Method::Accessor::try {...} , avg 312µs/call # spent 482µs making 3 calls to Moose::Meta::Method::Destructor::try {...} , avg 161µs/call # spent 143µs making 1 call to Class::Load::try {...}
82 } else {
83442428µs442214ms $try->();
# spent 112ms making 181 calls to Class::MOP::Class::try {...} , avg 620µs/call # spent 98.9ms making 252 calls to Class::MOP::Attribute::try {...} , avg 393µs/call # spent 2.62ms making 3 calls to Module::Implementation::try {...} , avg 874µs/call # spent 166µs making 1 call to DateTime::try {...} # spent 72µs making 5 calls to Moose::Object::try {...} , avg 14µs/call
84 };
85
86705272µs return 1; # properly set $fail to false
87 };
88
89 # preserve the current error and reset the original value of $@
90706118µs $error = $@;
91706100µs $@ = $prev_error;
92
93 # set up a scope guard to invoke the finally block at the end
94 my @guards =
95706397µs map { Try::Tiny::ScopeGuard->_new($_, $failed ? $error : ()) }
96 @finally;
97
98 # at this point $failed contains a true value if the eval died, even if some
99 # destructor overwrote $@ as the eval was unwinding.
100706153µs if ( $failed ) {
101 # if we got an error, invoke the catch block.
1021500ns if ( $catch ) {
103 # This works like given($error), but is backwards compatible and
104 # sets $_ in the dynamic scope for the body of C<$catch>
10511µs for ($error) {
106111µs134µs return $catch->($error);
# spent 34µs making 1 call to Class::Load::catch {...}
107 }
108
109 # in case when() was used without an explicit return, the C<for>
110 # loop will be aborted and there's no useful return value
111 }
112
113 return;
114 } else {
115 # no failure, $@ is back to what it was, everything is fine
1167051.60ms return $wantarray ? @ret : $ret[0];
117 }
118}
119
120
# spent 2.19ms within Try::Tiny::catch which was called 706 times, avg 3µs/call: # 252 times (747µs+0s) by Class::MOP::Attribute::_process_accessors at line 401 of Class/MOP/Attribute.pm, avg 3µs/call # 181 times (587µs+0s) by Class::MOP::Class::_post_add_attribute at line 896 of Class/MOP/Class.pm, avg 3µs/call # 83 times (227µs+0s) by Class::MOP::Method::Accessor::_generate_reader_method_inline at line 157 of Class/MOP/Method/Accessor.pm, avg 3µs/call # 64 times (182µs+0s) by Moose::Meta::Method::Accessor::_compile_code at line 47 of Moose/Meta/Method/Accessor.pm, avg 3µs/call # 52 times (149µs+0s) by Class::MOP::Method::Accessor::_generate_accessor_method_inline at line 123 of Class/MOP/Method/Accessor.pm, avg 3µs/call # 35 times (113µs+0s) by Class::MOP::Method::Constructor::_generate_constructor_method_inline at line 115 of Class/MOP/Method/Constructor.pm, avg 3µs/call # 18 times (46µs+0s) by Class::MOP::Method::Accessor::_generate_predicate_method_inline at line 212 of Class/MOP/Method/Accessor.pm, avg 3µs/call # 5 times (21µs+0s) by Moose::Object::DESTROY at line 102 of Moose/Object.pm, avg 4µs/call # 4 times (28µs+0s) by Class::Load::try_load_class at line 183 of Class/Load.pm, avg 7µs/call # 3 times (54µs+0s) by Module::Implementation::_load_implementation at line 93 of Module/Implementation.pm, avg 18µs/call # 3 times (15µs+0s) by Moose::Meta::Method::Destructor::_initialize_body at line 106 of Moose/Meta/Method/Destructor.pm, avg 5µs/call # 3 times (8µs+0s) by Class::MOP::Method::Accessor::_generate_writer_method_inline at line 187 of Class/MOP/Method/Accessor.pm, avg 3µs/call # 2 times (6µs+0s) by Class::MOP::Method::Accessor::_generate_clearer_method_inline at line 237 of Class/MOP/Method/Accessor.pm, avg 3µs/call # once (8µs+0s) by DateTime::set_time_zone at line 2017 of DateTime.pm
sub catch (&;@) {
121706441µs my ( $block, @rest ) = @_;
122
123706130µs croak 'Useless bare catch()' unless wantarray;
124
125 return (
1267062.26ms bless(\$block, 'Try::Tiny::Catch'),
127 @rest,
128 );
129}
130
131sub finally (&;@) {
132 my ( $block, @rest ) = @_;
133
134 croak 'Useless bare finally()' unless wantarray;
135
136 return (
137 bless(\$block, 'Try::Tiny::Finally'),
138 @rest,
139 );
140}
141
142{
1431800ns package # hide from PAUSE
144 Try::Tiny::ScopeGuard;
145
1462332µs2168µs
# spent 94µs (20+74) within Try::Tiny::ScopeGuard::BEGIN@146 which was called: # once (20µs+74µs) by Module::Implementation::BEGIN@13 at line 146
use constant UNSTABLE_DOLLARAT => ($] < '5.013002') ? 1 : 0;
# spent 94µs making 1 call to Try::Tiny::ScopeGuard::BEGIN@146 # spent 74µs making 1 call to constant::import
147
148 sub _new {
149 shift;
150 bless [ @_ ];
151 }
152
153 sub DESTROY {
154 my ($code, @args) = @{ $_[0] };
155
156 local $@ if UNSTABLE_DOLLARAT;
157 eval {
158 $code->(@args);
159 1;
160 } or do {
161 warn
162 "Execution of finally() block $code resulted in an exception, which "
163 . '*CAN NOT BE PROPAGATED* due to fundamental limitations of Perl. '
164 . 'Your program will continue as if this event never took place. '
165 . "Original exception text follows:\n\n"
166 . (defined $@ ? $@ : '$@ left undefined...')
167 . "\n"
168 ;
169 }
170 }
171}
172
173__PACKAGE__
174
175110µs__END__