git@vger.kernel.org list mirror (unofficial, one of many)
 help / color / mirror / code / Atom feed
5d4964c5c68e436407d77302a3832b8452e5ea90 blob 8565 bytes (raw)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
 
#!/usr/bin/perl

use lib '../../perl/build/lib';
use strict;
use warnings;
use Getopt::Long;
use Cwd qw(realpath);

sub get_times {
	my $name = shift;
	open my $fh, "<", $name or return undef;
	my $line = <$fh>;
	return undef if not defined $line;
	close $fh or die "cannot close $name: $!";
	# times
	if ($line =~ /^(?:(\d+):)?(\d+):(\d+(?:\.\d+)?) (\d+(?:\.\d+)?) (\d+(?:\.\d+)?)$/) {
		my $rt = ((defined $1 ? $1 : 0.0)*60+$2)*60+$3;
		return ($rt, $4, $5);
	# size
	} elsif ($line =~ /^\d+$/) {
		return $&;
	} else {
		die "bad input line: $line";
	}
}

sub relative_change {
	my ($r, $firstr) = @_;
	if ($firstr > 0) {
		return sprintf "%+.1f%%", 100.0*($r-$firstr)/$firstr;
	} elsif ($r == 0) {
		return "=";
	} else {
		return "+inf";
	}
}

sub format_times {
	my ($r, $u, $s, $firstr) = @_;
	# no value means we did not finish the test
	if (!defined $r) {
		return "<missing>";
	}
	# a single value means we have a size, not times
	if (!defined $u) {
		return format_size($r, $firstr);
	}
	# otherwise, we have real/user/system times
	my $out = sprintf "%.2f(%.2f+%.2f)", $r, $u, $s;
	$out .= ' ' . relative_change($r, $firstr) if defined $firstr;
	return $out;
}

sub usage {
	print <<EOT;
./aggregate.perl [options] [--] [<dir_or_rev>...] [--] [<test_script>...] >

  Options:
    --codespeed          * Format output for Codespeed
    --reponame    <str>  * Send given reponame to codespeed
    --results-dir <str>  * Directory where test results are located
    --sort-by     <str>  * Sort output (only "regression" criteria is supported)
    --subsection  <str>  * Use results from given subsection

EOT
	exit(1);
}

sub human_size {
	my $n = shift;
	my @units = ('', qw(K M G));
	while ($n > 900 && @units > 1) {
		$n /= 1000;
		shift @units;
	}
	return $n unless length $units[0];
	return sprintf '%.1f%s', $n, $units[0];
}

sub format_size {
	my ($size, $first) = @_;
	# match the width of a time: 0.00(0.00+0.00)
	my $out = sprintf '%15s', human_size($size);
	$out .= ' ' . relative_change($size, $first) if defined $first;
	return $out;
}

sub sane_backticks {
	open(my $fh, '-|', @_);
	return <$fh>;
}

my (@dirs, %dirnames, %dirabbrevs, %prefixes, @tests,
    $codespeed, $sortby, $subsection, $reponame, $resultsdir);

Getopt::Long::Configure qw/ require_order /;

my $rc = GetOptions("codespeed"     => \$codespeed,
		    "reponame=s"    => \$reponame,
		    "results-dir=s" => \$resultsdir,
		    "sort-by=s"     => \$sortby,
		    "subsection=s"  => \$subsection);
usage() unless $rc;

while (scalar @ARGV) {
	my $arg = $ARGV[0];
	my $dir;
	my $prefix = '';
	last if -f $arg or $arg eq "--";
	if (! -d $arg) {
		my $rev = sane_backticks(qw(git rev-parse --verify), $arg);
		chomp $rev;
		$dir = "build/".$rev;
	} elsif ($arg eq '.') {
		$dir = '.';
	} else {
		$dir = realpath($arg);
		$dirnames{$dir} = $dir;
		$prefix .= 'bindir';
	}
	push @dirs, $dir;
	$dirnames{$dir} ||= $arg;
	$prefix .= $dir;
	$prefix =~ tr/^a-zA-Z0-9/_/c;
	$prefixes{$dir} = $prefix . '.';
	shift @ARGV;
}

if (not @dirs) {
	@dirs = ('.');
}
$dirnames{'.'} = $dirabbrevs{'.'} = "this tree";
$prefixes{'.'} = '';

