Add built local::lib
[catagits/Gitalist.git] / local-lib5 / lib / perl5 / IPC / Run3 / ProfLogger.pm
1 package IPC::Run3::ProfLogger;
2
3 $VERSION = 0.043;
4
5 =head1 NAME
6
7 IPC::Run3::ProfLogger - write profiling data to a log file
8
9 =head1 SYNOPSIS
10
11  use IPC::Run3::ProfLogger;
12
13  my $logger = IPC::Run3::ProfLogger->new;  ## write to "run3.out"
14  my $logger = IPC::Run3::ProfLogger->new( Destination => $fn );
15
16  $logger->app_call( \@cmd, $time );
17
18  $logger->run_exit( \@cmd1, @times1 );
19  $logger->run_exit( \@cmd1, @times1 );
20
21  $logger->app_exit( $time );
22
23 =head1 DESCRIPTION
24
25 Used by IPC::Run3 to write a profiling log file.  Does not
26 generate reports or maintain statistics; its meant to have minimal
27 overhead.
28
29 Its API is compatible with a tiny subset of the other IPC::Run profiling
30 classes.
31
32 =cut
33
34 use strict;
35
36 =head1 METHODS
37
38 =head2 C<< IPC::Run3::ProfLogger->new( ... ) >>
39
40 =cut
41
42 sub new {
43     my $class = ref $_[0] ? ref shift : shift;
44     my $self = bless { @_ }, $class;
45     
46     $self->{Destination} = "run3.out"
47         unless defined $self->{Destination} && length $self->{Destination};
48
49     open PROFILE, ">$self->{Destination}"
50         or die "$!: $self->{Destination}\n";
51     binmode PROFILE;
52     $self->{FH} = *PROFILE{IO};
53
54     $self->{times} = [];
55     return $self;
56 }
57
58 =head2 C<< $logger->run_exit( ... ) >>
59
60 =cut
61
62 sub run_exit {
63     my $self = shift;
64     my $fh = $self->{FH};
65     print( $fh
66         join(
67             " ",
68             (
69                 map {
70                     my $s = $_;
71                     $s =~ s/\\/\\\\/g;
72                     $s =~ s/ /_/g;
73                     $s;
74                 } @{shift()}
75             ),
76             join(
77                 ",",
78                 @{$self->{times}},
79                 @_,
80             ),
81         ),
82         "\n"
83     );
84 }
85
86 =head2 C<< $logger->app_exit( $arg ) >>
87
88 =cut
89
90 sub app_exit {
91     my $self = shift;
92     my $fh = $self->{FH};
93     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     my $self = shift;
102     my $fh = $self->{FH};
103     my $t = shift;
104     print( $fh
105         join(
106             " ",
107             "\\app_call",
108             (
109                 map {
110                     my $s = $_;
111                     $s =~ s/\\\\/\\/g;
112                     $s =~ s/ /\\_/g;
113                     $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 E<lt>barries@slaysys.comE<gt>
136
137 =cut
138
139 1;