aboutsummaryrefslogtreecommitdiff
path: root/src/runtest
blob: e11f7c761a20fac58e0e0f59f5364c0ca3e9467a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/bin/sh
#! -*-perl-*-
eval 'exec perl -x -S $0 ${1+"$@"}'
    if 0;

use strict;
use warnings;
use Getopt::Long qw(:config gnu_getopt no_ignore_case require_order);
use File::Basename;
use File::Spec;

my $nsamples = 1;   # Number of times to run each test.
my $c_init = 1;     # Initial cache capacity.
my $c_step = 100;   # Cache capacity increment.
my $c_final = 100;  # Final cache capacity.
my $drop_caches;    # Drop system disk caches before each run.
my $log_file;       # Name of the log file.

use constant {
    AVG   => 0,
    MIN   => 1,
    MAX   => 2
};

sub init_times {
    my ($t) = @_;
    $t->[AVG] = 0;
    $t->[MIN] = 100;
    $t->[MAX] = 0;
}

sub update_times {
    my ($t, $v) = @_;
    $t->[AVG] += $v;
    $t->[MIN] = $v if $t->[MIN] > $v;
    $t->[MAX] = $v if $t->[MAX] < $v;
};

sub runtest {
    use constant {
	TOTAL => 0,
	OPEN  => 1,
	LOOP  => 2
    };
    my @times = ([0,100,0],[0,100,0],[0,100,0]);

    my $n;
    for ($n = 0; $n < $nsamples; $n++) {
	if ($drop_caches) {
	    system($drop_caches);
	}
	open(PH, '-|', @_)
	    or die "can't run ".join(' ', @_).": $!\n";
	my @inbuf;
	while (<PH>) {
	    if (chomp) {
		if (@inbuf == 3) {
		    print shift(@inbuf),"\n";
		}
		push @inbuf, $_;
	    } else {
		print "$_";
	    }
	}
	close PH;

	if (@inbuf == 3) {
	    update_times($times[TOTAL], $inbuf[TOTAL]);
	    update_times($times[OPEN], $inbuf[OPEN]);
	    update_times($times[LOOP], $inbuf[LOOP]);
        } else {
	    while (my $s = shift(@inbuf)) {
		print "$s\n";
	    }
            die "no timing info\n";
        }
    }
    map { $_->[AVG] /= $nsamples; @$_ } @times;
}

GetOptions(
    'n=n' => \$nsamples,
    'init|i=n' => \$c_init,
    'step|s=n' => \$c_step,
    'final|end|e=n' => \$c_final,
    'drop-caches|d' => sub {
	$drop_caches = File::Spec->catfile(dirname($0), 'dropcache');
	unless (-x $drop_caches) {
	    print STDERR <<EOT;
$0: the option --drop-caches (-d) requires that the program $drop_caches
be built, owned by root, and have the setuid bit set (or the tests be
run as root).  Please, make sure that this is the case and rerun the runtest
utility.
EOT
;    
	    exit(1);
	}
    },
    'log-file|l=s' => \$log_file
) or exit(1);

die "command line missing\n" unless @ARGV;

if ($c_init > $c_final) {
    $c_init = 10;
}
if ($c_step > $c_final - $c_init) {
    $c_step = 1;
}

if ($log_file) {
    open(LOG, '>', $log_file) or die "can't open log file $log_file: $!";
} else {
    open(LOG, '>&', 'STDOUT') or die "can't dup STDOUT: $!";
}

for (my $c = $c_init; $c <= $c_final; $c += $c_step) {
    printf LOG "%d ", $c;
    foreach my $t (runtest(@ARGV, '-c', $c)) {
	printf LOG " %.6f", $t;
    }
    print LOG "\n";		
}

    

Return to:

Send suggestions and report system problems to the System administrator.