| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 return text | 72 return text |
| 73 | 73 |
| 74 | 74 |
| 75 def GetRowData(data, key): | 75 def GetRowData(data, key): |
| 76 rowdata = [] | 76 rowdata = [] |
| 77 # reva and revb always come first. | 77 # reva and revb always come first. |
| 78 for subkey in ['reva', 'revb']: | 78 for subkey in ['reva', 'revb']: |
| 79 if subkey in data[key]: | 79 if subkey in data[key]: |
| 80 rowdata.append('"%s": %s' % (subkey, data[key][subkey])) | 80 rowdata.append('"%s": %s' % (subkey, data[key][subkey])) |
| 81 # Strings, like type, come next. | 81 # Strings, like type, come next. |
| 82 for subkey in ['type']: | 82 for subkey in ['type', 'better']: |
| 83 if subkey in data[key]: | 83 if subkey in data[key]: |
| 84 rowdata.append('"%s": "%s"' % (subkey, data[key][subkey])) | 84 rowdata.append('"%s": "%s"' % (subkey, data[key][subkey])) |
| 85 # Finally the main numbers come last. | 85 # Finally the main numbers come last. |
| 86 for subkey in ['improve', 'regress', 'tolerance']: | 86 for subkey in ['improve', 'regress', 'tolerance']: |
| 87 if subkey in data[key]: | 87 if subkey in data[key]: |
| 88 rowdata.append('"%s": %s' % (subkey, data[key][subkey])) | 88 rowdata.append('"%s": %s' % (subkey, data[key][subkey])) |
| 89 return rowdata | 89 return rowdata |
| 90 | 90 |
| 91 | 91 |
| 92 def GetRowDigest(rowdata, key): | 92 def GetRowDigest(rowdata, key): |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 # Fetch graphs.dat for this combination. | 153 # Fetch graphs.dat for this combination. |
| 154 perfkeys = perf.keys() | 154 perfkeys = perf.keys() |
| 155 # In perf_expectations.json, ignore the 'load' key. | 155 # In perf_expectations.json, ignore the 'load' key. |
| 156 perfkeys.remove('load') | 156 perfkeys.remove('load') |
| 157 perfkeys.sort() | 157 perfkeys.sort() |
| 158 | 158 |
| 159 write_new_expectations = False | 159 write_new_expectations = False |
| 160 for key in perfkeys: | 160 for key in perfkeys: |
| 161 value = perf[key] | 161 value = perf[key] |
| 162 tolerance = value.get('tolerance', DEFAULT_TOLERANCE) | 162 tolerance = value.get('tolerance', DEFAULT_TOLERANCE) |
| 163 better = value.get('better', None) |
| 163 | 164 |
| 164 # Verify the checksum. | 165 # Verify the checksum. |
| 165 original_checksum = value.get('sha1', '') | 166 original_checksum = value.get('sha1', '') |
| 166 if 'sha1' in value: | 167 if 'sha1' in value: |
| 167 del value['sha1'] | 168 del value['sha1'] |
| 168 rowdata = GetRowData(perf, key) | 169 rowdata = GetRowData(perf, key) |
| 169 computed_checksum = GetRowDigest(rowdata, key) | 170 computed_checksum = GetRowDigest(rowdata, key) |
| 170 if original_checksum == computed_checksum: | 171 if original_checksum == computed_checksum: |
| 171 OutputMessage('checksum matches, skipping') | 172 OutputMessage('checksum matches, skipping') |
| 172 continue | 173 continue |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 regress = (float(trace_values[tracename]['high']) - | 261 regress = (float(trace_values[tracename]['high']) - |
| 261 float(trace_values[reftracename]['low'])) | 262 float(trace_values[reftracename]['low'])) |
| 262 improve = (float(trace_values[tracename]['low']) - | 263 improve = (float(trace_values[tracename]['low']) - |
| 263 float(trace_values[reftracename]['high'])) | 264 float(trace_values[reftracename]['high'])) |
| 264 elif value_type == 'absolute': | 265 elif value_type == 'absolute': |
| 265 # Calculate assuming high absolutes are regressions and low absolutes are | 266 # Calculate assuming high absolutes are regressions and low absolutes are |
| 266 # improvements. | 267 # improvements. |
| 267 regress = float(trace_values[tracename]['high']) | 268 regress = float(trace_values[tracename]['high']) |
| 268 improve = float(trace_values[tracename]['low']) | 269 improve = float(trace_values[tracename]['low']) |
| 269 | 270 |
| 270 # At this point, regress > improve. If regress == improve, we adjust | 271 # So far we've assumed better is lower (regress > improve). If the actual |
| 271 # improve so it is just a little less than regress. I'm picking on improve | 272 # values for regress and improve are equal, though, and better was not |
| 272 # so we keep the sizes assumptions in place for now. | 273 # specified, alert the user so we don't let them create a new file with |
| 273 if regress == improve: | 274 # ambiguous rules. |
| 274 improve = float(regress * 0.99) | 275 if better == None and regress == improve: |
| 276 OutputMessage('regress (%s) is equal to improve (%s), and "better" is ' |
| 277 'unspecified, please fix by setting "better": "lower" or ' |
| 278 '"better": "higher" in this perf trace\'s expectation' % ( |
| 279 regress, improve), verbose_message=False) |
| 280 return 1 |
| 275 | 281 |
| 276 # If the existing values assume regressions are low deltas relative to | 282 # If the existing values assume regressions are low deltas relative to |
| 277 # improvements, swap our regress and improve. This value must be a | 283 # improvements, swap our regress and improve. This value must be a |
| 278 # scores-like result. | 284 # scores-like result. |
| 279 if ('regress' in perf[key] and 'improve' in perf[key] and | 285 if ('regress' in perf[key] and 'improve' in perf[key] and |
| 280 perf[key]['regress'] < perf[key]['improve']): | 286 perf[key]['regress'] < perf[key]['improve']): |
| 287 assert(better != 'lower') |
| 288 better = 'higher' |
| 281 temp = regress | 289 temp = regress |
| 282 regress = improve | 290 regress = improve |
| 283 improve = temp | 291 improve = temp |
| 284 if regress < improve: | 292 else: |
| 293 assert(better != 'higher') |
| 294 better = 'lower' |
| 295 |
| 296 if better == 'higher': |
| 285 regress = int(math.floor(regress - abs(regress*tolerance))) | 297 regress = int(math.floor(regress - abs(regress*tolerance))) |
| 286 improve = int(math.ceil(improve + abs(improve*tolerance))) | 298 improve = int(math.ceil(improve + abs(improve*tolerance))) |
| 287 else: | 299 else: |
| 288 improve = int(math.floor(improve - abs(improve*tolerance))) | 300 improve = int(math.floor(improve - abs(improve*tolerance))) |
| 289 regress = int(math.ceil(regress + abs(regress*tolerance))) | 301 regress = int(math.ceil(regress + abs(regress*tolerance))) |
| 290 | 302 |
| 291 # Calculate the new checksum to test if this is the only thing that may have | 303 # Calculate the new checksum to test if this is the only thing that may have |
| 292 # changed. | 304 # changed. |
| 293 checksum_rowdata = GetRowData(perf, key) | 305 checksum_rowdata = GetRowData(perf, key) |
| 294 new_checksum = GetRowDigest(checksum_rowdata, key) | 306 new_checksum = GetRowDigest(checksum_rowdata, key) |
| (...skipping 16 matching lines...) Expand all Loading... |
| 311 WriteJson(perf_file, perf, perfkeys) | 323 WriteJson(perf_file, perf, perfkeys) |
| 312 print 'done' | 324 print 'done' |
| 313 else: | 325 else: |
| 314 if options.verbose: | 326 if options.verbose: |
| 315 print '' | 327 print '' |
| 316 print 'No changes.' | 328 print 'No changes.' |
| 317 | 329 |
| 318 | 330 |
| 319 if __name__ == '__main__': | 331 if __name__ == '__main__': |
| 320 sys.exit(Main(sys.argv)) | 332 sys.exit(Main(sys.argv)) |
| OLD | NEW |