-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_all.pl
executable file
·149 lines (119 loc) · 3.97 KB
/
run_all.pl
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#! /usr/bin/env perl
use feature qw(say);
use strict;
use warnings;
use Cwd;
use Getopt::Long;
use Data::Printer;
use FGB::Common;
use File::pushd ();
use List::Util qw(max shuffle);
use Number::Bytes::Human qw(format_bytes);
use Sys::Info; # can determine number of CPU cores on the local machine.
GetOptions (
"verbose" => \my $verbose, # print info as the simulation proceeds
"check" => \my $check, # check if the correct number of lines were extracted
"single-case=s" => \my $case, # just run this case
"expected=i" => \my $expected_no_lines, # used together with option "check"
) or die("Error in command line arguments\n");
my $param = FGB::Common::get_param();
my $wc_expected = $expected_no_lines; # expected number of output lines
my $tests = get_test_names( $param, $case );
my $file2_size = get_file2_size();
my $num_cpus = Sys::Info->new()->device( CPU => () )->count;
my $run_times = do {
my $pdir = File::pushd::pushd( $param->{test_dir} );
run_cases( $param, $tests, $file2_size, $num_cpus, $verbose, $check, $wc_expected );
};
print_summary( $tests, $run_times );
# Runs all the test cases and returns an array of run times
sub run_cases {
my ( $param, $tests, $file2_size, $num_cpus, $verbose, $check, $wc_expected ) = @_;
my $cmd = 'run.sh';
my @times;
for my $case (@$tests) {
my $pdir = File::pushd::pushd( $case );
say "Running '$case'..";
my $arg = get_cmd_args( $case, $file2_size, $num_cpus, $param );
my $output = `bash -c "{ time -p $cmd $arg; } 2>&1"`;
my ($user, $sys, $real ) = get_run_times( $output );
print_timings( $user, $sys, $real ) if $verbose;
check_output_is_ok( $param, $wc_expected, $verbose, $check );
print "\n" if $verbose;
push @times, $real;
#push @times, $user + $sys; # this is wrong when using Gnu parallel
}
say "Done.\n";
return \@times;
}
sub get_file2_size {
return -s "file2.txt";
}
sub get_cmd_args {
my ( $case, $file2_size, $ncpus, $param ) = @_;
my $arg = '';
if ( ($case eq "gregory1") || ( $case eq "gregory1B" ) ) {
my $block_size = $file2_size / $ncpus;
$arg = Number::Bytes::Human::format_bytes( $block_size );
}
return $arg;
}
sub print_timings {
my ( $user, $sys, $real ) = @_;
say "..finished in $real seconds"
. " ( user: $user, sys: $sys )";
}
sub get_run_times {
my ( $output ) = @_;
my ( $real, $user, $sys ) = $output =~ /^(?:real|user|sys)\s*(\S+)/mg;
return ($user, $sys, $real );
}
sub print_summary {
my ( $tests, $times ) = @_;
my $N = max map length, @$tests;
say "Summary";
say "-------";
my @table = sort { $a->[1] <=> $b->[1] }
map [$tests->[$_], $times->[$_]], 0..$#$tests;
write_results_table( \@table );
printf "%-${N}s : %.4gs\n", $_->[0], $_->[1] for @table;
}
sub write_results_table {
my ( $table ) = @_;
my $fn = 'result_table.txt';
open ( my $fh, '>', $fn ) or die "Could not open file '$fn': $!";
print $fh join "\n", map { join ' ', @$_ } @$table;
close $fh;
}
sub check_output_is_ok {
my ( $param, $expected, $verbose, $check ) = @_;
my $fn = $param->{output_file};
my $count = 0;
open ( my $fh, '<', $fn ) or die "Could not open file '$fn': $!";
$count++ while <$fh>;
close $fh;
if ( $verbose ) {
print "..no of output lines: $count";
if ( $check ) {
my $ok_str = ( $count == $expected ) ? "ok" : "not ok";
print " ( $ok_str )";
}
print "\n";
}
}
sub get_test_names {
my ( $param, $case ) = @_;
my $dir = $param->{test_dir};
my @tests;
if ( defined $case ) {
@tests = ( $case );
}
else {
my $skip = FGB::Common::get_skip_test_names( );
my $curdir = getcwd();
chdir $dir;
@tests = List::Util::shuffle grep { -d && (!exists $skip->{$_}) } <*>;
chdir $curdir;
}
return \@tests;
}