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