shift @ARGV if scalar @ARGV and $ARGV[0] eq "--";

@tests = @ARGV;
if (not @tests) {
	@tests = glob "p????-*.sh";
}

if (not $resultsdir) {
	$resultsdir = "test-results";
}

if (! $subsection and
    exists $ENV{GIT_PERF_SUBSECTION} and
    $ENV{GIT_PERF_SUBSECTION} ne "") {
	$subsection = $ENV{GIT_PERF_SUBSECTION};
}

if ($subsection) {
	$resultsdir .= "/" . $subsection;
}

my @subtests;
my %shorttests;
for my $t (@tests) {
	$t =~ s{(?:.*/)?(p(\d+)-[^/]+)\.sh$}{$1} or die "bad test name: $t";
	my $n = $2;
	my $fname = "$resultsdir/$t.subtests";
	open my $fp, "<", $fname or die "cannot open $fname: $!";
	for (<$fp>) {
		chomp;
		/^(\d+)$/ or die "malformed subtest line: $_";
		push @subtests, "$t.$1";
		$shorttests{"$t.$1"} = "$n.$1";
	}
	close $fp or die "cannot close $fname: $!";
}

sub read_descr {
	my $name = shift;
	open my $fh, "<", $name or return "<error reading description>";
	binmode $fh, ":utf8" or die "PANIC on binmode: $!";
	my $line = <$fh>;
	close $fh or die "cannot close $name";
	chomp $line;
	return $line;
}

sub have_duplicate {
	my %seen;
	for (@_) {
		return 1 if exists $seen{$_};
		$seen{$_} = 1;
	}
	return 0;
}
sub have_slash {
	for (@_) {
		return 1 if m{/};
	}
	return 0;
}

sub display_dir {
	my ($d) = @_;
	return exists $dirabbrevs{$d} ? $dirabbrevs{$d} : $dirnames{$d};
}

sub print_default_results {
	my %descrs;
	my $descrlen = 4; # "Test"
	for my $t (@subtests) {
		$descrs{$t} = $shorttests{$t}.": ".read_descr("$resultsdir/$t.descr");
		$descrlen = length $descrs{$t} if length $descrs{$t}>$descrlen;
	}

	my %newdirabbrevs = %dirabbrevs;
	while (!have_duplicate(values %newdirabbrevs)) {
		%dirabbrevs = %newdirabbrevs;
		last if !have_slash(values %dirabbrevs);
		%newdirabbrevs = %dirabbrevs;
		for (values %newdirabbrevs) {
			s{^[^/]*/}{};
		}
	}

	my %times;
	my @colwidth = ((0)x@dirs);
	for my $i (0..$#dirs) {
		my $w = length display_dir($dirs[$i]);
		$colwidth[$i] = $w if $w > $colwidth[$i];
	}
	for my $t (@subtests) {
		my $firstr;
		for my $i (0..$#dirs) {
			my $d = $dirs[$i];
			my $base = "$resultsdir/$prefixes{$d}$t";
			$times{$prefixes{$d}.$t} = [get_times("$base.result")];
			my ($r,$u,$s) = @{$times{$prefixes{$d}.$t}};
			my $w = length format_times($r,$u,$s,$firstr);
			$colwidth[$i] = $w if $w > $colwidth[$i];
			$firstr = $r unless defined $firstr;
		}
	}
	my $totalwidth = 3*@dirs+$descrlen;
	$totalwidth += $_ for (@colwidth);

	printf "%-${descrlen}s", "Test";
	for my $i (0..$#dirs) {
		printf "   %-$colwidth[$i]s", display_dir($dirs[$i]);
	}
	print "\n";
	print "-"x$totalwidth, "\n";
	for my $t (@subtests) {
		printf "%-${descrlen}s", $descrs{$t};
		my $firstr;
		for my $i (0..$#dirs) {
			my $d = $dirs[$i];
			my ($r,$u,$s) = @{$times{$prefixes{$d}.$t}};
			printf "   %-$colwidth[$i]s", format_times($r,$u,$s,$firstr);
			$firstr = $r unless defined $firstr;
		}
		print "\n";
	}
}

