commit-bot@chromium.org | b1bcb21 | 2014-03-17 21:16:29 +0000 | [diff] [blame] | 1 | #!/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 | |
| 8 | import argparse |
| 9 | import bench_util |
| 10 | import os |
| 11 | import re |
| 12 | import sys |
| 13 | |
| 14 | # Parameters for calculating bench ranges. |
commit-bot@chromium.org | c9c5c42 | 2014-05-06 04:49:13 +0000 | [diff] [blame] | 15 | RANGE_RATIO_UPPER = 1.5 # Ratio of range for upper bounds. |
commit-bot@chromium.org | 379475f | 2014-05-03 12:40:14 +0000 | [diff] [blame] | 16 | RANGE_RATIO_LOWER = 2.0 # Ratio of range for lower bounds. |
commit-bot@chromium.org | 02a5a09 | 2014-04-25 22:03:39 +0000 | [diff] [blame] | 17 | ERR_RATIO = 0.08 # Further widens the range by the ratio of average value. |
commit-bot@chromium.org | c9c5c42 | 2014-05-06 04:49:13 +0000 | [diff] [blame] | 18 | ERR_UB = 1.0 # Adds an absolute upper error to cope with small benches. |
commit-bot@chromium.org | 59d318b | 2014-05-03 12:58:59 +0000 | [diff] [blame] | 19 | ERR_LB = 1.5 |
commit-bot@chromium.org | b1bcb21 | 2014-03-17 21:16:29 +0000 | [diff] [blame] | 20 | |
| 21 | # List of bench configs to monitor. Ignore all other configs. |
| 22 | CONFIGS_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.org | 1961c08 | 2014-05-12 14:36:43 +0000 | [diff] [blame] | 28 | # 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. |
| 35 | ENTRIES_TO_EXCLUDE = [ |
| 36 | ] |
commit-bot@chromium.org | 8cb46b9 | 2014-04-28 20:20:43 +0000 | [diff] [blame] | 37 | |
commit-bot@chromium.org | b1bcb21 | 2014-03-17 21:16:29 +0000 | [diff] [blame] | 38 | |
| 39 | def 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.org | 093ed31 | 2014-04-09 18:57:02 +0000 | [diff] [blame] | 51 | avg = sum(benches) / len(benches) |
commit-bot@chromium.org | b1bcb21 | 2014-03-17 21:16:29 +0000 | [diff] [blame] | 52 | |
commit-bot@chromium.org | d06ee45 | 2014-05-03 13:03:48 +0000 | [diff] [blame] | 53 | 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.org | b1bcb21 | 2014-03-17 21:16:29 +0000 | [diff] [blame] | 55 | |
| 56 | |
commit-bot@chromium.org | 1961c08 | 2014-05-12 14:36:43 +0000 | [diff] [blame] | 57 | def create_expectations_dict(revision_data_points, builder): |
commit-bot@chromium.org | b1bcb21 | 2014-03-17 21:16:29 +0000 | [diff] [blame] | 58 | """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.org | 1961c08 | 2014-05-12 14:36:43 +0000 | [diff] [blame] | 62 | builder: string of the corresponding buildbot builder name. |
commit-bot@chromium.org | b1bcb21 | 2014-03-17 21:16:29 +0000 | [diff] [blame] | 63 | |
| 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.org | 1961c08 | 2014-05-12 14:36:43 +0000 | [diff] [blame] | 72 | 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.org | b1bcb21 | 2014-03-17 21:16:29 +0000 | [diff] [blame] | 81 | 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 | |
| 90 | def 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.org | 1961c08 | 2014-05-12 14:36:43 +0000 | [diff] [blame] | 116 | expectations_dict = create_expectations_dict(data_points, builder) |
commit-bot@chromium.org | b1bcb21 | 2014-03-17 21:16:29 +0000 | [diff] [blame] | 117 | |
| 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 | |
| 137 | if __name__ == "__main__": |
| 138 | main() |