blob: ffc64866b609601f412ad589c98b48f6e0b21c16 [file] [log] [blame]
commit-bot@chromium.orgb1bcb212014-03-17 21:16:29 +00001#!/usr/bin/env python
2# Copyright (c) 2014 The Chromium Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6""" Generate bench_expectations file from a given set of bench data files. """
7
8import argparse
9import bench_util
10import os
11import re
12import sys
13
14# Parameters for calculating bench ranges.
commit-bot@chromium.org02a5a092014-04-25 22:03:39 +000015RANGE_RATIO_UPPER = 1.2 # Ratio of range for upper bounds.
16RANGE_RATIO_LOWER = 1.8 # Ratio of range for lower bounds.
17ERR_RATIO = 0.08 # Further widens the range by the ratio of average value.
commit-bot@chromium.orga1bf8be2014-04-11 19:54:16 +000018ERR_ABS = 0.5 # Adds an absolute error margin to cope with very small benches.
commit-bot@chromium.orgb1bcb212014-03-17 21:16:29 +000019
20# List of bench configs to monitor. Ignore all other configs.
21CONFIGS_TO_INCLUDE = ['simple_viewport_1000x1000',
22 'simple_viewport_1000x1000_gpu',
23 'simple_viewport_1000x1000_scalar_1.100000',
24 'simple_viewport_1000x1000_scalar_1.100000_gpu',
25 ]
26
commit-bot@chromium.org8cb46b92014-04-28 20:20:43 +000027# List of flaky SKPs that should be excluded.
28SKPS_TO_EXCLUDE = ['desk_chalkboard.skp',
29 ]
30
commit-bot@chromium.orgb1bcb212014-03-17 21:16:29 +000031
32def compute_ranges(benches):
33 """Given a list of bench numbers, calculate the alert range.
34
35 Args:
36 benches: a list of float bench values.
37
38 Returns:
39 a list of float [lower_bound, upper_bound].
40 """
41 minimum = min(benches)
42 maximum = max(benches)
43 diff = maximum - minimum
commit-bot@chromium.org093ed312014-04-09 18:57:02 +000044 avg = sum(benches) / len(benches)
commit-bot@chromium.orgb1bcb212014-03-17 21:16:29 +000045
commit-bot@chromium.orga1bf8be2014-04-11 19:54:16 +000046 return [minimum - diff * RANGE_RATIO_LOWER - avg * ERR_RATIO - ERR_ABS,
47 maximum + diff * RANGE_RATIO_UPPER + avg * ERR_RATIO + ERR_ABS]
commit-bot@chromium.orgb1bcb212014-03-17 21:16:29 +000048
49
50def create_expectations_dict(revision_data_points):
51 """Convert list of bench data points into a dictionary of expectations data.
52
53 Args:
54 revision_data_points: a list of BenchDataPoint objects.
55
56 Returns:
57 a dictionary of this form:
58 keys = tuple of (config, bench) strings.
59 values = list of float [expected, lower_bound, upper_bound] for the key.
60 """
61 bench_dict = {}
62 for point in revision_data_points:
63 if (point.time_type or # Not walltime which has time_type ''
commit-bot@chromium.org8cb46b92014-04-28 20:20:43 +000064 not point.config in CONFIGS_TO_INCLUDE or
65 point.bench in SKPS_TO_EXCLUDE):
commit-bot@chromium.orgb1bcb212014-03-17 21:16:29 +000066 continue
67 key = (point.config, point.bench)
68 if key in bench_dict:
69 raise Exception('Duplicate bench entry: ' + str(key))
70 bench_dict[key] = [point.time] + compute_ranges(point.per_iter_time)
71
72 return bench_dict
73
74
75def main():
76 """Reads bench data points, then calculate and export expectations.
77 """
78 parser = argparse.ArgumentParser()
79 parser.add_argument(
80 '-a', '--representation_alg', default='25th',
81 help='bench representation algorithm to use, see bench_util.py.')
82 parser.add_argument(
83 '-b', '--builder', required=True,
84 help='name of the builder whose bench ranges we are computing.')
85 parser.add_argument(
86 '-d', '--input_dir', required=True,
87 help='a directory containing bench data files.')
88 parser.add_argument(
89 '-o', '--output_file', required=True,
90 help='file path and name for storing the output bench expectations.')
91 parser.add_argument(
92 '-r', '--git_revision', required=True,
93 help='the git hash to indicate the revision of input data to use.')
94 args = parser.parse_args()
95
96 builder = args.builder
97
98 data_points = bench_util.parse_skp_bench_data(
99 args.input_dir, args.git_revision, args.representation_alg)
100
101 expectations_dict = create_expectations_dict(data_points)
102
103 out_lines = []
104 keys = expectations_dict.keys()
105 keys.sort()
106 for (config, bench) in keys:
107 (expected, lower_bound, upper_bound) = expectations_dict[(config, bench)]
108 out_lines.append('%(bench)s_%(config)s_,%(builder)s-%(representation)s,'
109 '%(expected)s,%(lower_bound)s,%(upper_bound)s' % {
110 'bench': bench,
111 'config': config,
112 'builder': builder,
113 'representation': args.representation_alg,
114 'expected': expected,
115 'lower_bound': lower_bound,
116 'upper_bound': upper_bound})
117
118 with open(args.output_file, 'w') as file_handle:
119 file_handle.write('\n'.join(out_lines))
120
121
122if __name__ == "__main__":
123 main()