1 package IPC::Run3::ProfReporter;
7 IPC::Run3::ProfReporter - base class for handling profiling data
13 See L<IPC::Run3::ProfPP|IPC::Run3::ProfPP> and for an example subclass.
15 This class just notes and accumulates times; subclasses use methods like
16 "handle_app_call", "handle_run_exit" and "handle_app_exit" to emit reports on
17 it. The default methods for these handlers are noops.
19 If run from the command line, a reporter will be created and run on
20 each logfile given as a command line parameter or on run3.out if none
23 This allows reports to be run like:
25 perl -MIPC::Run3::ProfPP -e1
26 perl -MIPC::Run3::ProfPP -e1 foo.out bar.out
28 Use "-" to read from STDIN (the log file format is meant to be moderately
31 grep "^cvs " run3.out perl -MIPC::Run3::ProfPP -e1 -
33 Use --app to show only application level statistics (ie don't emit
34 a report section for each command run).
48 for ( my $i = 0;; ++$i ) {
54 if ( $caller[0] eq "main"
57 require IPC::Run3::ProfLogReader;
61 Getopt::Long::GetOptions(
66 $app = 1, $run = 1 unless $app || $run;
68 for ( @ARGV ? @ARGV : "" ) {
69 my $r = IPC::Run3::ProfLogReader->new(
71 Handler => $loaded_by->new(
86 =item C<< IPC::Run3::ProfReporter->new >>
88 Returns a new profile reporting object.
93 my $class = ref $_[0] ? ref shift : shift;
94 my $self = bless { @_ }, $class;
95 $self->{app_report} = 1, $self->{run_report} = 1
96 unless $self->{app_report} || $self->{run_report};
101 =item C<< $reporter->handle_app_call( ... ) >>
103 =item C<< $reporter->handle_app_exit( ... ) >>
105 =item C<< $reporter->handle_run_exit( ... ) >>
107 These methods are called by the handled events (see below).
111 sub handle_app_call {}
112 sub handle_app_exit {}
114 sub handle_run_exit {}
116 =item C<< $reporter->app_call(\@cmd, $time) >>
118 =item C<< $reporter->app_exit($time) >>
120 =item C<< $reporter->run_exit(@times) >>
122 $self->app_call( $time );
123 my $time = $self->get_app_call_time;
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.
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
137 ( $self->{app_cmd}, $self->{app_call_time} ) = @_;
138 $self->handle_app_call if $self->{app_report};
143 $self->{app_exit_time} = shift;
144 $self->handle_app_exit if $self->{app_report};
150 run_cmd run_call_time sys_call_time sys_exit_time run_exit_time
153 ++$self->{run_count};
154 $self->{run_cumulative_time} += $self->get_run_time;
155 $self->{sys_cumulative_time} += $self->get_sys_time;
156 $self->handle_run_exit if $self->{run_report};
159 =item C<< $reporter->get_run_count() >>
161 =item C<< $reporter->get_app_call_time() >>
163 =item C<< $reporter->get_app_exit_time() >>
165 =item C<< $reporter->get_app_cmd() >>
167 =item C<< $reporter->get_app_time() >>
171 sub get_run_count { shift->{run_count} }
172 sub get_app_call_time { shift->{app_call_time} }
173 sub get_app_exit_time { shift->{app_exit_time} }
174 sub get_app_cmd { shift->{app_cmd} }
177 $self->get_app_exit_time - $self->get_app_call_time;
180 =item C<< $reporter->get_app_cumulative_time() >>
184 sub get_app_cumulative_time {
186 $self->get_app_exit_time - $self->get_app_call_time;
189 =item C<< $reporter->get_run_call_time() >>
191 =item C<< $reporter->get_run_exit_time() >>
193 =item C<< $reporter->get_run_time() >>
197 sub get_run_call_time { shift->{run_call_time} }
198 sub get_run_exit_time { shift->{run_exit_time} }
201 $self->get_run_exit_time - $self->get_run_call_time;
204 =item C<< $reporter->get_run_cumulative_time() >>
208 sub get_run_cumulative_time { shift->{run_cumulative_time} }
210 =item C<< $reporter->get_sys_call_time() >>
212 =item C<< $reporter->get_sys_exit_time() >>
214 =item C<< $reporter->get_sys_time() >>
218 sub get_sys_call_time { shift->{sys_call_time} }
219 sub get_sys_exit_time { shift->{sys_exit_time} }
222 $self->get_sys_exit_time - $self->get_sys_call_time;
225 =item C<< $reporter->get_sys_cumulative_time() >>
229 sub get_sys_cumulative_time { shift->{sys_cumulative_time} }
231 =item C<< $reporter->get_run_cmd() >>
235 sub get_run_cmd { shift->{run_cmd} }
243 Copyright 2003, R. Barrie Slaymaker, Jr., All Rights Reserved
247 You may use this module under the terms of the BSD, Artistic, or GPL licenses,
252 Barrie Slaymaker <barries@slaysys.com>