Merge branch 'ab/cond-skip-tests' into maint
[git/raj.git] / t / perf / aggregate.perl
blob924b19dab4122a36112bd908a6252e754ecc531a
1 #!/usr/bin/perl
3 use lib '../../perl/blib/lib';
4 use strict;
5 use warnings;
6 use Git;
8 sub get_times {
9 my $name = shift;
10 open my $fh, "<", $name or return undef;
11 my $line = <$fh>;
12 return undef if not defined $line;
13 close $fh or die "cannot close $name: $!";
14 $line =~ /^(?:(\d+):)?(\d+):(\d+(?:\.\d+)?) (\d+(?:\.\d+)?) (\d+(?:\.\d+)?)$/
15 or die "bad input line: $line";
16 my $rt = ((defined $1 ? $1 : 0.0)*60+$2)*60+$3;
17 return ($rt, $4, $5);
20 sub format_times {
21 my ($r, $u, $s, $firstr) = @_;
22 if (!defined $r) {
23 return "<missing>";
25 my $out = sprintf "%.2f(%.2f+%.2f)", $r, $u, $s;
26 if (defined $firstr) {
27 if ($firstr > 0) {
28 $out .= sprintf " %+.1f%%", 100.0*($r-$firstr)/$firstr;
29 } elsif ($r == 0) {
30 $out .= " =";
31 } else {
32 $out .= " +inf";
35 return $out;
38 my (@dirs, %dirnames, %dirabbrevs, %prefixes, @tests);
39 while (scalar @ARGV) {
40 my $arg = $ARGV[0];
41 my $dir;
42 last if -f $arg or $arg eq "--";
43 if (! -d $arg) {
44 my $rev = Git::command_oneline(qw(rev-parse --verify), $arg);
45 $dir = "build/".$rev;
46 } else {
47 $arg =~ s{/*$}{};
48 $dir = $arg;
49 $dirabbrevs{$dir} = $dir;
51 push @dirs, $dir;
52 $dirnames{$dir} = $arg;
53 my $prefix = $dir;
54 $prefix =~ tr/^a-zA-Z0-9/_/c;
55 $prefixes{$dir} = $prefix . '.';
56 shift @ARGV;
59 if (not @dirs) {
60 @dirs = ('.');
62 $dirnames{'.'} = $dirabbrevs{'.'} = "this tree";
63 $prefixes{'.'} = '';
65 shift @ARGV if scalar @ARGV and $ARGV[0] eq "--";
67 @tests = @ARGV;
68 if (not @tests) {
69 @tests = glob "p????-*.sh";
72 my @subtests;
73 my %shorttests;
74 for my $t (@tests) {
75 $t =~ s{(?:.*/)?(p(\d+)-[^/]+)\.sh$}{$1} or die "bad test name: $t";
76 my $n = $2;
77 my $fname = "test-results/$t.subtests";
78 open my $fp, "<", $fname or die "cannot open $fname: $!";
79 for (<$fp>) {
80 chomp;
81 /^(\d+)$/ or die "malformed subtest line: $_";
82 push @subtests, "$t.$1";
83 $shorttests{"$t.$1"} = "$n.$1";
85 close $fp or die "cannot close $fname: $!";
88 sub read_descr {
89 my $name = shift;
90 open my $fh, "<", $name or return "<error reading description>";
91 my $line = <$fh>;
92 close $fh or die "cannot close $name";
93 chomp $line;
94 return $line;
97 my %descrs;
98 my $descrlen = 4; # "Test"
99 for my $t (@subtests) {
100 $descrs{$t} = $shorttests{$t}.": ".read_descr("test-results/$t.descr");
101 $descrlen = length $descrs{$t} if length $descrs{$t}>$descrlen;
104 sub have_duplicate {
105 my %seen;
106 for (@_) {
107 return 1 if exists $seen{$_};
108 $seen{$_} = 1;
110 return 0;
112 sub have_slash {
113 for (@_) {
114 return 1 if m{/};
116 return 0;
119 my %newdirabbrevs = %dirabbrevs;
120 while (!have_duplicate(values %newdirabbrevs)) {
121 %dirabbrevs = %newdirabbrevs;
122 last if !have_slash(values %dirabbrevs);
123 %newdirabbrevs = %dirabbrevs;
124 for (values %newdirabbrevs) {
125 s{^[^/]*/}{};
129 my %times;
130 my @colwidth = ((0)x@dirs);
131 for my $i (0..$#dirs) {
132 my $d = $dirs[$i];
133 my $w = length (exists $dirabbrevs{$d} ? $dirabbrevs{$d} : $dirnames{$d});
134 $colwidth[$i] = $w if $w > $colwidth[$i];
136 for my $t (@subtests) {
137 my $firstr;
138 for my $i (0..$#dirs) {
139 my $d = $dirs[$i];
140 $times{$prefixes{$d}.$t} = [get_times("test-results/$prefixes{$d}$t.times")];
141 my ($r,$u,$s) = @{$times{$prefixes{$d}.$t}};
142 my $w = length format_times($r,$u,$s,$firstr);
143 $colwidth[$i] = $w if $w > $colwidth[$i];
144 $firstr = $r unless defined $firstr;
147 my $totalwidth = 3*@dirs+$descrlen;
148 $totalwidth += $_ for (@colwidth);
150 printf "%-${descrlen}s", "Test";
151 for my $i (0..$#dirs) {
152 my $d = $dirs[$i];
153 printf " %-$colwidth[$i]s", (exists $dirabbrevs{$d} ? $dirabbrevs{$d} : $dirnames{$d});
155 print "\n";
156 print "-"x$totalwidth, "\n";
157 for my $t (@subtests) {
158 printf "%-${descrlen}s", $descrs{$t};
159 my $firstr;
160 for my $i (0..$#dirs) {
161 my $d = $dirs[$i];
162 my ($r,$u,$s) = @{$times{$prefixes{$d}.$t}};
163 printf " %-$colwidth[$i]s", format_times($r,$u,$s,$firstr);
164 $firstr = $r unless defined $firstr;
166 print "\n";