blob: cf56ab050e896a6020a9bd37f45b3ad2404aaff4 [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.orgc9c5c422014-05-06 04:49:13 +000015RANGE_RATIO_UPPER = 1.5 # Ratio of range for upper bounds.
commit-bot@chromium.org379475f2014-05-03 12:40:14 +000016RANGE_RATIO_LOWER = 2.0 # Ratio of range for lower bounds.
commit-bot@chromium.org02a5a092014-04-25 22:03:39 +000017ERR_RATIO = 0.08 # Further widens the range by the ratio of average value.
commit-bot@chromium.orgc9c5c422014-05-06 04:49:13 +000018ERR_UB = 1.0 # Adds an absolute upper error to cope with small benches.
commit-bot@chromium.org59d318b2014-05-03 12:58:59 +000019ERR_LB = 1.5
commit-bot@chromium.orgb1bcb212014-03-17 21:16:29 +000020
21# List of bench configs to monitor. Ignore all other configs.
22CONFIGS_TO_INCLUDE = ['simple_viewport_1000x1000',
23 'simple_viewport_1000x1000_gpu',
24 'simple_viewport_1000x1000_scalar_1.100000',
25 'simple_viewport_1000x1000_scalar_1.100000_gpu',
26 ]
27
commit-bot@chromium.org1961c082014-05-12 14:36:43 +000028# List of flaky entries that should be excluded. Each entry is defined by a list
29# of 3 strings, corresponding to the substrings of [bench, config, builder] to
30# search for. A bench expectations line is excluded when each of the 3 strings
31# in the list is a substring of the corresponding element of the given line. For
32# instance, ['desk_yahooanswers', 'gpu', 'Ubuntu'] will skip expectation entries
33# of SKP benchs whose name contains 'desk_yahooanswers' on all gpu-related
34# configs of all Ubuntu builders.
35ENTRIES_TO_EXCLUDE = [
36 ]
commit-bot@chromium.org8cb46b92014-04-28 20:20:43 +000037
commit-bot@chromium.orgb1bcb212014-03-17 21:16:29 +000038
39def compute_ranges(benches):
40 """Given a list of bench numbers, calculate the alert range.
41
42 Args:
43 benches: a list of float bench values.
44
45 Returns:
46 a list of float [lower_bound, upper_bound].
47 """
48 minimum = min(benches)
49 maximum = max(benches)
50 diff = maximum - minimum
commit-bot@chromium.org093ed312014-04-09 18:57:02 +000051 avg = sum(benches) / len(benches)
commit-bot@chromium.orgb1bcb212014-03-17 21:16:29 +000052
commit-bot@chromium.orgd06ee452014-05-03 13:03:48 +000053 return [minimum - diff * RANGE_RATIO_LOWER - avg * ERR_RATIO - ERR_LB,
54 maximum + diff * RANGE_RATIO_UPPER + avg * ERR_RATIO + ERR_UB]
commit-bot@chromium.orgb1bcb212014-03-17 21:16:29 +000055
56
commit-bot@chromium.org1961c082014-05-12 14:36:43 +000057def create_expectations_dict(revision_data_points, builder):
commit-bot@chromium.orgb1bcb212014-03-17 21:16:29 +000058 """Convert list of bench data points into a dictionary of expectations data.
59
60 Args:
61 revision_data_points: a list of BenchDataPoint objects.
commit-bot@chromium.org1961c082014-05-12 14:36:43 +000062 builder: string of the corresponding buildbot builder name.
commit-bot@chromium.orgb1bcb212014-03-17 21:16:29 +000063
64 Returns:
65 a dictionary of this form:
66 keys = tuple of (config, bench) strings.
67 values = list of float [expected, lower_bound, upper_bound] for the key.
68 """
69 bench_dict = {}
70 for point in revision_data_points:
71 if (point.time_type or # Not walltime which has time_type ''
commit-bot@chromium.org1961c082014-05-12 14:36:43 +000072 not point.config in CONFIGS_TO_INCLUDE):
73 continue
74 to_skip = False
75 for bench_substr, config_substr, builder_substr in ENTRIES_TO_EXCLUDE:
76 if (bench_substr in point.bench and config_substr in point.config and
77 builder_substr in builder):
78 to_skip = True
79 break
80 if to_skip:
commit-bot@chromium.orgb1bcb212014-03-17 21:16:29 +000081 continue
82 key = (point.config, point.bench)
83 if key in bench_dict:
84 raise Exception('Duplicate bench entry: ' + str(key))
85 bench_dict[key] = [point.time] + compute_ranges(point.per_iter_time)
86
87 return bench_dict
88
89
90def main():
91 """Reads bench data points, then calculate and export expectations.
92 """
93 parser = argparse.ArgumentParser()
94 parser.add_argument(
95 '-a', '--representation_alg', default='25th',
96 help='bench representation algorithm to use, see bench_util.py.')
97 parser.add_argument(
98 '-b', '--builder', required=True,
99 help='name of the builder whose bench ranges we are computing.')
100 parser.add_argument(
101 '-d', '--input_dir', required=True,
102 help='a directory containing bench data files.')
103 parser.add_argument(
104 '-o', '--output_file', required=True,
105 help='file path and name for storing the output bench expectations.')
106 parser.add_argument(
107 '-r', '--git_revision', required=True,
108 help='the git hash to indicate the revision of input data to use.')
109 args = parser.parse_args()
110
111 builder = args.builder
112
113 data_points = bench_util.parse_skp_bench_data(
114 args.input_dir, args.git_revision, args.representation_alg)
115
commit-bot@chromium.org1961c082014-05-12 14:36:43 +0000116 expectations_dict = create_expectations_dict(data_points, builder)
commit-bot@chromium.orgb1bcb212014-03-17 21:16:29 +0000117
118 out_lines = []
119 keys = expectations_dict.keys()
120 keys.sort()
121 for (config, bench) in keys:
122 (expected, lower_bound, upper_bound) = expectations_dict[(config, bench)]
123 out_lines.append('%(bench)s_%(config)s_,%(builder)s-%(representation)s,'
124 '%(expected)s,%(lower_bound)s,%(upper_bound)s' % {
125 'bench': bench,
126 'config': config,
127 'builder': builder,
128 'representation': args.representation_alg,
129 'expected': expected,
130 'lower_bound': lower_bound,
131 'upper_bound': upper_bound})
132
133 with open(args.output_file, 'w') as file_handle:
134 file_handle.write('\n'.join(out_lines))
135
136
137if __name__ == "__main__":
138 main()