sub print_sorted_results {
	my ($sortby) = @_;

	if ($sortby ne "regression") {
		print "Only 'regression' is supported as '--sort-by' argument\n";
		usage();
	}

	my @evolutions;
	for my $t (@subtests) {
		my ($prevr, $prevu, $prevs, $prevrev);
		for my $i (0..$#dirs) {
			my $d = $dirs[$i];
			my ($r, $u, $s) = get_times("$resultsdir/$prefixes{$d}$t.result");
			if ($i > 0 and defined $r and defined $prevr and $prevr > 0) {
				my $percent = 100.0 * ($r - $prevr) / $prevr;
				push @evolutions, { "percent"  => $percent,
						    "test"     => $t,
						    "prevrev"  => $prevrev,
						    "rev"      => $d,
						    "prevr"    => $prevr,
						    "r"        => $r,
						    "prevu"    => $prevu,
						    "u"        => $u,
						    "prevs"    => $prevs,
						    "s"        => $s};
			}
			($prevr, $prevu, $prevs, $prevrev) = ($r, $u, $s, $d);
		}
	}

	my @sorted_evolutions = sort { $b->{percent} <=> $a->{percent} } @evolutions;

	for my $e (@sorted_evolutions) {
		printf "%+.1f%%", $e->{percent};
		print " " . $e->{test};
		print " " . format_times($e->{prevr}, $e->{prevu}, $e->{prevs});
		print " " . format_times($e->{r}, $e->{u}, $e->{s});
		print " " . display_dir($e->{prevrev});
		print " " . display_dir($e->{rev});
		print "\n";
	}
}

sub print_codespeed_results {
	my ($subsection) = @_;

	my $project = "Git";

	my $executable = `uname -s -m`;
	chomp $executable;

	if ($subsection) {
		$executable .= ", " . $subsection;
	}

	my $environment;
	if ($reponame) {
		$environment = $reponame;
	} elsif (exists $ENV{GIT_PERF_REPO_NAME} and $ENV{GIT_PERF_REPO_NAME} ne "") {
		$environment = $ENV{GIT_PERF_REPO_NAME};
	} else {
		$environment = `uname -r`;
		chomp $environment;
	}

	my @data;

	for my $t (@subtests) {
		for my $d (@dirs) {
			my $commitid = $prefixes{$d};
			$commitid =~ s/^build_//;
			$commitid =~ s/\.$//;
			my ($result_value, $u, $s) = get_times("$resultsdir/$prefixes{$d}$t.result");

			my %vals = (
				"commitid" => $commitid,
				"project" => $project,
				"branch" => $dirnames{$d},
				"executable" => $executable,
				"benchmark" => $shorttests{$t} . " " . read_descr("$resultsdir/$t.descr"),
				"environment" => $environment,
				"result_value" => $result_value,
			    );
			push @data, \%vals;
		}
	}

	require JSON;
	print JSON::to_json(\@data, {utf8 => 1, pretty => 1, canonical => 1}), "\n";
}

binmode STDOUT, ":utf8" or die "PANIC on binmode: $!";

if ($codespeed) {
	print_codespeed_results($subsection);
} elsif (defined $sortby) {
	print_sorted_results($sortby);
} else {
	print_default_results();
}
debug log:

solving 5d4964c5c6 ...
found 5d4964c5c6 in https://public-inbox.org/git/005cc9a695f7f9b17190293821369763e9bae662.1623834515.git.ps@pks.im/ ||
	https://public-inbox.org/git/5488f0f4888fbc46378e2777d7daba1ec627b6c6.1621451532.git.ps@pks.im/
found 14e4cda287 in https://80x24.org/mirrors/git.git
preparing index
index prepared:
100755 14e4cda287d7e61f040bb2cbfce1c9c2b869f362	t/perf/aggregate.perl

applying [1/2] https://public-inbox.org/git/005cc9a695f7f9b17190293821369763e9bae662.1623834515.git.ps@pks.im/
diff --git a/t/perf/aggregate.perl b/t/perf/aggregate.perl
index 14e4cda287..5d4964c5c6 100755

Checking patch t/perf/aggregate.perl...
Applied patch t/perf/aggregate.perl cleanly.

skipping https://public-inbox.org/git/5488f0f4888fbc46378e2777d7daba1ec627b6c6.1621451532.git.ps@pks.im/ for 5d4964c5c6
index at:
100755 5d4964c5c68e436407d77302a3832b8452e5ea90	t/perf/aggregate.perl

Code repositories for project(s) associated with this inbox:

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).