Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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. | |
| 15 RANGE_RATIO = 1.0 # Ratio of range for upper and lower bounds. | |
| 16 ABS_ERR = 1.0 # Additional allowed error in milliseconds. | |
| 17 | |
| 18 # List of bench configs to monitor. Ignore all other configs. | |
| 19 CONFIGS_TO_INCLUDE = ['simple_viewport_1000x1000', | |
| 20 'simple_viewport_1000x1000_gpu', | |
| 21 'simple_viewport_1000x1000_scalar_1.100000', | |
| 22 'simple_viewport_1000x1000_scalar_1.100000_gpu', | |
| 23 ] | |
| 24 | |
| 25 | |
| 26 def compute_ranges(benches): | |
| 27 """Given a list of bench numbers, calculate the alert range. | |
| 28 | |
| 29 Args: | |
| 30 benches: a list of float bench values. | |
| 31 | |
| 32 Returns: | |
| 33 a list of float [lower_bound, upper_bound]. | |
| 34 """ | |
| 35 minimum = min(benches) | |
| 36 maximum = max(benches) | |
| 37 diff = maximum - minimum | |
| 38 | |
| 39 return [minimum - diff * RANGE_RATIO - ABS_ERR, | |
| 40 maximum + diff * RANGE_RATIO + ABS_ERR] | |
| 41 | |
| 42 | |
| 43 def create_expectations_dict(revision_data_points): | |
| 44 """Convert list of bench data points into a dictionary of expectations data. | |
| 45 | |
| 46 Args: | |
| 47 revision_data_points: a list of BenchDataPoint objects. | |
| 48 | |
| 49 Returns: | |
| 50 a dictionary of this form: | |
| 51 keys = tuple of (config, bench) strings. | |
| 52 values = list of float [expected, lower_bound, upper_bound] for the key. | |
| 53 """ | |
| 54 bench_dict = {} | |
| 55 for point in revision_data_points: | |
| 56 if (point.time_type or # Not walltime which has time_type '' | |
|
borenet
2014/03/17 17:43:05
This seems confusing to me, but I guess it's okay
benchen
2014/03/17 19:02:40
this is legacy format. I think it meant "default".
| |
| 57 not point.config in CONFIGS_TO_INCLUDE): | |
| 58 continue | |
| 59 key = (point.config, point.bench) | |
| 60 if key in bench_dict: | |
| 61 raise Exception('Duplicate bench entry: ' + str(key)) | |
| 62 bench_dict[key] = [point.time] + compute_ranges(point.per_iter_time) | |
| 63 | |
| 64 return bench_dict | |
| 65 | |
| 66 | |
| 67 def main(): | |
| 68 """Reads bench data points, then calculate and export expectations. | |
| 69 """ | |
| 70 parser = argparse.ArgumentParser() | |
| 71 parser.add_argument( | |
| 72 '-a', '--representation_alg', default='25th', | |
| 73 help='bench representation algorithm to use, see bench_util.py.') | |
| 74 parser.add_argument( | |
| 75 '-b', '--builder', required=True, | |
| 76 help='name of the builder whose bench ranges we are computing.') | |
| 77 parser.add_argument( | |
| 78 '-d', '--input_dir', required=True, | |
| 79 help='a directory containing bench data files.') | |
| 80 parser.add_argument( | |
| 81 '-o', '--output_file', required=True, | |
| 82 help='file path and name for storing the output bench expectations.') | |
| 83 parser.add_argument( | |
| 84 '-r', '--git_revision', required=True, | |
| 85 help='the git hash to indicate the revision of input data to use.') | |
| 86 args = parser.parse_args() | |
| 87 | |
| 88 builder = args.builder | |
| 89 | |
| 90 data_points = bench_util.parse_skp_bench_data( | |
| 91 args.input_dir, args.git_revision, args.representation_alg) | |
| 92 | |
| 93 expectations_dict = create_expectations_dict(data_points) | |
| 94 | |
| 95 out_lines = [] | |
| 96 keys = expectations_dict.keys() | |
| 97 keys.sort() | |
| 98 for (config, bench) in keys: | |
| 99 (expected, lower_bound, upper_bound) = expectations_dict[(config, bench)] | |
| 100 out_lines.append('%s_%s_,%s-%s,%s,%s,%s' % ( | |
| 101 bench, config, builder, args.representation_alg, expected, | |
| 102 lower_bound, upper_bound)) | |
|
borenet
2014/03/17 17:43:05
Can we use a format dict here for clarity?
'%(ben
benchen
2014/03/17 19:02:40
Done.
| |
| 103 | |
| 104 with open(args.output_file, 'w') as file_handle: | |
| 105 file_handle.write('\n'.join(out_lines)) | |
| 106 | |
| 107 | |
| 108 if __name__ == "__main__": | |
| 109 main() | |
| OLD | NEW |