File Coverage

blib/lib/IPC/Run3/ProfLogger.pm
Criterion Covered Total %
statement 6 34 17.6
branch 0 6 0.0
condition 0 3 0.0
subroutine 2 6 33.3
pod 4 4 100.0
total 12 53 22.6


line stmt bran cond sub pod time code
1 1     1   13228 use strict;
  1         3  
  1         48  
2 1     1   6 use warnings;
  1         2  
  1         762  
3             package IPC::Run3::ProfLogger;
4              
5             our $VERSION = 0.049;
6              
7             =head1 NAME
8              
9             IPC::Run3::ProfLogger - write profiling data to a log file
10              
11             =head1 SYNOPSIS
12              
13             use IPC::Run3::ProfLogger;
14              
15             my $logger = IPC::Run3::ProfLogger->new; ## write to "run3.out"
16             my $logger = IPC::Run3::ProfLogger->new( Destination => $fn );
17              
18             $logger->app_call( \@cmd, $time );
19              
20             $logger->run_exit( \@cmd1, @times1 );
21             $logger->run_exit( \@cmd1, @times1 );
22              
23             $logger->app_exit( $time );
24              
25             =head1 DESCRIPTION
26              
27             Used by IPC::Run3 to write a profiling log file. Does not
28             generate reports or maintain statistics; its meant to have minimal
29             overhead.
30              
31             Its API is compatible with a tiny subset of the other IPC::Run profiling
32             classes.
33              
34             =cut
35              
36             =head1 METHODS
37              
38             =head2 C<< IPC::Run3::ProfLogger->new( ... ) >>
39              
40             =cut
41              
42             sub new {
43 0 0   0 1   my $class = ref $_[0] ? ref shift : shift;
44 0           my $self = bless { @_ }, $class;
45              
46             $self->{Destination} = "run3.out"
47 0 0 0       unless defined $self->{Destination} && length $self->{Destination};
48              
49 0 0         open PROFILE, ">$self->{Destination}"
50             or die "$!: $self->{Destination}\n";
51 0           binmode PROFILE;
52 0           $self->{FH} = *PROFILE{IO};
53              
54 0           $self->{times} = [];
55 0           return $self;
56             }
57              
58             =head2 C<< $logger->run_exit( ... ) >>
59              
60             =cut
61              
62             sub run_exit {
63 0     0 1   my $self = shift;
64 0           my $fh = $self->{FH};
65             print( $fh
66             join(
67             " ",
68             (
69             map {
70 0           my $s = $_;
71 0           $s =~ s/\\/\\\\/g;
72 0           $s =~ s/ /_/g;
73 0           $s;
74 0           } @{shift()}
75             ),
76             join(
77             ",",
78 0           @{$self->{times}},
  0            
79             @_,
80             ),
81             ),
82             "\n"
83             );
84             }
85              
86             =head2 C<< $logger->app_exit( $arg ) >>
87              
88             =cut
89              
90             sub app_exit {
91 0     0 1   my $self = shift;
92 0           my $fh = $self->{FH};
93 0           print $fh "\\app_exit ", shift, "\n";
94             }
95              
96             =head2 C<< $logger->app_call( $t, @args) >>
97              
98             =cut
99              
100             sub app_call {
101 0     0 1   my $self = shift;
102 0           my $fh = $self->{FH};
103 0           my $t = shift;
104             print( $fh
105             join(
106             " ",
107             "\\app_call",
108             (
109             map {
110 0           my $s = $_;
  0            
111 0           $s =~ s/\\\\/\\/g;
112 0           $s =~ s/ /\\_/g;
113 0           $s;
114             } @_
115             ),
116             $t,
117             ),
118             "\n"
119             );
120             }
121              
122             =head1 LIMITATIONS
123              
124             =head1 COPYRIGHT
125              
126             Copyright 2003, R. Barrie Slaymaker, Jr., All Rights Reserved
127              
128             =head1 LICENSE
129              
130             You may use this module under the terms of the BSD, Artistic, or GPL licenses,
131             any version.
132              
133             =head1 AUTHOR
134              
135             Barrie Slaymaker Ebarries@slaysys.comE
136              
137             =cut
138              
139             1;