blob: 75035ffda77f89a94f49d8184f142f931b1ebe3f [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.orga1bf8be2014-04-11 19:54:16 +000015RANGE_RATIO_UPPER = 1.0 # Ratio of range for upper bounds.
16RANGE_RATIO_LOWER = 1.5 # Ratio of range for lower bounds.
commit-bot@chromium.org093ed312014-04-09 18:57:02 +000017ERR_RATIO = 0.05 # 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
27
28def compute_ranges(benches):
29 """Given a list of bench numbers, calculate the alert range.
30
31 Args:
32 benches: a list of float bench values.
33
34 Returns:
35 a list of float [lower_bound, upper_bound].
36 """
37 minimum = min(benches)
38 maximum = max(benches)
39 diff = maximum - minimum
commit-bot@chromium.org093ed312014-04-09 18:57:02 +000040 avg = sum(benches) / len(benches)
commit-bot@chromium.orgb1bcb212014-03-17 21:16:29 +000041
commit-bot@chromium.orga1bf8be2014-04-11 19:54:16 +000042 return [minimum - diff * RANGE_RATIO_LOWER - avg * ERR_RATIO - ERR_ABS,
43 maximum + diff * RANGE_RATIO_UPPER + avg * ERR_RATIO + ERR_ABS]
commit-bot@chromium.orgb1bcb212014-03-17 21:16:29 +000044
45
46def create_expectations_dict(revision_data_points):
47 """Convert list of bench data points into a dictionary of expectations data.
48
49 Args:
50 revision_data_points: a list of BenchDataPoint objects.
51
52 Returns:
53 a dictionary of this form:
54 keys = tuple of (config, bench) strings.
55 values = list of float [expected, lower_bound, upper_bound] for the key.
56 """
57 bench_dict = {}
58 for point in revision_data_points:
59 if (point.time_type or # Not walltime which has time_type ''
60 not point.config in CONFIGS_TO_INCLUDE):
61 continue
62 key = (point.config, point.bench)
63 if key in bench_dict:
64 raise Exception('Duplicate bench entry: ' + str(key))
65 bench_dict[key] = [point.time] + compute_ranges(point.per_iter_time)
66
67 return bench_dict
68
69
70def main():
71 """Reads bench data points, then calculate and export expectations.
72 """
73 parser = argparse.ArgumentParser()
74 parser.add_argument(
75 '-a', '--representation_alg', default='25th',
76 help='bench representation algorithm to use, see bench_util.py.')
77 parser.add_argument(
78 '-b', '--builder', required=True,
79 help='name of the builder whose bench ranges we are computing.')
80 parser.add_argument(
81 '-d', '--input_dir', required=True,
82 help='a directory containing bench data files.')
83 parser.add_argument(
84 '-o', '--output_file', required=True,
85 help='file path and name for storing the output bench expectations.')
86 parser.add_argument(
87 '-r', '--git_revision', required=True,
88 help='the git hash to indicate the revision of input data to use.')
89 args = parser.parse_args()
90
91 builder = args.builder
92
93 data_points = bench_util.parse_skp_bench_data(
94 args.input_dir, args.git_revision, args.representation_alg)
95
96 expectations_dict = create_expectations_dict(data_points)
97
98 out_lines = []
99 keys = expectations_dict.keys()
100 keys.sort()
101 for (config, bench) in keys:
102 (expected, lower_bound, upper_bound) = expectations_dict[(config, bench)]
103 out_lines.append('%(bench)s_%(config)s_,%(builder)s-%(representation)s,'
104 '%(expected)s,%(lower_bound)s,%(upper_bound)s' % {
105 'bench': bench,
106 'config': config,
107 'builder': builder,
108 'representation': args.representation_alg,
109 'expected': expected,
110 'lower_bound': lower_bound,
111 'upper_bound': upper_bound})
112
113 with open(args.output_file, 'w') as file_handle:
114 file_handle.write('\n'.join(out_lines))
115
116
117if __name__ == "__main__":
118 main()