2 # ***********************************************************************
4 # * Copyright (c) 2002-2006, International Business Machines Corporation
5 # * and others. All Rights Reserved.
6 # ***********************************************************************
16 my $start_l = ""; #formatting help
18 my @testArgs; # different kinds of tests we want to do
20 my $extraArgs; # stuff that always gets passed to the test program
26 my $ITERATIONS; #Added by Doug
30 my %options = %{shift @_};
32 if($options{"time"}) {
33 $TIME = $options{"time"};
36 if($options{"passes"}) {
37 $NUMPASSES = $options{"passes"};
40 if($options{"dataDir"}) {
41 $DATADIR = $options{"dataDir"};
45 if ($options{"iterations"}) {
46 $ITERATIONS = $options{"iterations"};
51 debug("Enter runTest in PerfFramework4j\n");
56 if($#_ >= 0) { # maybe no files/locales
57 my $datafiles = shift;
59 %datafiles = %{$datafiles};
62 setupOutput($options);
63 setupOptions($options);
65 my($locale, $iter, $data, $program, $args, $variable);
67 # Outer loop runs through the locales to test
70 foreach $locale (sort keys %datafiles ) {
71 foreach $data (@{ $datafiles{$locale} }) {
74 if(!($locale eq "")) {
75 $locdata = "<b>Locale:</b> $locale<br>";
77 $locdata .= "<b>Datafile:</b> $data<br>";
81 compareLoop ($tests, $locale, $DATADIR."/".$data);
83 compareLoop ($tests, $locale, $data);
94 #debug("enter compareLoop\n");
97 #debug("tests $tests");
98 #my @tests = @{$tests};
99 my %tests = %{$tests};
100 #debug("tests $tests");
102 my $datafile = shift;
105 $locAndData .= " -L $locale";
109 $locAndData .= " -f $datafile";
114 foreach $i ( sort keys %tests ) {
115 #debug("Test: $i\n");
124 for $j ( 0 .. $#{$aref} ) {
125 # first we calibrate. Use time from somewhere
126 # first test is used for calibration
128 # ($program, @argsAndTest) = split(/\ /, @{ $tests{$i} }[$j]);
132 # $commandLine = "$program -i $ITERATIONS -p $NUMPASSES $locAndData @argsAndTest";
134 # $commandLine = "$program -t $TIME -p $NUMPASSES $locAndData @argsAndTest";
136 ######################
137 ######################
139 my $testCommand = @{ $tests{$i} }[$j];
140 if ($testCommand =~/--/) {
141 $custArgs = $& . $'; #The matched part and the right part
142 $testCommand = $`; #The left part for furthur processing
143 } else { $custArgs = ''; }
144 ($program, @argsAndTest) = split(/\ /, $testCommand);
147 $commandLine = "$program @argsAndTest -i $ITERATIONS -p $NUMPASSES $locAndData $custArgs";
149 $commandLine = "$program @argsAndTest -t $TIME -p $NUMPASSES $locAndData $custArgs";
151 #debug("custArgs:$custArgs\n");
154 my @res = measure1($commandLine);
155 store("$i, $program @argsAndTest", @res);
157 push(@iterPerPass, shift(@res));
158 push(@noopers, shift(@res));
159 my @data = @{ shift(@res) };
161 push(@noevents, shift(@res));
165 shift(@data) if (@data > 1); # discard first run
167 #debug("data is @data\n");
168 my $ds = Dataset->new(@data);
170 push(@timedata, $ds);
173 outputRow($i, \@iterPerPass, \@noopers, \@timedata, \@noevents);
178 #---------------------------------------------------------------------
179 # Measure a given test method with a give test pattern using the
180 # global run parameters.
182 # @param the method to run
183 # @param the pattern defining characters to test
184 # @param if >0 then the number of iterations per pass. If <0 then
185 # (negative of) the number of seconds per pass.
188 # [0] iterations per pass
189 # [1] events per iteration
190 # [2..] ms reported for each pass, in order
194 my @t = callProg(shift); #"$program $args $argsAndTest");
198 # $a->[0]: method name, corresponds to $method
199 # $a->[1]: 'begin' data, == $iterCount
200 # $a->[2]: 'end' data, of the form <ms> <eventsPerIter>
201 # $a->[3...]: gc messages from JVM during pass
202 @b = split(/\s+/, $a->[2]);
204 push(@ms, shift(@b));
206 my $iterCount = shift(@b);
207 my $operationsPerIter = shift(@b);
210 $eventsPerIter = shift(@b);
213 # out("Iterations per pass: $iterCount<BR>\n");
214 # out("Events per iteration: $eventsPerIter<BR>\n");
215 # debug("Iterations per pass: $iterCount<BR>\n");
216 # if($eventsPerIter) {
217 # debug("Events per iteration: $eventsPerIter<BR>\n");
221 $ms_str[0] .= " (discarded)" if (@ms_str > 1);
222 # out("Raw times (ms/pass): ", join(", ", @ms_str), "<BR>\n");
223 debug("Raw times (ms/pass): ", join(", ", @ms_str), "<BR>\n");
225 ($iterCount, $operationsPerIter, \@ms, $eventsPerIter);
227 ($iterCount, $operationsPerIter, \@ms);
233 #---------------------------------------------------------------------
234 # Measure a given test method with a give test pattern using the
235 # global run parameters.
237 # @param the method to run
238 # @param the pattern defining characters to test
239 # @param if >0 then the number of iterations per pass. If <0 then
240 # (negative of) the number of seconds per pass.
242 # @return a Dataset object, scaled by iterations per pass and
243 # events per iteration, to give time per event
246 my @res = measure1(@_);
247 my $iterPerPass = shift(@res);
248 my $operationsPerIter = shift(@res);
249 my @data = @{ shift(@res) };
250 my $eventsPerIter = shift(@res);
253 shift(@data) if (@data > 1); # discard first run
255 my $ds = Dataset->new(@data);
256 #$ds->setScale(1.0e-3 / ($iterPerPass * $operationsPerIter));
257 ($ds, $iterPerPass, $operationsPerIter, $eventsPerIter);
261 #---------------------------------------------------------------------
262 # Invoke program and capture results, passing it the given parameters.
264 # @param the method to run
265 # @param the number of iterations, or if negative, the duration
266 # in seconds. If more than on pass is desired, pass in
267 # a string, e.g., "100 100 100".
268 # @param the pattern defining characters to test
270 # @return an array of results. Each result is an array REF
271 # describing one pass. The array REF contains:
272 # ->[0]: The method name as reported
273 # ->[1]: The params on the '= <meth> begin ...' line
274 # ->[2]: The params on the '= <meth> end ...' line
275 # ->[3..]: GC messages from the JVM, if any
282 #my $cmd = "java -cp c:\\dev\\myicu4j\\classes $TESTCLASS $method $n $pat";
283 debug( "[$cmd]\n"); # for debugging
284 open(PIPE, "$cmd|") or die "Can't run \"$cmd\"";
289 close(PIPE) or die "Program failed: \"$cmd\"";
291 @out = grep(!/^\#/, @out); # filter out comments
293 #debug( "[", join("\n", @out), "]\n");
301 if (/^=\s*(\w+)\s*(\w+)\s*(.*)/) {
302 my ($m, $state, $d) = ($1, $2, $3);
303 #debug ("$_ => [[$m $state !!!$d!!! $data ]]\n");
304 if ($state eq 'begin') {
305 die "$method was begun but not finished" if ($method);
308 push(@$data, ''); # placeholder for end data
309 } elsif ($state eq 'end') {
311 die "$method end does not match: $_";
313 $data->[1] = $d; # insert end data at [1]
314 #debug( "#$method:", join(";",@$data), "\n");
315 unshift(@$data, $method); # add method to start
316 push(@results, $data);
320 die "Can't parse: $_";
328 # ignore extraneous GC notices
333 die "Can't parse: $_";
337 die "$method was begun but not finished" if ($method);
345 foreach $message (@_) {
346 print STDERR "$message";
352 #Added here, was global
353 my $CALIBRATE = 2; # duration in seconds for initial calibration
357 my $iterCount = shift; # actually might be -seconds/pass
359 out("<P>Measuring $method using $pat, ");
360 if ($iterCount > 0) {
361 out("$iterCount iterations/pass, $NUMPASSES passes</P>\n");
363 out(-$iterCount, " seconds/pass, $NUMPASSES passes</P>\n");
366 # is $iterCount actually -seconds?
367 if ($iterCount < 0) {
369 # calibrate: estimate ms/iteration
370 print "Calibrating...";
371 my @t = callJava($method, $pat, -$CALIBRATE);
374 my @data = split(/\s+/, $t[0]->[2]);
375 my $timePerIter = 1.0e-3 * $data[0] / $data[2];
377 # determine iterations/pass
378 $iterCount = int(-$iterCount / $timePerIter + 0.5);
380 out("<P>Calibration pass ($CALIBRATE sec): ");
381 out("$data[0] ms, ");
382 out("$data[2] iterations = ");
383 out(formatSeconds(4, $timePerIter), "/iteration<BR>\n");
387 print "Measuring $iterCount iterations x $NUMPASSES passes...";
388 my @t = callJava($method, $pat, "$iterCount " x $NUMPASSES);
393 # $a->[0]: method name, corresponds to $method
394 # $a->[1]: 'begin' data, == $iterCount
395 # $a->[2]: 'end' data, of the form <ms> <eventsPerIter>
396 # $a->[3...]: gc messages from JVM during pass
397 @b = split(/\s+/, $a->[2]);
400 my $eventsPerIter = $b[1];
402 out("Iterations per pass: $iterCount<BR>\n");
403 out("Events per iteration: $eventsPerIter<BR>\n");
406 $ms_str[0] .= " (discarded)" if (@ms_str > 1);
407 out("Raw times (ms/pass): ", join(", ", @ms_str), "<BR>\n");
409 ($iterCount, $eventsPerIter, @ms);