Run3/ProfReporter.pm

filter: Statementstmt 86.6% 52 / 60 Branchbran 44.4% 8 / 18 Conditioncond 22.2% 2 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 100% 26 / 26 Podpod 100% 22 / 22 totaltotal 78.0% 110 / 141 CC 14 SCAR 18.7
CC
14
Cov
71%
END
25.0
new
4.8
app_call
2.0
CRAP 6.5
« Run3/ProfLogReader.pm ↑ Summary Run3/ProfPP.pm »
1 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 package IPC::Run3::ProfReporter;
4  
5 2 our $VERSION = 0.049;
6  
7 =head1 NAME
8  
9 IPC::Run3::ProfReporter - base class for handling profiling data
10  
11 =head1 SYNOPSIS
12  
13 =head1 DESCRIPTION
14  
15 See L<IPC::Run3::ProfPP|IPC::Run3::ProfPP> and for an example subclass.
16  
17 This class just notes and accumulates times; subclasses use methods like
18 "handle_app_call", "handle_run_exit" and "handle_app_exit" to emit reports on
19 it. The default methods for these handlers are noops.
20  
21 If run from the command line, a reporter will be created and run on
22 each logfile given as a command line parameter or on run3.out if none
23 are given.
24  
25 This allows reports to be run like:
26  
27 perl -MIPC::Run3::ProfPP -e1
28 perl -MIPC::Run3::ProfPP -e1 foo.out bar.out
29  
30 Use "-" to read from STDIN (the log file format is meant to be moderately
31 greppable):
32  
33 grep "^cvs " run3.out perl -MIPC::Run3::ProfPP -e1 -
34  
35 Use --app to show only application level statistics (ie don't emit
36 a report section for each command run).
37  
38 =cut
39  
40 2 my $loaded_by;
41  
42 2 ▶sub import {
Subroutine import: called CC=1 SCAR=0.0
43 2 $loaded_by = shift;
44 }
45  
46 2 ▶END {
Subroutine END: called CC=8 SCAR=32.2
47 2 my @caller;
48 2 for ( my $i = 0;; ++$i ) {
49 6 my @c = caller $i;
50 6 ▶ last unless @c;
Branch: 1 branch
BranchTrueFalseTotal
unless @c 2 4 6
51 4 @caller = @c;
52 }
53  
54 2 ▶ if ( $caller[0] eq "main"
Branch: 1 branch
BranchTrueFalseTotal
if ($caller[0] eq "main" and $caller[1] eq "-e") 0 2 2
Condition33%1/3
$caller[0] eq "main" and $caller[1] eq "-e"
!ll&&!rl&&r
020
MC/DC0%0/2
$caller[0] eq "main" and $caller[1] eq "-e"
$caller[0] eq "main" $caller[1] eq "-e"
Truth table33%1/3
A and B
A= $caller[0] eq "main"B= $caller[1] eq "-e"
ABresult
0X0
100
111
55 && $caller[1] eq "-e"
56 ) {
57 0 require IPC::Run3::ProfLogReader;
58 0 require Getopt::Long;
59 0 my ( $app, $run );
60  
61 0 Getopt::Long::GetOptions(
62 "app" => \$app,
63 "run" => \$run,
64 );
65  
66 0 ▶ $app = 1, $run = 1 unless $app || $run;
Branch: 1 branch
BranchTrueFalseTotal
unless $app or $run 0 0 0
Condition0%0/3
$app or $run
l!l&&r!l&&!r
000
MC/DC0%0/2
$app or $run
$app $run
Truth table0%0/3
A or B
A= $appB= $run
ABresult
1X1
011
000
67  
68 0 ▶ for ( @ARGV ? @ARGV : "" ) {
Branch: 1 branch
BranchTrueFalseTotal
@ARGV ? : 0 0 0
69 0 my $r = IPC::Run3::ProfLogReader->new(
70 Source => $_,
71 Handler => $loaded_by->new(
72 Source => $_,
73 app_report => $app,
74 run_report => $run,
75 ),
76 );
77 0 $r->read_all;
78 }
79 }
80 }
81  
82 =head1 METHODS
83  
84 =over
85  
86 =item C<< IPC::Run3::ProfReporter->new >>
87  
88 Returns a new profile reporting object.
89  
90 =cut
91  
92 2 ▶sub new {
Subroutine new: called CC=4 SCAR=15.6
Pod documented
93 2 ▶ my $class = ref $_[0] ? ref shift : shift;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 0 2 2
94 2 my $self = bless { @_ }, $class;
95 $self->{app_report} = 1, $self->{run_report} = 1
96 2 ▶ unless $self->{app_report} || $self->{run_report};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"app_report"} or $self->{"run_report"} 2 0 2
Condition33%1/3
$self->{"app_report"} or $self->{"run_report"}
l!l&&r!l&&!r
002
MC/DC0%0/2
$self->{"app_report"} or $self->{"run_report"}
$self->{"app_report"} $self->{"run_report"}
Truth table33%1/3
A or B
A= $self->{"app_report"}B= $self->{"run_report"}
ABresult
1X1
011
000
97  
98 2 return $self;
99 }
100  
101 =item C<< $reporter->handle_app_call( ... ) >>
102  
103 =item C<< $reporter->handle_app_exit( ... ) >>
104  
105 =item C<< $reporter->handle_run_exit( ... ) >>
106  
107 These methods are called by the handled events (see below).
108  
109 =cut
110  
111 1 ▶sub handle_app_call {}
Subroutine handle_app_call: called CC=1 SCAR=0.0
Pod documented
112 1 ▶sub handle_app_exit {}
Subroutine handle_app_exit: called CC=1 SCAR=0.0
Pod documented
113  
114 1 ▶sub handle_run_exit {}
Subroutine handle_run_exit: called CC=1 SCAR=0.0
Pod documented
115  
116 =item C<< $reporter->app_call(\@cmd, $time) >>
117  
118 =item C<< $reporter->app_exit($time) >>
119  
120 =item C<< $reporter->run_exit(@times) >>
121  
122 $self->app_call( $time );
123 my $time = $self->get_app_call_time;
124  
125 Sets the time (in floating point seconds) when the application, run3(),
126 or system() was called or exited. If no time parameter is passed, uses
127 IPC::Run3's time routine.
128  
129 Use get_...() to retrieve these values (and _accum values, too). This
130 is a separate method to speed the execution time of the setters just a
131 bit.
132  
133 =cut
134  
135 2 ▶sub app_call {
Subroutine app_call: called CC=2 SCAR=7.1
Pod documented
136 2 my $self = shift;
137 2 ( $self->{app_cmd}, $self->{app_call_time} ) = @_;
138 2 ▶ $self->handle_app_call if $self->{app_report};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"app_report"} 2 0 2
139 }
140  
141 2 ▶sub app_exit {
Subroutine app_exit: called CC=2 SCAR=7.1
Pod documented
142 2 my $self = shift;
143 2 $self->{app_exit_time} = shift;
144 2 ▶ $self->handle_app_exit if $self->{app_report};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"app_report"} 2 0 2
145 }
146  
147 2 ▶sub run_exit {
Subroutine run_exit: called CC=2 SCAR=7.0
Pod documented
148 2 my $self = shift;
149 2 @{$self}{qw(
150 run_cmd run_call_time sys_call_time sys_exit_time run_exit_time
151 )} = @_;
152  
153 2 ++$self->{run_count};
154 2 $self->{run_cumulative_time} += $self->get_run_time;
155 2 $self->{sys_cumulative_time} += $self->get_sys_time;
156 2 ▶ $self->handle_run_exit if $self->{run_report};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"run_report"} 2 0 2
157 }
158  
159 =item C<< $reporter->get_run_count() >>
160  
161 =item C<< $reporter->get_app_call_time() >>
162  
163 =item C<< $reporter->get_app_exit_time() >>
164  
165 =item C<< $reporter->get_app_cmd() >>
166  
167 =item C<< $reporter->get_app_time() >>
168  
169 =cut
170  
171 4 ▶sub get_run_count { shift->{run_count} }
Subroutine get_run_count: called CC=1 SCAR=0.0
Pod documented
172 8 ▶sub get_app_call_time { shift->{app_call_time} }
Subroutine get_app_call_time: called CC=1 SCAR=0.0
Pod documented
173 8 ▶sub get_app_exit_time { shift->{app_exit_time} }
Subroutine get_app_exit_time: called CC=1 SCAR=0.0
Pod documented
174 1 ▶sub get_app_cmd { shift->{app_cmd} }
Subroutine get_app_cmd: called CC=1 SCAR=0.0
Pod documented
175 1 ▶sub get_app_time {
Subroutine get_app_time: called CC=1 SCAR=0.0
Pod documented
176 1 my $self = shift;
177 1 $self->get_app_exit_time - $self->get_app_call_time;
178 }
179  
180 =item C<< $reporter->get_app_cumulative_time() >>
181  
182 =cut
183  
184 6 ▶sub get_app_cumulative_time {
Subroutine get_app_cumulative_time: called CC=1 SCAR=0.0
Pod documented
185 6 my $self = shift;
186 6 $self->get_app_exit_time - $self->get_app_call_time;
187 }
188  
189 =item C<< $reporter->get_run_call_time() >>
190  
191 =item C<< $reporter->get_run_exit_time() >>
192  
193 =item C<< $reporter->get_run_time() >>
194  
195 =cut
196  
197 5 ▶sub get_run_call_time { shift->{run_call_time} }
Subroutine get_run_call_time: called CC=1 SCAR=0.0
Pod documented
198 4 ▶sub get_run_exit_time { shift->{run_exit_time} }
Subroutine get_run_exit_time: called CC=1 SCAR=0.0
Pod documented
199 4 ▶sub get_run_time {
Subroutine get_run_time: called CC=1 SCAR=0.0
Pod documented
200 4 my $self = shift;
201 4 $self->get_run_exit_time - $self->get_run_call_time;
202 }
203  
204 =item C<< $reporter->get_run_cumulative_time() >>
205  
206 =cut
207  
208 5 ▶sub get_run_cumulative_time { shift->{run_cumulative_time} }
Subroutine get_run_cumulative_time: called CC=1 SCAR=0.0
Pod documented
209  
210 =item C<< $reporter->get_sys_call_time() >>
211  
212 =item C<< $reporter->get_sys_exit_time() >>
213  
214 =item C<< $reporter->get_sys_time() >>
215  
216 =cut
217  
218 6 ▶sub get_sys_call_time { shift->{sys_call_time} }
Subroutine get_sys_call_time: called CC=1 SCAR=0.0
Pod documented
219 5 ▶sub get_sys_exit_time { shift->{sys_exit_time} }
Subroutine get_sys_exit_time: called CC=1 SCAR=0.0
Pod documented
220 5 ▶sub get_sys_time {
Subroutine get_sys_time: called CC=1 SCAR=0.0
Pod documented
221 5 my $self = shift;
222 5 $self->get_sys_exit_time - $self->get_sys_call_time;
223 }
224  
225 =item C<< $reporter->get_sys_cumulative_time() >>
226  
227 =cut
228  
229 5 ▶sub get_sys_cumulative_time { shift->{sys_cumulative_time} }
Subroutine get_sys_cumulative_time: called CC=1 SCAR=0.0
Pod documented
230  
231 =item C<< $reporter->get_run_cmd() >>
232  
233 =cut
234  
235 1 ▶sub get_run_cmd { shift->{run_cmd} }
Subroutine get_run_cmd: called CC=1 SCAR=0.0
Pod documented
236  
237 =back
238  
239 =head1 LIMITATIONS
240  
241 =head1 COPYRIGHT
242  
243 Copyright 2003, R. Barrie Slaymaker, Jr., All Rights Reserved
244  
245 =head1 LICENSE
246  
247 You may use this module under the terms of the BSD, Artistic, or GPL licenses,
248 any version.
249  
250 =head1 AUTHOR
251  
252 Barrie Slaymaker <barries@slaysys.com>
253  
254 =cut
255  
256 2 1;
« Run3/ProfLogReader.pm ↑ Summary Run3/ProfPP.pm »