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, $codespeed);
40 while (scalar @ARGV) {
43 if ($arg eq "--codespeed") {
48 last if -f $arg or $arg eq "--";
50 my $rev = Git::command_oneline(qw(rev-parse --verify), $arg);
55 $dirabbrevs{$dir} = $dir;
58 $dirnames{$dir} = $arg;
60 $prefix =~ tr/^a-zA-Z0-9/_/c;
61 $prefixes{$dir} = $prefix . '.';
68 $dirnames{'.'} = $dirabbrevs{'.'} = "this tree";
71 shift @ARGV if scalar @ARGV and $ARGV[0] eq "--";
75 @tests = glob "p????-*.sh";
78 my $resultsdir = "test-results";
79 my $results_section = "";
80 if (exists $ENV{GIT_PERF_SUBSECTION} and $ENV{GIT_PERF_SUBSECTION} ne "") {
81 $resultsdir .= "/" . $ENV{GIT_PERF_SUBSECTION};
82 $results_section = $ENV{GIT_PERF_SUBSECTION};
88 $t =~ s{(?:.*/)?(p(\d+)-[^/]+)\.sh$}{$1} or die "bad test name: $t";
90 my $fname = "$resultsdir/$t.subtests";
91 open my $fp, "<", $fname or die "cannot open $fname: $!";
94 /^(\d+)$/ or die "malformed subtest line: $_";
95 push @subtests, "$t.$1";
96 $shorttests{"$t.$1"} = "$n.$1";
98 close $fp or die "cannot close $fname: $!";
103 open my $fh, "<", $name or return "<error reading description>";
104 binmode $fh, ":utf8" or die "PANIC on binmode: $!";
106 close $fh or die "cannot close $name";
114 return 1 if exists $seen{$_};
126 sub print_default_results {
128 my $descrlen = 4; # "Test"
129 for my $t (@subtests) {
130 $descrs{$t} = $shorttests{$t}.": ".read_descr("$resultsdir/$t.descr");
131 $descrlen = length $descrs{$t} if length $descrs{$t}>$descrlen;
134 my %newdirabbrevs = %dirabbrevs;
135 while (!have_duplicate(values %newdirabbrevs)) {
136 %dirabbrevs = %newdirabbrevs;
137 last if !have_slash(values %dirabbrevs);
138 %newdirabbrevs = %dirabbrevs;
139 for (values %newdirabbrevs) {
145 my @colwidth = ((0)x@dirs);
146 for my $i (0..$#dirs) {
148 my $w = length (exists $dirabbrevs{$d} ? $dirabbrevs{$d} : $dirnames{$d});
149 $colwidth[$i] = $w if $w > $colwidth[$i];
151 for my $t (@subtests) {
153 for my $i (0..$#dirs) {
155 $times{$prefixes{$d}.$t} = [get_times("$resultsdir/$prefixes{$d}$t.times")];
156 my ($r,$u,$s) = @{$times{$prefixes{$d}.$t}};
157 my $w = length format_times($r,$u,$s,$firstr);
158 $colwidth[$i] = $w if $w > $colwidth[$i];
159 $firstr = $r unless defined $firstr;
162 my $totalwidth = 3*@dirs+$descrlen;
163 $totalwidth += $_ for (@colwidth);
165 printf "%-${descrlen}s", "Test";
166 for my $i (0..$#dirs) {
168 printf " %-$colwidth[$i]s", (exists $dirabbrevs{$d} ? $dirabbrevs{$d} : $dirnames{$d});
171 print "-"x$totalwidth, "\n";
172 for my $t (@subtests) {
173 printf "%-${descrlen}s", $descrs{$t};
175 for my $i (0..$#dirs) {
177 my ($r,$u,$s) = @{$times{$prefixes{$d}.$t}};
178 printf " %-$colwidth[$i]s", format_times($r,$u,$s,$firstr);
179 $firstr = $r unless defined $firstr;
185 sub print_codespeed_results {
186 my ($results_section) = @_;
190 my $executable = `uname -s -m`;
193 if ($results_section ne "") {
194 $executable .= ", " . $results_section;
198 if (exists $ENV{GIT_PERF_REPO_NAME} and $ENV{GIT_PERF_REPO_NAME} ne "") {
199 $environment = $ENV{GIT_PERF_REPO_NAME};
200 } elsif (exists $ENV{GIT_TEST_INSTALLED} and $ENV{GIT_TEST_INSTALLED} ne "") {
201 $environment = $ENV{GIT_TEST_INSTALLED};
202 $environment =~ s|/bin-wrappers$||;
204 $environment = `uname -r`;
210 for my $t (@subtests) {
212 my $commitid = $prefixes{$d};
213 $commitid =~ s/^build_//;
214 $commitid =~ s/\.$//;
215 my ($result_value, $u, $s) = get_times("$resultsdir/$prefixes{$d}$t.times");
218 "commitid" => $commitid,
219 "project" => $project,
220 "branch" => $dirnames{$d},
221 "executable" => $executable,
222 "benchmark" => $shorttests{$t} . " " . read_descr("$resultsdir/$t.descr"),
223 "environment" => $environment,
224 "result_value" => $result_value,
230 print to_json(\@data, {utf8 => 1, pretty => 1}), "\n";
233 binmode STDOUT, ":utf8" or die "PANIC on binmode: $!";
236 print_codespeed_results($results_section);
238 print_default_results();