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: $!";
15 $line =~ /^(?:(\d+):)?(\d+):(\d+(?:\.\d+)?) (\d+(?:\.\d+)?) (\d+(?:\.\d+)?)$/
16 or die "bad input line: $line";
17 my $rt = ((defined $1 ? $1 : 0.0)*60+$2)*60+$3;
22 my ($r, $u, $s, $firstr) = @_;
26 my $out = sprintf "%.2f(%.2f+%.2f)", $r, $u, $s;
27 if (defined $firstr) {
29 $out .= sprintf " %+.1f%%", 100.0*($r-$firstr)/$firstr;
39 my (@dirs, %dirnames, %dirabbrevs, %prefixes, @tests,
40 $codespeed, $sortby, $subsection, $reponame);
41 while (scalar @ARGV) {
44 if ($arg eq "--codespeed") {
49 if ($arg =~ /--sort-by(?:=(.*))?/) {
54 $sortby = shift @ARGV;
55 if (! defined $sortby) {
56 die "'--sort-by' requires an argument";
61 if ($arg eq "--subsection") {
63 $subsection = $ARGV[0];
66 die "empty subsection";
70 if ($arg eq "--reponame") {
79 last if -f $arg or $arg eq "--";
81 my $rev = Git::command_oneline(qw(rev-parse --verify), $arg);
86 $dirabbrevs{$dir} = $dir;
89 $dirnames{$dir} = $arg;
91 $prefix =~ tr/^a-zA-Z0-9/_/c;
92 $prefixes{$dir} = $prefix . '.';
99 $dirnames{'.'} = $dirabbrevs{'.'} = "this tree";
102 shift @ARGV if scalar @ARGV and $ARGV[0] eq "--";
106 @tests = glob "p????-*.sh";
109 my $resultsdir = "test-results";
111 if (! $subsection and
112 exists $ENV{GIT_PERF_SUBSECTION} and
113 $ENV{GIT_PERF_SUBSECTION} ne "") {
114 $subsection = $ENV{GIT_PERF_SUBSECTION};
118 $resultsdir .= "/" . $subsection;
124 $t =~ s{(?:.*/)?(p(\d+)-[^/]+)\.sh$}{$1} or die "bad test name: $t";
126 my $fname = "$resultsdir/$t.subtests";
127 open my $fp, "<", $fname or die "cannot open $fname: $!";
130 /^(\d+)$/ or die "malformed subtest line: $_";
131 push @subtests, "$t.$1";
132 $shorttests{"$t.$1"} = "$n.$1";
134 close $fp or die "cannot close $fname: $!";
139 open my $fh, "<", $name or return "<error reading description>";
140 binmode $fh, ":utf8" or die "PANIC on binmode: $!";
142 close $fh or die "cannot close $name";
150 return 1 if exists $seen{$_};
164 return exists $dirabbrevs{$d} ? $dirabbrevs{$d} : $dirnames{$d};
167 sub print_default_results {
169 my $descrlen = 4; # "Test"
170 for my $t (@subtests) {
171 $descrs{$t} = $shorttests{$t}.": ".read_descr("$resultsdir/$t.descr");
172 $descrlen = length $descrs{$t} if length $descrs{$t}>$descrlen;
175 my %newdirabbrevs = %dirabbrevs;
176 while (!have_duplicate(values %newdirabbrevs)) {
177 %dirabbrevs = %newdirabbrevs;
178 last if !have_slash(values %dirabbrevs);
179 %newdirabbrevs = %dirabbrevs;
180 for (values %newdirabbrevs) {
186 my @colwidth = ((0)x@dirs);
187 for my $i (0..$#dirs) {
188 my $w = length display_dir($dirs[$i]);
189 $colwidth[$i] = $w if $w > $colwidth[$i];
191 for my $t (@subtests) {
193 for my $i (0..$#dirs) {
195 $times{$prefixes{$d}.$t} = [get_times("$resultsdir/$prefixes{$d}$t.times")];
196 my ($r,$u,$s) = @{$times{$prefixes{$d}.$t}};
197 my $w = length format_times($r,$u,$s,$firstr);
198 $colwidth[$i] = $w if $w > $colwidth[$i];
199 $firstr = $r unless defined $firstr;
202 my $totalwidth = 3*@dirs+$descrlen;
203 $totalwidth += $_ for (@colwidth);
205 printf "%-${descrlen}s", "Test";
206 for my $i (0..$#dirs) {
207 printf " %-$colwidth[$i]s", display_dir($dirs[$i]);
210 print "-"x$totalwidth, "\n";
211 for my $t (@subtests) {
212 printf "%-${descrlen}s", $descrs{$t};
214 for my $i (0..$#dirs) {
216 my ($r,$u,$s) = @{$times{$prefixes{$d}.$t}};
217 printf " %-$colwidth[$i]s", format_times($r,$u,$s,$firstr);
218 $firstr = $r unless defined $firstr;
224 sub print_sorted_results {
227 if ($sortby ne "regression") {
228 die "only 'regression' is supported as '--sort-by' argument";
232 for my $t (@subtests) {
233 my ($prevr, $prevu, $prevs, $prevrev);
234 for my $i (0..$#dirs) {
236 my ($r, $u, $s) = get_times("$resultsdir/$prefixes{$d}$t.times");
237 if ($i > 0 and defined $r and defined $prevr and $prevr > 0) {
238 my $percent = 100.0 * ($r - $prevr) / $prevr;
239 push @evolutions, { "percent" => $percent,
241 "prevrev" => $prevrev,
250 ($prevr, $prevu, $prevs, $prevrev) = ($r, $u, $s, $d);
254 my @sorted_evolutions = sort { $b->{percent} <=> $a->{percent} } @evolutions;
256 for my $e (@sorted_evolutions) {
257 printf "%+.1f%%", $e->{percent};
258 print " " . $e->{test};
259 print " " . format_times($e->{prevr}, $e->{prevu}, $e->{prevs});
260 print " " . format_times($e->{r}, $e->{u}, $e->{s});
261 print " " . display_dir($e->{prevrev});
262 print " " . display_dir($e->{rev});
267 sub print_codespeed_results {
268 my ($subsection) = @_;
272 my $executable = `uname -s -m`;
276 $executable .= ", " . $subsection;
281 $environment = $reponame;
282 } elsif (exists $ENV{GIT_PERF_REPO_NAME} and $ENV{GIT_PERF_REPO_NAME} ne "") {
283 $environment = $ENV{GIT_PERF_REPO_NAME};
284 } elsif (exists $ENV{GIT_TEST_INSTALLED} and $ENV{GIT_TEST_INSTALLED} ne "") {
285 $environment = $ENV{GIT_TEST_INSTALLED};
286 $environment =~ s|/bin-wrappers$||;
288 $environment = `uname -r`;
294 for my $t (@subtests) {
296 my $commitid = $prefixes{$d};
297 $commitid =~ s/^build_//;
298 $commitid =~ s/\.$//;
299 my ($result_value, $u, $s) = get_times("$resultsdir/$prefixes{$d}$t.times");
302 "commitid" => $commitid,
303 "project" => $project,
304 "branch" => $dirnames{$d},
305 "executable" => $executable,
306 "benchmark" => $shorttests{$t} . " " . read_descr("$resultsdir/$t.descr"),
307 "environment" => $environment,
308 "result_value" => $result_value,
314 print to_json(\@data, {utf8 => 1, pretty => 1, canonical => 1}), "\n";
317 binmode STDOUT, ":utf8" or die "PANIC on binmode: $!";
320 print_codespeed_results($subsection);
321 } elsif (defined $sortby) {
322 print_sorted_results($sortby);
324 print_default_results();