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 | a1bf8be | 2014-04-11 19:54:16 +0000 | [diff] [blame^] | 15 | RANGE_RATIO_UPPER = 1.0 # Ratio of range for upper bounds. |
| 16 | RANGE_RATIO_LOWER = 1.5 # Ratio of range for lower bounds. |
commit-bot@chromium.org | 093ed31 | 2014-04-09 18:57:02 +0000 | [diff] [blame] | 17 | ERR_RATIO = 0.05 # Further widens the range by the ratio of average value. |
commit-bot@chromium.org | a1bf8be | 2014-04-11 19:54:16 +0000 | [diff] [blame^] | 18 | ERR_ABS = 0.5 # Adds an absolute error margin to cope with very small benches. |
commit-bot@chromium.org | b1bcb21 | 2014-03-17 21:16:29 +0000 | [diff] [blame] | 19 | |
| 20 | # List of bench configs to monitor. Ignore all other configs. |
| 21 | CONFIGS_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 | |
| 28 | def 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.org | 093ed31 | 2014-04-09 18:57:02 +0000 | [diff] [blame] | 40 | avg = sum(benches) / len(benches) |
commit-bot@chromium.org | b1bcb21 | 2014-03-17 21:16:29 +0000 | [diff] [blame] | 41 | |
commit-bot@chromium.org | a1bf8be | 2014-04-11 19:54:16 +0000 | [diff] [blame^] | 42 | 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.org | b1bcb21 | 2014-03-17 21:16:29 +0000 | [diff] [blame] | 44 | |
| 45 | |
| 46 | def 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 | |
| 70 | def 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 | |
| 117 | if __name__ == "__main__": |
| 118 | main() |