← 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:23:21 2012

Filename/2home/ss5/perl5/perlbrew/perls/perl-5.12.3/lib/site_perl/5.12.3/Devel/Backtrace.pm
StatementsExecuted 17 statements in 595µs
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
111897µs6.40msDevel::Backtrace::::BEGIN@4Devel::Backtrace::BEGIN@4
11113µs16µsDevel::Backtrace::::BEGIN@2Devel::Backtrace::BEGIN@2
11110µs28µsDevel::Backtrace::::BEGIN@3Devel::Backtrace::BEGIN@3
1119µs54µsDevel::Backtrace::::BEGIN@5Devel::Backtrace::BEGIN@5
1119µs37µsDevel::Backtrace::::BEGIN@7Devel::Backtrace::BEGIN@7
0000s0sDevel::Backtrace::::_adjustskipDevel::Backtrace::_adjustskip
0000s0sDevel::Backtrace::::newDevel::Backtrace::new
0000s0sDevel::Backtrace::::pointDevel::Backtrace::point
0000s0sDevel::Backtrace::::pointsDevel::Backtrace::points
0000s0sDevel::Backtrace::::skipmeDevel::Backtrace::skipme
0000s0sDevel::Backtrace::::skipmysubsDevel::Backtrace::skipmysubs
0000s0sDevel::Backtrace::::to_long_stringDevel::Backtrace::to_long_string
0000s0sDevel::Backtrace::::to_stringDevel::Backtrace::to_string
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package Devel::Backtrace;
2318µs219µs
# spent 16µs (13+3) within Devel::Backtrace::BEGIN@2 which was called: # once (13µs+3µs) by main::BEGIN@24 at line 2
use strict;
# spent 16µs making 1 call to Devel::Backtrace::BEGIN@2 # spent 3µs making 1 call to strict::import
3319µs247µs
# spent 28µs (10+18) within Devel::Backtrace::BEGIN@3 which was called: # once (10µs+18µs) by main::BEGIN@24 at line 3
use warnings;
# spent 28µs making 1 call to Devel::Backtrace::BEGIN@3 # spent 18µs making 1 call to warnings::import
4397µs26.40ms
# spent 6.40ms (897µs+5.50) within Devel::Backtrace::BEGIN@4 which was called: # once (897µs+5.50ms) by main::BEGIN@24 at line 4
use Devel::Backtrace::Point;
# spent 6.40ms making 1 call to Devel::Backtrace::BEGIN@4 # spent 4µs making 1 call to Class::Accessor::import
5327µs2100µs
# spent 54µs (9+45) within Devel::Backtrace::BEGIN@5 which was called: # once (9µs+45µs) by main::BEGIN@24 at line 5
use Carp;
# spent 54µs making 1 call to Devel::Backtrace::BEGIN@5 # spent 45µs making 1 call to Exporter::import
6
73431µs266µs
# spent 37µs (9+28) within Devel::Backtrace::BEGIN@7 which was called: # once (9µs+28µs) by main::BEGIN@24 at line 7
use overload '""' => \&to_string;
# spent 37µs making 1 call to Devel::Backtrace::BEGIN@7 # spent 28µs making 1 call to overload::import
8
9=head1 NAME
10
11Devel::Backtrace - Object-oriented backtrace
12
13=head1 VERSION
14
15This is version 0.12.
16
17=cut
18
191400nsour $VERSION = '0.12';
20
21=head1 SYNOPSIS
22
23 my $backtrace = Devel::Backtrace->new;
24
25 print $backtrace; # use automatic stringification
26 # See EXAMPLES to see what the output might look like
27
28 print $backtrace->point(0)->line;
29
30=head1 METHODS
31
32=head2 Devel::Backtrace->new()
33
34Optional parameters: -start => $start, -format => $format
35
36If only one parameter is given, it will be used as $start.
37
38Constructs a new C<Devel::Backtrace> which is filled with all the information
39C<caller($i)> provides, where C<$i> starts from C<$start>. If no argument is
40given, C<$start> defaults to 0.
41
42If C<$start> is 1 (or higher), the backtrace won't contain the information that
43(and where) Devel::Backtrace::new() was called.
44
45=cut
46
47sub new {
48 my $class = shift;
49 my (@opts) = @_;
50
51 my $start;
52 my %pointopts;
53
54 if (1 == @opts) {
55 $start = shift @opts;
56 }
57 while (my $opt = shift @opts) {
58 if ('-format' eq $opt) {
59 $pointopts{$opt} = shift @opts;
60 } elsif ('-start' eq $opt) {
61 $start = shift @opts;
62 } else {
63 croak "Unknown option $opt";
64 }
65 }
66
67 if (defined $start) {
68 $pointopts{'-skip'} = $start;
69 } else {
70 $start = 0;
71 }
72
73 my @backtrace;
74 for (my $deep = $start; my @caller = caller($deep); ++$deep) {
75 push @backtrace, Devel::Backtrace::Point->new(
76 \@caller,
77 -level => $deep,
78 %pointopts,
79 );
80 }
81
82 return bless \@backtrace, $class;
83}
84
85=head2 $backtrace->point($i)
86
87Returns the i'th tracepoint as a L<Devel::Backtrace::Point> object (see its documentation
88for how to access every bit of information).
89
90Note that the following code snippet will print the information of
91C<caller($start+$i)>:
92
93 print Devel::Backtrace->new($start)->point($i)
94
95=cut
96
97sub point {
98 my $this = shift;
99 my ($i) = @_;
100 return $this->[$i];
101}
102
103=head2 $backtrace->points()
104
105Returns a list of all tracepoints. In scalar context, the number of
106tracepoints is returned.
107
108=cut
109
110sub points {
111 my $this = shift;
112 return @$this;
113}
114
115=head2 $backtrace->skipme([$package])
116
117This method deletes all leading tracepoints that contain information about calls
118within C<$package>. Afterwards the C<$backtrace> will look as though it had
119been created with a higher value of C<$start>.
120
121If the optional parameter C<$package> is not given, it defaults to the calling
122package.
123
124The effect is similar to what the L<Carp> module does.
125
126This module ships with an example "skipme.pl" that demonstrates how to use this
127method. See also L</EXAMPLES>.
128
129=cut
130
131sub skipme {
132 my $this = shift;
133 my $package = @_ ? $_[0] : caller;
134
135 my $skip = 0;
136 my $skipped;
137 while (@$this and $package eq $this->point(0)->package) {
138 $skipped = shift @$this;
139 $skip++;
140 }
141 $this->_adjustskip($skip);
142 return $skipped;
143}
144
145sub _adjustskip {
146 my ($this, $newskip) = @_;
147
148 $_->_skip($newskip + ($_->_skip || 0)) for $this->points;
149}
150
151=head2 $backtrace->skipmysubs([$package])
152
153This method is like C<skipme> except that it deletes calls I<to> the package
154rather than calls I<from> the package.
155
156Before discarding those calls, C<skipme> is called. This is because usually
157the topmost call in the stack is to Devel::Backtrace->new, which would not be
158catched by C<skipmysubs> otherwise.
159
160This means that skipmysubs usually deletes more lines than skipme would.
161
162C<skipmysubs> was added in Devel::Backtrace version 0.06.
163
164See also L</EXAMPLES> and the example "skipme.pl".
165
166=cut
167
168sub skipmysubs {
169 my $this = shift;
170 my $package = @_ ? $_[0] : caller;
171
172 my $skipped = $this->skipme($package);
173 my $skip = 0;
174 while (@$this and $package eq $this->point(0)->called_package) {
175 $skipped = shift @$this;
176 $skip++;
177 }
178 $this->_adjustskip($skip);
179 return $skipped;
180}
181
182=head2 $backtrace->to_string()
183
184Returns a string that contains one line for each tracepoint. It will contain
185the information from C<Devel::Backtrace::Point>'s to_string() method. To get
186more information, use the to_long_string() method.
187
188Note that you don't have to call to_string() if you print a C<Devel::Backtrace>
189object or otherwise treat it as a string, as the stringification operator is
190overloaded.
191
192See L</EXAMPLES>.
193
194=cut
195
196sub to_string {
197 my $this = shift;
198 return join '', map "$_\n", $this->points;
199}
200
201
202=head2 $backtrace->to_long_string()
203
204Returns a very long string that contains several lines for each trace point.
205The result will contain every available bit of information. See
206L<Devel::Backtrace::Point/to_long_string> for an example of what the result
207looks like.
208
209=cut
210
211sub to_long_string {
212 my $this = shift;
213 return join "\n", map $_->to_long_string, $this->points;
214}
215
216
21713µs1
218__END__