-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgen-suspicious-failure-rates-json.pl
executable file
·99 lines (80 loc) · 3.51 KB
/
gen-suspicious-failure-rates-json.pl
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
#!/usr/bin/perl
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#######
# expects:
# - a file name with the "recent" failures on command line
# - a stream of entries cat'ed to STDIN from "older" files
use strict;
use warnings;
use Data::Dumper;
my %results = ();
my $recent_failure_file_name = shift
or die "Must have a single command line arg for the recent failure rates";
open(my $recent_failure_file, "<", $recent_failure_file_name)
or die "Can't open $recent_failure_file_name: $!";
while (<$recent_failure_file>) {
chomp;
my ($class,$method,$rate,$fail,$runs,$gap,@failed_jobs) = split /,/;
die "WTF: gap is really $gap" unless ('' eq $gap);
next if ("" eq $method); # ignore suites since the failure rates are missleading
next unless (10 <= $runs); # ignore methods where run data is too small to draw conclusions
next unless (0.1 <= $rate); # ignore methods where failure rate is (relativly) low
my %failed_job_counts = ();
for (@failed_jobs) {
if (exists $failed_job_counts{$_}) {
$failed_job_counts{$_} += 1;
} else {
$failed_job_counts{$_} = 1;
}
}
my $failed_jobs_json = join(", ", map { qq({ "path":"$_","count":$failed_job_counts{$_} }) } keys %failed_job_counts);
$results{"$class,$method"} = { 'rate' => $rate,
'fail' => $fail,
'runs' => $runs,
'failed_jobs_json' => $failed_jobs_json,
'historic_fail' => 0,
'historic_runs' => 0,
};
}
close $recent_failure_file;
while (<>) {
chomp;
my ($class,$method,$rate,$fail,$runs,$gap,@failed_jobs) = split /,/;
next if ("" eq $method); # ignore suites since the failure rates are missleading
next unless exists $results{"$class,$method"};
my $record = $results{"$class,$method"};
$record->{'historic_fail'} += $fail;
$record->{'historic_runs'} += $runs;
}
print "[";
my $i = 0;
while (my ($key, $record) = each %results) {
my ($class,$method) = split /,/, $key;
my $fail = $record->{'fail'};
my $runs = $record->{'runs'};
my $historic_fail = $record->{'historic_fail'};
my $historic_runs = $record->{'historic_runs'};
# tabulator wants percentages
my $rate = 100 * $record->{'rate'};
my $historic_rate = 100 * (0 < $historic_runs ? ($historic_fail / $historic_runs) : 0);
my $delta = $rate - $historic_rate;
next unless 0 <= $delta; # skip tests where we are improving
my $failed_jobs_json = $record->{'failed_jobs_json'};
$i++;
print((1 == $i) ? "\n " : ", ");
print qq[ { "class":"$class", "method":"$method", "fail_rate":"$rate", "failures":"$fail", "runs":"$runs", "historic_fail_rate":"$historic_rate", "historic_failures":"$historic_fail", "historic_runs":"$historic_runs", "delta_fail_rate":"$delta", "failed_jobs": [ $failed_jobs_json ]}\n];
}
print "]\n";