aboutsummaryrefslogtreecommitdiff
path: root/src/runtest
diff options
context:
space:
mode:
Diffstat (limited to 'src/runtest')
-rwxr-xr-xsrc/runtest97
1 files changed, 97 insertions, 0 deletions
diff --git a/src/runtest b/src/runtest
new file mode 100755
index 0000000..33322b1
--- /dev/null
+++ b/src/runtest
@@ -0,0 +1,97 @@
1#!/bin/sh
2#! -*-perl-*-
3eval 'exec perl -x -S $0 ${1+"$@"}'
4 if 0;
5
6use strict;
7use warnings;
8use Getopt::Long qw(:config gnu_getopt no_ignore_case require_order);
9use File::Basename;
10use File::Spec;
11
12my $nsamples = 1; # Number of times to run each test.
13my $c_init = 100; # Initial cache capacity.
14my $c_step = 100; # Cache capacity increment.
15my $c_final = 100; # Final cache capacity.
16my $drop_caches; # Drop system disk caches before each run.
17my $log_file; # Name of the log file.
18
19sub runtest {
20 my ($t_total, $t_open, $t_loop) = (0,0,0);
21
22 my $n;
23 for ($n = 0; $n < $nsamples; $n++) {
24 if ($drop_caches) {
25 system($drop_caches);
26 }
27 open(PH, '-|', @_)
28 or die "can't run ".join(' ', @_).": $!\n";
29 my @inbuf;
30 while (<PH>) {
31 if (chomp) {
32 if (@inbuf == 3) {
33 print shift(@inbuf),"\n";
34 }
35 push @inbuf, $_;
36 } else {
37 print "$_";
38 }
39 }
40 close PH;
41
42 if (@inbuf == 3) {
43 $t_total += $inbuf[0];
44 $t_open += $inbuf[1];
45 $t_loop += $inbuf[2];
46 } else {
47 while (my $s = shift(@inbuf)) {
48 print "$s\n";
49 }
50 die "no timing info\n";
51 }
52 }
53 return ($t_total/$nsamples, $t_open/$nsamples, $t_loop/$nsamples)
54}
55
56GetOptions(
57 'n=n' => \$nsamples,
58 'init|i=n' => \$c_init,
59 'step|s=n' => \$c_step,
60 'final|end|e=n' => \$c_final,
61 'drop-caches|d' => sub {
62 $drop_caches = File::Spec->catfile(dirname($0), 'dropcache');
63 unless (-x $drop_caches) {
64 print STDERR <<EOT;
65$0: the option --drop-caches (-d) requires that the program $drop_caches
66be built, be owned by root, and have the setuid bit set (or the tests be
67run as root). Please, make sure that this is the case and rerun the runtest
68utility.
69EOT
70;
71 exit(1);
72 }
73 },
74 'log-file|l=s' => \$log_file
75) or exit(1);
76
77die "command line missing\n" unless @ARGV;
78
79if ($c_init > $c_final) {
80 $c_init = 10;
81}
82if ($c_step > $c_final - $c_init) {
83 $c_step = 1;
84}
85
86if ($log_file) {
87 open(LOG, '>', $log_file) or die "can't open log file $log_file: $!";
88} else {
89 open(LOG, '>&', 'STDOUT') or die "can't dup STDOUT: $!";
90}
91
92for (my $c = $c_init; $c <= $c_final; $c += $c_step) {
93 my ($t_total, $t_open, $t_loop) = runtest(@ARGV, '-c', $c);
94 printf LOG "%d %.6f %.6f %.6f\n", $c, $t_total, $t_open, $t_loop;
95}
96
97

Return to:

Send suggestions and report system problems to the System administrator.