diff options
Diffstat (limited to 'src/runtest')
-rwxr-xr-x | src/runtest | 97 |
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-*- | ||
3 | eval 'exec perl -x -S $0 ${1+"$@"}' | ||
4 | if 0; | ||
5 | |||
6 | use strict; | ||
7 | use warnings; | ||
8 | use Getopt::Long qw(:config gnu_getopt no_ignore_case require_order); | ||
9 | use File::Basename; | ||
10 | use File::Spec; | ||
11 | |||
12 | my $nsamples = 1; # Number of times to run each test. | ||
13 | my $c_init = 100; # Initial cache capacity. | ||
14 | my $c_step = 100; # Cache capacity increment. | ||
15 | my $c_final = 100; # Final cache capacity. | ||
16 | my $drop_caches; # Drop system disk caches before each run. | ||
17 | my $log_file; # Name of the log file. | ||
18 | |||
19 | sub 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 | |||
56 | GetOptions( | ||
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 | ||
66 | be built, be owned by root, and have the setuid bit set (or the tests be | ||
67 | run as root). Please, make sure that this is the case and rerun the runtest | ||
68 | utility. | ||
69 | EOT | ||
70 | ; | ||
71 | exit(1); | ||
72 | } | ||
73 | }, | ||
74 | 'log-file|l=s' => \$log_file | ||
75 | ) or exit(1); | ||
76 | |||
77 | die "command line missing\n" unless @ARGV; | ||
78 | |||
79 | if ($c_init > $c_final) { | ||
80 | $c_init = 10; | ||
81 | } | ||
82 | if ($c_step > $c_final - $c_init) { | ||
83 | $c_step = 1; | ||
84 | } | ||
85 | |||
86 | if ($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 | |||
92 | for (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 | |||