Skip to content

Commit 05eb1c3

Browse files
chriscoolgitster
authored andcommitted
perf/aggregate: implement codespeed JSON output
Codespeed (https://github.com/tobami/codespeed/) is an open source project that can be used to track how some software performs over time. It stores performance test results in a database and can show nice graphs and charts on a web interface. As it can be interesting to use Codespeed to see how Git performance evolves over time and releases, let's implement a Codespeed output in "perf/aggregate.perl". Helped-by: Eric Sunshine <[email protected]> Signed-off-by: Christian Couder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 30ffff6 commit 05eb1c3

File tree

1 file changed

+62
-2
lines changed

1 file changed

+62
-2
lines changed

t/perf/aggregate.perl

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
use lib '../../perl/blib/lib';
44
use strict;
55
use warnings;
6+
use JSON;
67
use Git;
78

89
sub get_times {
@@ -35,10 +36,15 @@ sub format_times {
3536
return $out;
3637
}
3738

38-
my (@dirs, %dirnames, %dirabbrevs, %prefixes, @tests);
39+
my (@dirs, %dirnames, %dirabbrevs, %prefixes, @tests, $codespeed);
3940
while (scalar @ARGV) {
4041
my $arg = $ARGV[0];
4142
my $dir;
43+
if ($arg eq "--codespeed") {
44+
$codespeed = 1;
45+
shift @ARGV;
46+
next;
47+
}
4248
last if -f $arg or $arg eq "--";
4349
if (! -d $arg) {
4450
my $rev = Git::command_oneline(qw(rev-parse --verify), $arg);
@@ -70,8 +76,10 @@ sub format_times {
7076
}
7177

7278
my $resultsdir = "test-results";
79+
my $results_section = "";
7380
if (exists $ENV{GIT_PERF_SUBSECTION} and $ENV{GIT_PERF_SUBSECTION} ne "") {
7481
$resultsdir .= "/" . $ENV{GIT_PERF_SUBSECTION};
82+
$results_section = $ENV{GIT_PERF_SUBSECTION};
7583
}
7684

7785
my @subtests;
@@ -174,6 +182,58 @@ sub print_default_results {
174182
}
175183
}
176184

185+
sub print_codespeed_results {
186+
my ($results_section) = @_;
187+
188+
my $project = "Git";
189+
190+
my $executable = `uname -s -m`;
191+
chomp $executable;
192+
193+
if ($results_section ne "") {
194+
$executable .= ", " . $results_section;
195+
}
196+
197+
my $environment;
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$||;
203+
} else {
204+
$environment = `uname -r`;
205+
chomp $environment;
206+
}
207+
208+
my @data;
209+
210+
for my $t (@subtests) {
211+
for my $d (@dirs) {
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");
216+
217+
my %vals = (
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,
225+
);
226+
push @data, \%vals;
227+
}
228+
}
229+
230+
print to_json(\@data, {utf8 => 1, pretty => 1}), "\n";
231+
}
232+
177233
binmode STDOUT, ":utf8" or die "PANIC on binmode: $!";
178234

179-
print_default_results();
235+
if ($codespeed) {
236+
print_codespeed_results($results_section);
237+
} else {
238+
print_default_results();
239+
}

0 commit comments

Comments
 (0)