Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(34)

Side by Side Diff: bench/gen_bench_expectations.py

Issue 331683003: Added in framework to get more bench data (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2014 The Chromium Authors. All rights reserved. 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 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """ Generate bench_expectations file from a given set of bench data files. """ 6 """ Generate bench_expectations file from a given set of bench data files. """
7 7
8 import argparse 8 import argparse
9 import bench_util 9 import bench_util
10 import json
10 import os 11 import os
11 import re 12 import re
12 import sys 13 import sys
14 import urllib2
13 15
14 # Parameters for calculating bench ranges. 16 # Parameters for calculating bench ranges.
15 RANGE_RATIO_UPPER = 1.5 # Ratio of range for upper bounds. 17 RANGE_RATIO_UPPER = 1.5 # Ratio of range for upper bounds.
16 RANGE_RATIO_LOWER = 2.0 # Ratio of range for lower bounds. 18 RANGE_RATIO_LOWER = 2.0 # Ratio of range for lower bounds.
17 ERR_RATIO = 0.08 # Further widens the range by the ratio of average value. 19 ERR_RATIO = 0.08 # Further widens the range by the ratio of average value.
18 ERR_UB = 1.0 # Adds an absolute upper error to cope with small benches. 20 ERR_UB = 1.0 # Adds an absolute upper error to cope with small benches.
19 ERR_LB = 1.5 21 ERR_LB = 1.5
20 22
21 # List of bench configs to monitor. Ignore all other configs. 23 # List of bench configs to monitor. Ignore all other configs.
22 CONFIGS_TO_INCLUDE = ['simple_viewport_1000x1000', 24 CONFIGS_TO_INCLUDE = ['simple_viewport_1000x1000',
23 'simple_viewport_1000x1000_angle', 25 'simple_viewport_1000x1000_angle',
24 'simple_viewport_1000x1000_gpu', 26 'simple_viewport_1000x1000_gpu',
25 'simple_viewport_1000x1000_scalar_1.100000', 27 'simple_viewport_1000x1000_scalar_1.100000',
26 'simple_viewport_1000x1000_scalar_1.100000_gpu', 28 'simple_viewport_1000x1000_scalar_1.100000_gpu',
27 ] 29 ]
28 30
29 # List of flaky entries that should be excluded. Each entry is defined by a list 31 # List of flaky entries that should be excluded. Each entry is defined by a list
30 # of 3 strings, corresponding to the substrings of [bench, config, builder] to 32 # of 3 strings, corresponding to the substrings of [bench, config, builder] to
31 # search for. A bench expectations line is excluded when each of the 3 strings 33 # search for. A bench expectations line is excluded when each of the 3 strings
32 # in the list is a substring of the corresponding element of the given line. For 34 # in the list is a substring of the corresponding element of the given line. For
33 # instance, ['desk_yahooanswers', 'gpu', 'Ubuntu'] will skip expectation entries 35 # instance, ['desk_yahooanswers', 'gpu', 'Ubuntu'] will skip expectation entries
34 # of SKP benchs whose name contains 'desk_yahooanswers' on all gpu-related 36 # of SKP benchs whose name contains 'desk_yahooanswers' on all gpu-related
35 # configs of all Ubuntu builders. 37 # configs of all Ubuntu builders.
36 ENTRIES_TO_EXCLUDE = [ 38 ENTRIES_TO_EXCLUDE = [
37 ] 39 ]
38 40
41 _GS_CLOUD_FORMAT = 'http://storage.googleapis.com/chromium-skia-gm/perfdata/%s/% s'
39 42
40 def compute_ranges(benches): 43 def compute_ranges(benches, more_benches=None):
41 """Given a list of bench numbers, calculate the alert range. 44 """Given a list of bench numbers, calculate the alert range.
42 45
43 Args: 46 Args:
44 benches: a list of float bench values. 47 benches: a list of float bench values.
48 more_benches: a tuple of lists of additional bench values.
45 49
46 Returns: 50 Returns:
47 a list of float [lower_bound, upper_bound]. 51 a list of float [lower_bound, upper_bound].
48 """ 52 """
49 avg = sum(benches)/len(benches) 53 avg = sum(benches)/len(benches)
50 minimum = min(benches) 54 minimum = min(benches)
51 maximum = max(benches) 55 maximum = max(benches)
52 diff = maximum - minimum 56 diff = maximum - minimum
53 57
54 return [minimum - diff*RANGE_RATIO_LOWER - avg*ERR_RATIO - ERR_LB, 58 return [minimum - diff*RANGE_RATIO_LOWER - avg*ERR_RATIO - ERR_LB,
55 maximum + diff*RANGE_RATIO_UPPER + avg*ERR_RATIO + ERR_UB] 59 maximum + diff*RANGE_RATIO_UPPER + avg*ERR_RATIO + ERR_UB]
56 60
57 61
58 def create_expectations_dict(revision_data_points, builder): 62 def create_expectations_dict(revision_data_points, builder, extra_data=None):
59 """Convert list of bench data points into a dictionary of expectations data. 63 """Convert list of bench data points into a dictionary of expectations data.
60 64
61 Args: 65 Args:
62 revision_data_points: a list of BenchDataPoint objects. 66 revision_data_points: a list of BenchDataPoint objects.
63 builder: string of the corresponding buildbot builder name. 67 builder: string of the corresponding buildbot builder name.
64 68
65 Returns: 69 Returns:
66 a dictionary of this form: 70 a dictionary of this form:
67 keys = tuple of (config, bench) strings. 71 keys = tuple of (config, bench) strings.
68 values = list of float [expected, lower_bound, upper_bound] for the key. 72 values = list of float [expected, lower_bound, upper_bound] for the key.
69 """ 73 """
70 bench_dict = {} 74 bench_dict = {}
71 for point in revision_data_points: 75 for point in revision_data_points:
72 if (point.time_type or # Not walltime which has time_type '' 76 if (point.time_type or # Not walltime which has time_type ''
73 not point.config in CONFIGS_TO_INCLUDE): 77 not point.config in CONFIGS_TO_INCLUDE):
74 continue 78 continue
75 to_skip = False 79 to_skip = False
76 for bench_substr, config_substr, builder_substr in ENTRIES_TO_EXCLUDE: 80 for bench_substr, config_substr, builder_substr in ENTRIES_TO_EXCLUDE:
77 if (bench_substr in point.bench and config_substr in point.config and 81 if (bench_substr in point.bench and config_substr in point.config and
78 builder_substr in builder): 82 builder_substr in builder):
79 to_skip = True 83 to_skip = True
80 break 84 break
81 if to_skip: 85 if to_skip:
82 continue 86 continue
83 key = (point.config, point.bench) 87 key = (point.config, point.bench)
88
89 extras = []
90 for idx, dataset in extra_data:
91 for data in dataset:
92 if (data.bench == point.bench and data.config == point.config and
93 data.time_type == point.time_type and data.per_iter_time):
94 extras.append((idx, data.per_iter_time))
95
84 if key in bench_dict: 96 if key in bench_dict:
85 raise Exception('Duplicate bench entry: ' + str(key)) 97 raise Exception('Duplicate bench entry: ' + str(key))
86 bench_dict[key] = [point.time] + compute_ranges(point.per_iter_time) 98 bench_dict[key] = [point.time] + compute_ranges(point.per_iter_time, extras)
87 99
88 return bench_dict 100 return bench_dict
89 101
90 102
103 def get_parent_commits(start_hash, num_back):
benchen 2014/06/12 17:50:23 Need method description here.
kelvinly 2014/06/12 18:02:00 Done.
104 list_commits = urllib2.urlopen('https://skia.googlesource.com/skia/+log/%s?for mat=json&n=%d' %
105 (start_hash, num_back))
106 # NOTE: Very brittle. Removes the four extraneous characters to json can be re ad successfully
107 trunc_list = list_commits.read()[4:]
108 json_data = json.loads(trunc_list)
109 return [revision['commit'] for revision in json_data['log']]
110
111
112 def get_file_suffixes(commit_hash, directory):
113 """Gets all the suffixes available in the directory"""
114 possible_files = os.listdir(directory)
115 prefix = 'bench_' + commit_hash + '_data_'
116 return [name[len(prefix):] for name in possible_files
117 if name.startswith(prefix)]
118
119
120 def download_bench_data(builder, commit_hash, suffixes, directory):
121 """Downloads data, returns the number successfully downloaded"""
122 cur_files = os.listdir(directory)
123 count = 0
124 for suffix in suffixes:
125 file_name = 'bench_'+commit_hash+'_data_'+suffix
126 if file_name in cur_files:
127 continue
128 try:
129 src = urllib2.urlopen(_GS_CLOUD_FORMAT % (builder, file_name))
130 with open(os.path.join(directory, file_name), 'w') as dest:
131 dest.writelines(src)
132 count += 1
133 except urllib2.HTTPError:
134 pass
135 return count
136
137
91 def main(): 138 def main():
92 """Reads bench data points, then calculate and export expectations. 139 """Reads bench data points, then calculate and export expectations.
93 """ 140 """
94 parser = argparse.ArgumentParser() 141 parser = argparse.ArgumentParser()
95 parser.add_argument( 142 parser.add_argument(
96 '-a', '--representation_alg', default='25th', 143 '-a', '--representation_alg', default='25th',
97 help='bench representation algorithm to use, see bench_util.py.') 144 help='bench representation algorithm to use, see bench_util.py.')
98 parser.add_argument( 145 parser.add_argument(
99 '-b', '--builder', required=True, 146 '-b', '--builder', required=True,
100 help='name of the builder whose bench ranges we are computing.') 147 help='name of the builder whose bench ranges we are computing.')
101 parser.add_argument( 148 parser.add_argument(
102 '-d', '--input_dir', required=True, 149 '-d', '--input_dir', required=True,
103 help='a directory containing bench data files.') 150 help='a directory containing bench data files.')
104 parser.add_argument( 151 parser.add_argument(
105 '-o', '--output_file', required=True, 152 '-o', '--output_file', required=True,
106 help='file path and name for storing the output bench expectations.') 153 help='file path and name for storing the output bench expectations.')
107 parser.add_argument( 154 parser.add_argument(
108 '-r', '--git_revision', required=True, 155 '-r', '--git_revision', required=True,
109 help='the git hash to indicate the revision of input data to use.') 156 help='the git hash to indicate the revision of input data to use.')
157 parser.add_argument(
158 '-t', '--back_track', required=False, default=10,
159 help='the number of commit hashes backwards to look to include in the ca lculations.')
160 parser.add_argument(
161 '-m', '--max_commits', required=False, default=1,
162 help='the number of commit hashes to include in the calculations.')
110 args = parser.parse_args() 163 args = parser.parse_args()
111 164
112 builder = args.builder 165 builder = args.builder
113 166
167 # TODO: Look for commit data by finding the files on CS and parsing it
168 # Copy data into the appropriate dir and then call parse_skp_bench_data ?
114 data_points = bench_util.parse_skp_bench_data( 169 data_points = bench_util.parse_skp_bench_data(
115 args.input_dir, args.git_revision, args.representation_alg) 170 args.input_dir, args.git_revision, args.representation_alg)
116 171
117 expectations_dict = create_expectations_dict(data_points, builder) 172 parent_commits = get_parent_commits(args.git_revision, args.back_track)
173 print "Using commits: {}".format(parent_commits)
174 suffixes = get_file_suffixes(args.git_revision, args.input_dir)
175 print "Using suffixes: {}".format(suffixes)
176
177 downloaded_commits = []
178 for idx, commit in enumerate(parent_commits):
179 num_downloaded = download_bench_data(
180 builder, commit, suffixes, args.input_dir)
181 if num_downloaded > 0:
182 downloaded_commits.append((num_downloaded, idx, commit))
183
184 if len(downloaded_commits) < args.max_commits:
185 print "Less than desired number of commits found. Please increase --back_t rack in later runs"
186 trunc_commits = sorted(downloaded_commits,reverse=True)[:args.max_commits]
187 extra_data = []
188 for _, idx, commit in trunc_commits:
189 extra_data.append((idx, bench_util.parse_skp_bench_data(
190 args.input_dir, commit, args.representation_alg)))
191
192 expectations_dict = create_expectations_dict(data_points, builder, extra_dat a)
118 193
119 out_lines = [] 194 out_lines = []
120 keys = expectations_dict.keys() 195 keys = expectations_dict.keys()
121 keys.sort() 196 keys.sort()
122 for (config, bench) in keys: 197 for (config, bench) in keys:
123 (expected, lower_bound, upper_bound) = expectations_dict[(config, bench)] 198 (expected, lower_bound, upper_bound) = expectations_dict[(config, bench)]
124 out_lines.append('%(bench)s_%(config)s_,%(builder)s-%(representation)s,' 199 out_lines.append('%(bench)s_%(config)s_,%(builder)s-%(representation)s,'
125 '%(expected)s,%(lower_bound)s,%(upper_bound)s' % { 200 '%(expected)s,%(lower_bound)s,%(upper_bound)s' % {
126 'bench': bench, 201 'bench': bench,
127 'config': config, 202 'config': config,
128 'builder': builder, 203 'builder': builder,
129 'representation': args.representation_alg, 204 'representation': args.representation_alg,
130 'expected': expected, 205 'expected': expected,
131 'lower_bound': lower_bound, 206 'lower_bound': lower_bound,
132 'upper_bound': upper_bound}) 207 'upper_bound': upper_bound})
133 208
134 with open(args.output_file, 'w') as file_handle: 209 with open(args.output_file, 'w') as file_handle:
135 file_handle.write('\n'.join(out_lines)) 210 file_handle.write('\n'.join(out_lines))
136 211
137 212
138 if __name__ == "__main__": 213 if __name__ == "__main__":
139 main() 214 main()
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698