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

Side by Side Diff: tools/perf_expectations/make_expectations.py

Issue 8400009: Support setting 'better' and using it in expectations. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | tools/perf_expectations/perf_expectations.json » ('j') | 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) 2011 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2011 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 6
7 import hashlib 7 import hashlib
8 import math 8 import math
9 import optparse 9 import optparse
10 import os 10 import os
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 return text 74 return text
75 75
76 76
77 def GetRowData(data, key): 77 def GetRowData(data, key):
78 rowdata = [] 78 rowdata = []
79 # reva and revb always come first. 79 # reva and revb always come first.
80 for subkey in ['reva', 'revb']: 80 for subkey in ['reva', 'revb']:
81 if subkey in data[key]: 81 if subkey in data[key]:
82 rowdata.append('"%s": %s' % (subkey, data[key][subkey])) 82 rowdata.append('"%s": %s' % (subkey, data[key][subkey]))
83 # Strings, like type, come next. 83 # Strings, like type, come next.
84 for subkey in ['type']: 84 for subkey in ['type', 'better']:
85 if subkey in data[key]: 85 if subkey in data[key]:
86 rowdata.append('"%s": "%s"' % (subkey, data[key][subkey])) 86 rowdata.append('"%s": "%s"' % (subkey, data[key][subkey]))
87 # Finally the main numbers come last. 87 # Finally the main numbers come last.
88 for subkey in ['improve', 'regress', 'tolerance']: 88 for subkey in ['improve', 'regress', 'tolerance']:
89 if subkey in data[key]: 89 if subkey in data[key]:
90 rowdata.append('"%s": %s' % (subkey, data[key][subkey])) 90 rowdata.append('"%s": %s' % (subkey, data[key][subkey]))
91 return rowdata 91 return rowdata
92 92
93 93
94 def GetRowDigest(rowdata, key): 94 def GetRowDigest(rowdata, key):
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 perfkeys = perf.keys() 158 perfkeys = perf.keys()
159 # In perf_expectations.json, ignore the 'load' key. 159 # In perf_expectations.json, ignore the 'load' key.
160 perfkeys.remove('load') 160 perfkeys.remove('load')
161 perfkeys.sort() 161 perfkeys.sort()
162 162
163 write_new_expectations = False 163 write_new_expectations = False
164 found_checksum_mismatch = False 164 found_checksum_mismatch = False
165 for key in perfkeys: 165 for key in perfkeys:
166 value = perf[key] 166 value = perf[key]
167 tolerance = value.get('tolerance', DEFAULT_TOLERANCE) 167 tolerance = value.get('tolerance', DEFAULT_TOLERANCE)
168 better = value.get('better', None)
168 169
169 # Verify the checksum. 170 # Verify the checksum.
170 original_checksum = value.get('sha1', '') 171 original_checksum = value.get('sha1', '')
171 if 'sha1' in value: 172 if 'sha1' in value:
172 del value['sha1'] 173 del value['sha1']
173 rowdata = GetRowData(perf, key) 174 rowdata = GetRowData(perf, key)
174 computed_checksum = GetRowDigest(rowdata, key) 175 computed_checksum = GetRowDigest(rowdata, key)
175 if original_checksum == computed_checksum: 176 if original_checksum == computed_checksum:
176 OutputMessage('checksum matches, skipping') 177 OutputMessage('checksum matches, skipping')
177 continue 178 continue
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 regress = (float(trace_values[tracename]['high']) - 270 regress = (float(trace_values[tracename]['high']) -
270 float(trace_values[reftracename]['low'])) 271 float(trace_values[reftracename]['low']))
271 improve = (float(trace_values[tracename]['low']) - 272 improve = (float(trace_values[tracename]['low']) -
272 float(trace_values[reftracename]['high'])) 273 float(trace_values[reftracename]['high']))
273 elif value_type == 'absolute': 274 elif value_type == 'absolute':
274 # Calculate assuming high absolutes are regressions and low absolutes are 275 # Calculate assuming high absolutes are regressions and low absolutes are
275 # improvements. 276 # improvements.
276 regress = float(trace_values[tracename]['high']) 277 regress = float(trace_values[tracename]['high'])
277 improve = float(trace_values[tracename]['low']) 278 improve = float(trace_values[tracename]['low'])
278 279
279 # At this point, regress > improve. If regress == improve, we adjust 280 # So far we've assumed better is lower (regress > improve). If the actual
280 # improve so it is just a little less than regress. I'm picking on improve 281 # values for regress and improve are equal, though, and better was not
281 # so we keep the sizes assumptions in place for now. 282 # specified, alert the user so we don't let them create a new file with
282 if regress == improve: 283 # ambiguous rules.
283 improve = float(improve - abs(regress * 0.01)) 284 if better == None and regress == improve:
285 OutputMessage('regress (%s) is equal to improve (%s), and "better" is '
286 'unspecified, please fix by setting "better": "lower" or '
287 '"better": "higher" in this perf trace\'s expectation' % (
288 regress, improve), verbose_message=False)
289 return 1
284 290
285 # If the existing values assume regressions are low deltas relative to 291 # If the existing values assume regressions are low deltas relative to
286 # improvements, swap our regress and improve. This value must be a 292 # improvements, swap our regress and improve. This value must be a
287 # scores-like result. 293 # scores-like result.
288 if ('regress' in perf[key] and 'improve' in perf[key] and 294 if ('regress' in perf[key] and 'improve' in perf[key] and
289 perf[key]['regress'] < perf[key]['improve']): 295 perf[key]['regress'] < perf[key]['improve']):
296 assert(better != 'lower')
297 better = 'higher'
290 temp = regress 298 temp = regress
291 regress = improve 299 regress = improve
292 improve = temp 300 improve = temp
293 if regress < improve: 301 else:
302 assert(better != 'higher')
303 better = 'lower'
304
305 if better == 'higher':
294 regress = int(math.floor(regress - abs(regress*tolerance))) 306 regress = int(math.floor(regress - abs(regress*tolerance)))
295 improve = int(math.ceil(improve + abs(improve*tolerance))) 307 improve = int(math.ceil(improve + abs(improve*tolerance)))
296 else: 308 else:
297 improve = int(math.floor(improve - abs(improve*tolerance))) 309 improve = int(math.floor(improve - abs(improve*tolerance)))
298 regress = int(math.ceil(regress + abs(regress*tolerance))) 310 regress = int(math.ceil(regress + abs(regress*tolerance)))
299 311
300 # Calculate the new checksum to test if this is the only thing that may have 312 # Calculate the new checksum to test if this is the only thing that may have
301 # changed. 313 # changed.
302 checksum_rowdata = GetRowData(perf, key) 314 checksum_rowdata = GetRowData(perf, key)
303 new_checksum = GetRowDigest(checksum_rowdata, key) 315 new_checksum = GetRowDigest(checksum_rowdata, key)
(...skipping 23 matching lines...) Expand all
327 print 'done' 339 print 'done'
328 else: 340 else:
329 if options.verbose: 341 if options.verbose:
330 print '' 342 print ''
331 print 'No changes.' 343 print 'No changes.'
332 return 0 344 return 0
333 345
334 346
335 if __name__ == '__main__': 347 if __name__ == '__main__':
336 sys.exit(Main(sys.argv)) 348 sys.exit(Main(sys.argv))
OLDNEW
« no previous file with comments | « no previous file | tools/perf_expectations/perf_expectations.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698