3 use lib '../../perl/build/lib';
12 open my $fh, "<", $name or return undef;
14 return undef if not defined $line;
15 close $fh or die "cannot close $name: $!";
17 if ($line =~ /^(?:(\d+):)?(\d+):(\d+(?:\.\d+)?) (\d+(?:\.\d+)?) (\d+(?:\.\d+)?)$/) {
18 my $rt = ((defined $1 ? $1 : 0.0)*60+$2)*60+$3;
21 } elsif ($line =~ /^\d+$/) {
24 die "bad input line: $line";
29 my ($r, $firstr) = @_;
31 return sprintf "%+.1f%%", 100.0*($r-$firstr)/$firstr;
40 my ($r, $u, $s, $firstr) = @_;
41 # no value means we did not finish the test
45 # a single value means we have a size, not times
47 return format_size($r, $firstr);
49 # otherwise, we have real/user/system times
50 my $out = sprintf "%.2f(%.2f+%.2f)", $r, $u, $s;
51 $out .= ' ' . relative_change($r, $firstr) if defined $firstr;
57 ./aggregate.perl [options] [--] [<dir_or_rev>...] [--] [<test_script>...] >
60 --codespeed * Format output for Codespeed
61 --reponame <str> * Send given reponame to codespeed
62 --sort-by <str> * Sort output (only "regression" criteria is supported)
63 --subsection <str> * Use results from given subsection
71 my @units = ('', qw(K M G));
72 while ($n > 900 && @units > 1) {
76 return $n unless length $units[0];
77 return sprintf '%.1f%s', $n, $units[0];
81 my ($size, $first) = @_;
82 # match the width of a time: 0.00(0.00+0.00)
83 my $out = sprintf '%15s', human_size($size);
84 $out .= ' ' . relative_change($size, $first) if defined $first;
88 my (@dirs, %dirnames, %dirabbrevs, %prefixes, @tests,
89 $codespeed, $sortby, $subsection, $reponame);
91 Getopt::Long::Configure qw/ require_order /;
93 my $rc = GetOptions("codespeed" => \$codespeed,
94 "reponame=s" => \$reponame,
95 "sort-by=s" => \$sortby,
96 "subsection=s" => \$subsection);
99 while (scalar @ARGV) {
103 last if -f $arg or $arg eq "--";
105 my $rev = Git::command_oneline(qw(rev-parse --verify), $arg);
106 $dir = "build/".$rev;
107 } elsif ($arg eq '.') {
110 $dir = realpath($arg);
111 $dirnames{$dir} = $dir;
115 $dirnames{$dir} ||= $arg;
117 $prefix =~ tr/^a-zA-Z0-9/_/c;
118 $prefixes{$dir} = $prefix . '.';
125 $dirnames{'.'} = $dirabbrevs{'.'} = "this tree";
128 shift @ARGV if scalar @ARGV and $ARGV[0] eq "--";
132 @tests = glob "p????-*.sh";
135 my $resultsdir = "test-results";
137 if (! $subsection and
138 exists $ENV{GIT_PERF_SUBSECTION} and
139 $ENV{GIT_PERF_SUBSECTION} ne "") {
140 $subsection = $ENV{GIT_PERF_SUBSECTION};
144 $resultsdir .= "/" . $subsection;
150 $t =~ s{(?:.*/)?(p(\d+)-[^/]+)\.sh$}{$1} or die "bad test name: $t";
152 my $fname = "$resultsdir/$t.subtests";
153 open my $fp, "<", $fname or die "cannot open $fname: $!";
156 /^(\d+)$/ or die "malformed subtest line: $_";
157 push @subtests, "$t.$1";
158 $shorttests{"$t.$1"} = "$n.$1";
160 close $fp or die "cannot close $fname: $!";
165 open my $fh, "<", $name or return "<error reading description>";
166 binmode $fh, ":utf8" or die "PANIC on binmode: $!";
168 close $fh or die "cannot close $name";
176 return 1 if exists $seen{$_};
190 return exists $dirabbrevs{$d} ? $dirabbrevs{$d} : $dirnames{$d};
193 sub print_default_results {
195 my $descrlen = 4; # "Test"
196 for my $t (@subtests) {
197 $descrs{$t} = $shorttests{$t}.": ".read_descr("$resultsdir/$t.descr");
198 $descrlen = length $descrs{$t} if length $descrs{$t}>$descrlen;
201 my %newdirabbrevs = %dirabbrevs;
202 while (!have_duplicate(values %newdirabbrevs)) {
203 %dirabbrevs = %newdirabbrevs;
204 last if !have_slash(values %dirabbrevs);
205 %newdirabbrevs = %dirabbrevs;
206 for (values %newdirabbrevs) {
212 my @colwidth = ((0)x@dirs);
213 for my $i (0..$#dirs) {
214 my $w = length display_dir($dirs[$i]);
215 $colwidth[$i] = $w if $w > $colwidth[$i];
217 for my $t (@subtests) {
219 for my $i (0..$#dirs) {
221 my $base = "$resultsdir/$prefixes{$d}$t";
222 $times{$prefixes{$d}.$t} = [get_times("$base.result")];
223 my ($r,$u,$s) = @{$times{$prefixes{$d}.$t}};
224 my $w = length format_times($r,$u,$s,$firstr);
225 $colwidth[$i] = $w if $w > $colwidth[$i];
226 $firstr = $r unless defined $firstr;
229 my $totalwidth = 3*@dirs+$descrlen;
230 $totalwidth += $_ for (@colwidth);
232 printf "%-${descrlen}s", "Test";
233 for my $i (0..$#dirs) {
234 printf " %-$colwidth[$i]s", display_dir($dirs[$i]);
237 print "-"x$totalwidth, "\n";
238 for my $t (@subtests) {
239 printf "%-${descrlen}s", $descrs{$t};
241 for my $i (0..$#dirs) {
243 my ($r,$u,$s) = @{$times{$prefixes{$d}.$t}};
244 printf " %-$colwidth[$i]s", format_times($r,$u,$s,$firstr);
245 $firstr = $r unless defined $firstr;
251 sub print_sorted_results {
254 if ($sortby ne "regression") {
255 print "Only 'regression' is supported as '--sort-by' argument\n";
260 for my $t (@subtests) {
261 my ($prevr, $prevu, $prevs, $prevrev);
262 for my $i (0..$#dirs) {
264 my ($r, $u, $s) = get_times("$resultsdir/$prefixes{$d}$t.result");
265 if ($i > 0 and defined $r and defined $prevr and $prevr > 0) {
266 my $percent = 100.0 * ($r - $prevr) / $prevr;
267 push @evolutions, { "percent" => $percent,
269 "prevrev" => $prevrev,
278 ($prevr, $prevu, $prevs, $prevrev) = ($r, $u, $s, $d);
282 my @sorted_evolutions = sort { $b->{percent} <=> $a->{percent} } @evolutions;
284 for my $e (@sorted_evolutions) {
285 printf "%+.1f%%", $e->{percent};
286 print " " . $e->{test};
287 print " " . format_times($e->{prevr}, $e->{prevu}, $e->{prevs});
288 print " " . format_times($e->{r}, $e->{u}, $e->{s});
289 print " " . display_dir($e->{prevrev});
290 print " " . display_dir($e->{rev});
295 sub print_codespeed_results {
296 my ($subsection) = @_;
300 my $executable = `uname -s -m`;
304 $executable .= ", " . $subsection;
309 $environment = $reponame;
310 } elsif (exists $ENV{GIT_PERF_REPO_NAME} and $ENV{GIT_PERF_REPO_NAME} ne "") {
311 $environment = $ENV{GIT_PERF_REPO_NAME};
313 $environment = `uname -r`;
319 for my $t (@subtests) {
321 my $commitid = $prefixes{$d};
322 $commitid =~ s/^build_//;
323 $commitid =~ s/\.$//;
324 my ($result_value, $u, $s) = get_times("$resultsdir/$prefixes{$d}$t.result");
327 "commitid" => $commitid,
328 "project" => $project,
329 "branch" => $dirnames{$d},
330 "executable" => $executable,
331 "benchmark" => $shorttests{$t} . " " . read_descr("$resultsdir/$t.descr"),
332 "environment" => $environment,
333 "result_value" => $result_value,
340 print JSON::to_json(\@data, {utf8 => 1, pretty => 1, canonical => 1}), "\n";
343 binmode STDOUT, ":utf8" or die "PANIC on binmode: $!";
346 print_codespeed_results($subsection);
347 } elsif (defined $sortby) {
348 print_sorted_results($sortby);
350 print_default_results();