File Coverage

blib/lib/IPC/Run3/ProfPP.pm
Criterion Covered Total %
statement 39 39 100.0
branch 4 8 50.0
condition 2 6 33.3
subroutine 10 10 100.0
pod 3 3 100.0
total 58 66 87.8


line stmt bran cond sub pod time code
1 1     1   12918 use strict;
  1         6  
  1         45  
2 1     1   5 use warnings;
  1         2  
  1         152  
3             package IPC::Run3::ProfPP;
4              
5             our $VERSION = 0.049;
6              
7             =head1 NAME
8              
9             IPC::Run3::ProfPP - Generate reports from IPC::Run3 profiling data
10              
11             =head1 SYNOPSIS
12              
13             =head1 DESCRIPTION
14              
15             Used by IPC::Run3 and/or run3profpp to print out profiling reports for
16             human readers. Use other classes for extracting data in other ways.
17              
18             The output methods are plain text, override these (see the source for
19             now) to provide other formats.
20              
21             This class generates reports on each run3_exit() and app_exit() call.
22              
23             =cut
24              
25             require IPC::Run3::ProfReporter;
26             our @ISA = qw( IPC::Run3::ProfReporter );
27              
28 1     1   522 use POSIX qw( floor );
  1         8786  
  1         7  
29              
30             =head1 METHODS
31              
32             =head2 C<< IPC::Run3::ProfPP->new() >>
33              
34             Returns a new profile reporting object.
35              
36             =cut
37              
38 11     11   17 sub _emit { shift; warn @_ }
  11         98  
39              
40             sub _t {
41 8     8   96 sprintf "%10.6f secs", @_;
42             }
43              
44             sub _r {
45 3     3   7 my ( $num, $denom ) = @_;
46 3 50       8 return () unless $denom;
47 3         32 sprintf "%10.6f", $num / $denom;
48             }
49              
50             sub _pct {
51 5     5   14 my ( $num, $denom ) = @_;
52 5 50       12 return () unless $denom;
53 5         73 sprintf " (%3d%%)", floor( 100 * $num / $denom + 0.5 );
54             }
55              
56             =head2 C<< $profpp->handle_app_call() >>
57              
58             =cut
59              
60             sub handle_app_call {
61 1     1 1 2 my $self = shift;
62             $self->_emit("IPC::Run3 parent: ",
63 1         3 join( " ", @{$self->get_app_cmd} ),
  1         22  
64             "\n",
65             );
66              
67 1         9 $self->{NeedNL} = 1;
68             }
69              
70             =head2 C<< $profpp->handle_app_exit() >>
71              
72             =cut
73              
74             sub handle_app_exit {
75 1     1 1 3 my $self = shift;
76              
77 1 50 33     10 $self->_emit("\n") if $self->{NeedNL} && $self->{NeedNL} != 1;
78              
79 1         10 $self->_emit( "IPC::Run3 total elapsed: ",
80             _t( $self->get_app_cumulative_time ),
81             "\n");
82 1         11 $self->_emit( "IPC::Run3 calls to run3(): ",
83             sprintf( "%10d", $self->get_run_count ),
84             "\n");
85 1         8 $self->_emit( "IPC::Run3 total spent in run3(): ",
86             _t( $self->get_run_cumulative_time ),
87             _pct( $self->get_run_cumulative_time, $self->get_app_cumulative_time ),
88             ", ",
89             _r( $self->get_run_cumulative_time, $self->get_run_count ),
90             " per call",
91             "\n");
92 1         7 my $exclusive =
93             $self->get_app_cumulative_time - $self->get_run_cumulative_time;
94 1         3 $self->_emit( "IPC::Run3 total spent not in run3(): ",
95             _t( $exclusive ),
96             _pct( $exclusive, $self->get_app_cumulative_time ),
97             "\n");
98 1         10 $self->_emit( "IPC::Run3 total spent in children: ",
99             _t( $self->get_sys_cumulative_time ),
100             _pct( $self->get_sys_cumulative_time, $self->get_app_cumulative_time ),
101             ", ",
102             _r( $self->get_sys_cumulative_time, $self->get_run_count ),
103             " per call",
104             "\n");
105 1         13 my $overhead =
106             $self->get_run_cumulative_time - $self->get_sys_cumulative_time;
107 1         4 $self->_emit( "IPC::Run3 total overhead: ",
108             _t( $overhead ),
109             _pct(
110             $overhead,
111             $self->get_sys_cumulative_time
112             ),
113             ", ",
114             _r( $overhead, $self->get_run_count ),
115             " per call",
116             "\n");
117             }
118              
119             =head2 C<< $profpp->handle_run_exit() >>
120              
121             =cut
122              
123             sub handle_run_exit {
124 1     1 1 3 my $self = shift;
125 1         3 my $overhead = $self->get_run_time - $self->get_sys_time;
126              
127 1 50 33     11 $self->_emit("\n") if $self->{NeedNL} && $self->{NeedNL} != 2;
128 1         7 $self->{NeedNL} = 3;
129              
130             $self->_emit( "IPC::Run3 child: ",
131 1         3 join( " ", @{$self->get_run_cmd} ),
  1         7  
132             "\n");
133 1         6 $self->_emit( "IPC::Run3 run3() : ", _t( $self->get_run_time ), "\n",
134             "IPC::Run3 child : ", _t( $self->get_sys_time ), "\n",
135             "IPC::Run3 overhead: ", _t( $overhead ),
136             _pct( $overhead, $self->get_sys_time ),
137             "\n");
138             }
139              
140             =head1 LIMITATIONS
141              
142             =head1 COPYRIGHT
143              
144             Copyright 2003, R. Barrie Slaymaker, Jr., All Rights Reserved
145              
146             =head1 LICENSE
147              
148             You may use this module under the terms of the BSD, Artistic, or GPL licenses,
149             any version.
150              
151             =head1 AUTHOR
152              
153             Barrie Slaymaker Ebarries@slaysys.comE
154              
155             =cut
156              
157             1;