File Coverage

blib/lib/Benchmark/Harness/Trace.pm
Criterion Covered Total %
statement 21 45 46.6
branch 0 2 0.0
condition 0 2 0.0
subroutine 7 13 53.8
pod 0 1 0.0
total 28 63 44.4


line stmt bran cond sub pod time code
1 1     1   739 use strict;
  1         2  
  1         36  
2 1     1   571 use Benchmark::Harness;
  1         4  
  1         84  
3             package Benchmark::Harness::Trace;
4 1     1   12 use base qw(Benchmark::Harness);
  1         17  
  1         222  
5 1     1   12 use Benchmark::Harness::Constants;
  1         2  
  1         390  
6            
7 1     1   12 use vars qw($VERSION); $VERSION = sprintf("%d.%02d", q$Revision: 1.2 $ =~ /(\d+)\.(\d+)/);
  1         3  
  1         1044  
8            
9             ### ###########################################################################
10             sub Initialize {
11 0     0 0   my $self = Benchmark::Harness::Initialize(@_);
12            
13             # Things we get for the ProcessInfo element:
14             #
15             # W32 Linux attr : meaning
16             # X X 'm' : virtual memory size (kilobytes)
17             # X 'r' : resident set size (kilobytes)
18             # X 'u' : user mode time (milliseconds)
19             # X 's' : kernel mode time (milliseconds)
20             # X 'x' : user + kernal time
21             # ? ? 't' : system time, since process started, from time()
22             # X 'p' : percent cpu used since process started
23            
24 0 0         if ( $^O eq 'MSWin32' ) {
25            
26 0           $self->{XmlTempFilename} = 'C:/TEMP/benchmark_harness';
27 0           eval 'use Win32::Process::Info';
28 0           $self->{procInfo} = Win32::Process::Info->new(undef,'NT');
29            
30             *Benchmark::Harness::Handler::Trace::reportTraceInfo =
31             sub {
32 0     0     my $slf = shift;
33 0           my $proc = ($slf->[HNDLR_HARNESS]->{procInfo}->GetProcInfo({no_user_info=>1},$$))[0];
34 0   0       return Benchmark::Harness::Handler::reportTraceInfo($slf,
35             {
36             'm' => $proc->{WorkingSetSize}/1024,
37             's' => $proc->{KernelModeTime} || '0',
38             't' => (time() - $slf->[HNDLR_HARNESS]->{_startTime}),
39             'u' => $proc->{UserModeTime},
40             }
41             ,@_
42             );
43 0           };
44             }
45             else { # Assume Linux, for now . . .
46            
47 0           $self->{XmlTempFilename} = '/tmp/benchmark_harness';
48            
49             *Benchmark::Harness::Handler::Trace::reportTraceInfo =
50             sub {
51 0     0     my $slf = shift;
52            
53 0           my $ps = `ps -l -p $$`;
54 0           my ($pMem, $pTimeH, $pTimeM, $pTimeS) = ($ps =~ m{CMD(?:\s+\S+){9}\s+(\S+)(?:\s+\S+){2}\s+(\d+):(\d+):(\d+)}s);
55 0           my $pTime = ( $pTimeH*60 + $pTimeM*60 ) + $pTimeS;
56            
57 0           return Benchmark::Harness::Handler::reportTraceInfo($slf,
58             {
59             'm' => $pMem
60             ,'t' => (time() - $slf->[HNDLR_HARNESS]->{_startTime})
61             ,'u' => $pTime
62             }
63             ,@_
64             );
65 0           };
66             }
67 0           return $self;
68             }
69            
70             package Benchmark::Harness::Handler::Trace;
71 1     1   10 use base qw(Benchmark::Harness::Handler);
  1         3  
  1         1226  
72 1     1   7 use strict;
  1         2  
  1         194  
