3 use lib '../../perl/build/lib';
11 open my $fh, "<", $name or return undef;
13 return undef if not defined $line;
14 close $fh or die "cannot close $name: $!";
16 if ($line =~ /^(?:(\d+):)?(\d+):(\d+(?:\.\d+)?) (\d+(?:\.\d+)?) (\d+(?:\.\d+)?)$/) {
17 my $rt = ((defined $1 ? $1 : 0.0)*60+$2)*60+$3;
20 } elsif ($line =~ /^\d+$/) {
23 die "bad input line: $line";
28 my ($r, $firstr) = @_;
30 return sprintf "%+.1f%%", 100.0*($r-$firstr)/$firstr;
39 my ($r, $u, $s, $firstr) = @_;
40 # no value means we did not finish the test
44 # a single value means we have a size, not times
46 return format_size($r, $firstr);
48 # otherwise, we have real/user/system times
49 my $out = sprintf "%.2f(%.2f+%.2f)", $r, $u, $s;
50 $out .= ' ' . relative_change($r, $firstr) if defined $firstr;
56 ./aggregate.perl [options] [--] [<dir_or_rev>...] [--] [<test_script>...] >
59 --codespeed * Format output for Codespeed
60 --reponame <str> * Send given reponame to codespeed
61 --sort-by <str> * Sort output (only "regression" criteria is supported)
62 --subsection <str> * Use results from given subsection
70 my @units = ('', qw(K M G));
71 while ($n > 900 && @units > 1) {
75 return $n unless length $units[0];
76 return sprintf '%.1f%s', $n, $units[0];
80 my ($size, $first) = @_;
81 # match the width of a time: 0.00(0.00+0.00)
82 my $out = sprintf '%15s', human_size($size);
83 $out .= ' ' . relative_change($size, $first) if defined $first;
88 open(my $fh, '-|', @_);
92 my (@dirs, %dirnames, %dirabbrevs, %prefixes, @tests,
93 $codespeed, $sortby, $subsection, $reponame);
95 Getopt::Long::Configure qw/ require_order /;
97 my $rc = GetOptions("codespeed" => \$codespeed,
98 "reponame=s" => \$reponame,
99 "sort-by=s" => \$sortby,
100 "subsection=s" => \$subsection);
103 while (scalar @ARGV) {
107 last if -f $arg or $arg eq "--";
109 my $rev = sane_backticks(qw(git rev-parse --verify), $arg);
111 $dir = "build/".$rev;
112 } elsif ($arg eq '.') {
115 $dir = realpath($arg);
116 $dirnames{$dir} = $dir;
120 $dirnames{$dir} ||= $arg;
122 $prefix =~ tr/^a-zA-Z0-9/_/c;
123 $prefixes{$dir} = $prefix . '.';
130 $dirnames{'.'} = $dirabbrevs{'.'} = "this tree";
133 shift @ARGV if scalar @ARGV and $ARGV[0] eq "--";
137 @tests = glob "p????-*.sh";
140 my $resultsdir = "test-results";
142 if (! $subsection and
143 exists $ENV{GIT_PERF_SUBSECTION} and
144 $ENV{GIT_PERF_SUBSECTION} ne "") {
145 $subsection = $ENV{GIT_PERF_SUBSECTION};
149 $resultsdir .= "/" . $subsection;
155 $t =~ s{(?:.*/)?(p(\d+)-[^/]+)\.sh$}{$1} or die "bad test name: $t";
157 my $fname = "$resultsdir/$t.subtests";
158 open my $fp, "<", $fname or die "cannot open $fname: $!";
161 /^(\d+)$/ or die "malformed subtest line: $_";
162 push @subtests, "$t.$1";
163 $shorttests{"$t.$1"} = "$n.$1";
165 close $fp or die "cannot close $fname: $!";
170 open my $fh, "<", $name or return "<error reading description>";
171 binmode $fh, ":utf8" or die "PANIC on binmode: $!";
173 close $fh or die "cannot close $name";
181 return 1 if exists $seen{$_};
195 return exists $dirabbrevs{$d} ? $dirabbrevs{$d} : $dirnames{$d};
198 sub print_default_results {
200 my $descrlen = 4; # "Test"
201 for my $t (@subtests) {
202 $descrs{$t} = $shorttests{$t}.": ".read_descr("$resultsdir/$t.descr");
203 $descrlen = length $descrs{$t} if length $descrs{$t}>$descrlen;
206 my %newdirabbrevs = %dirabbrevs;
207 while (!have_duplicate(values %newdirabbrevs)) {
208 %dirabbrevs = %newdirabbrevs;
209 last if !have_slash(values %dirabbrevs);
210 %newdirabbrevs = %dirabbrevs;
211 for (values %newdirabbrevs) {
217 my @colwidth = ((0)x@dirs);
218 for my $i (0..$#dirs) {
219 my $w = length display_dir($dirs[$i]);
220 $colwidth[$i] = $w if $w > $colwidth[$i];
222 for my $t (@subtests) {
224 for my $i (0..$#dirs) {
226 my $base = "$resultsdir/$prefixes{$d}$t";
227 $times{$prefixes{$d}.$t} = [get_times("$base.result")];
228 my ($r,$u,$s) = @{$times{$prefixes{$d}.$t}};
229 my $w = length format_times($r,$u,$s,$firstr);
230 $colwidth[$i] = $w if $w > $colwidth[$i];
231 $firstr = $r unless defined $firstr;
234 my $totalwidth = 3*@dirs+$descrlen;
235 $totalwidth += $_ for (@colwidth);
237 printf "%-${descrlen}s", "Test";
238 for my $i (0..$#dirs) {
239 printf " %-$colwidth[$i]s", display_dir($dirs[$i]);
242 print "-"x$totalwidth, "\n";
243 for my $t (@subtests) {
244 printf "%-${descrlen}s", $descrs{$t};
246 for my $i (0..$#dirs) {
248 my ($r,$u,$s) = @{$times{$prefixes{$d}.$t}};
249 printf " %-$colwidth[$i]s", format_times($r,$u,$s,$firstr);
250 $firstr = $r unless defined $firstr;
256 sub print_sorted_results {
259 if ($sortby ne "regression") {
260 print "Only 'regression' is supported as '--sort-by' argument\n";
265 for my $t (@subtests) {
266 my ($prevr, $prevu, $prevs, $prevrev);
267 for my $i (0..$#dirs) {
269 my ($r, $u, $s) = get_times("$resultsdir/$prefixes{$d}$t.result");
270 if ($i > 0 and defined $r and defined $prevr and $prevr > 0) {
271 my $percent = 100.0 * ($r - $prevr) / $prevr;
272 push @evolutions, { "percent" => $percent,
274 "prevrev" => $prevrev,
283 ($prevr, $prevu, $prevs, $prevrev) = ($r, $u, $s, $d);
287 my @sorted_evolutions = sort { $b->{percent} <=> $a->{percent} } @evolutions;
289 for my $e (@sorted_evolutions) {
290 printf "%+.1f%%", $e->{percent};
291 print " " . $e->{test};
292 print " " . format_times($e->{prevr}, $e->{prevu}, $e->{prevs});
293 print " " . format_times($e->{r}, $e->{u}, $e->{s});
294 print " " . display_dir($e->{prevrev});
295 print " " . display_dir($e->{rev});
300 sub print_codespeed_results {
301 my ($subsection) = @_;
305 my $executable = `uname -s -m`;
309 $executable .= ", " . $subsection;
314 $environment = $reponame;
315 } elsif (exists $ENV{GIT_PERF_REPO_NAME} and $ENV{GIT_PERF_REPO_NAME} ne "") {
316 $environment = $ENV{GIT_PERF_REPO_NAME};
318 $environment = `uname -r`;
324 for my $t (@subtests) {
326 my $commitid = $prefixes{$d};
327 $commitid =~ s/^build_//;
328 $commitid =~ s/\.$//;
329 my ($result_value, $u, $s) = get_times("$resultsdir/$prefixes{$d}$t.result");
332 "commitid" => $commitid,
333 "project" => $project,
334 "branch" => $dirnames{$d},
335 "executable" => $executable,
336 "benchmark" => $shorttests{$t} . " " . read_descr("$resultsdir/$t.descr"),
337 "environment" => $environment,
338 "result_value" => $result_value,
345 print JSON::to_json(\@data, {utf8 => 1, pretty => 1, canonical => 1}), "\n";
348 binmode STDOUT, ":utf8" or die "PANIC on binmode: $!";
351 print_codespeed_results($subsection);
352 } elsif (defined $sortby) {
353 print_sorted_results($sortby);
355 print_default_results();