73            
74            
75             =pod
76            
77             =head1 Benchmark::Harness::Trace
78            
79             =head2 SYNOPSIS
80            
81             A harness that records the time and sequence, and simple memory usage
82             of your program, at entries and exits of functions in the target program.
83            
84             See Benchmark::Harness, "Parameters", for instruction on how to configure
85             a test harness, and use 'Trace' as your harness name.
86            
87             =head2 REPORT
88            
89             The report is an XML file with schema you can find in xsd/Trace.xsd,
90             or at http://schemas.benchmark-harness.org/Trace.xsd
91            
92             For example:
93            
94            
95            
96            
97            
98            
99            
100            
101             The @_i attribute is described in L.
102             It identifies the name of the function being traced.
103            
104             @_m will be 'E' or 'X', for entry or exit from the function.
105            
106             @u is the user memory use at that moment, in megabytes.
107            
108             @m is virtual memory size, in megabytes.
109            
110             @s is kernal memory size, in megabytes.
111            
112             @t is time since the Harness started, in seconds.
113            
114             =head2 IMPACT
115            
116             =over 8
117            
118             =item1 MSWin32
119            
120             Approximately 0.7 millisecond per trace.
121            
122             =item1 Linux
123            
124             =back
125            
126             =head2 Available
127            
128             =over 8
129            
130             These process parameters are also available via this code, but are not transferred to the harness report.
131            
132             =item1 MSWin32
133            
134             'Caption',
135             'CommandLine',
136             'CreationClassName',
137             'CreationDate',
138             'CSCreationClassName',
139             'CSName',
140             'Description',
141             'ExecutablePath',
142             'ExecutionState',
143             'Handle',
144             'HandleCount',
145             'InstallDate',
146             'KernelModeTime' => @s
147             'MaximumWorkingSetSize',
148             'MinimumWorkingSetSize',
149             'Name',
150             'OSCreationClassName',
151             'OSName',
152             'OtherOperationCount',
153             'OtherTransferCount',
154             'PageFaults',
155             'PageFileUsage',
156             'ParentProcessId',
157             'PeakPageFileUsage',
158             'PeakVirtualSize',
159             'PeakWorkingSetSize',
160             'Priority',
161             'PrivatePageCount',
162             'ProcessId',
163             'QuotaNonPagedPoolUsage',
164             'QuotaPagedPoolUsage',
165             'QuotaPeakNonPagedPoolUsage',
166             'QuotaPeakPagedPoolUsage',
167             'ReadOperationCount',
168             'ReadTransferCount',
169             'SessionId',
170             'Status',
171             'TerminationDate',
172             'ThreadCount',
173             'UserModeTime' => @u
174             'VirtualSize',
175             'WindowsVersion',
176             'WorkingSetSize' => @m
177             'WriteOperationCount',
178             'WriteTransferCount'
179            
180             =item1 Linux
181            
182             =back
183            
184             =head2 SEE ALSO
185            
186             L
187            
188             =cut
189            
190             ### ###########################################################################
191             sub reportValueInfo {
192 0     0     return Benchmark::Harness::Handler::reportValueInfo(@_);
193             }
194            
195             ### ###########################################################################
196             sub OnSubEntry {
197 0     0     my $self = shift;
198 0           $self->reportTraceInfo();#(shift, caller(1));
199 0           return @_; # return the input arguments unchanged.
200             }
201            
202             ### ###########################################################################
203             sub OnSubExit {
204 0     0     my $self = shift;
205 0           $self->reportTraceInfo();#(shift, caller(1));
206 0           return @_; # return the input arguments unchanged.
207             }
208            
209            
210             ### ###########################################################################
211            
212             =head1 AUTHOR
213            
214             Glenn Wood,
215            
216             =head1 COPYRIGHT
217            
218             Copyright (C) 2004 Glenn Wood. All rights reserved.
219             This program is free software; you can redistribute it and/or
220             modify it under the same terms as Perl itself.
221            
222             =cut
223            
224             1;