| OLD | NEW |
| 1 # Copyright 2016 Google Inc. | 1 # Copyright 2016 Google Inc. |
| 2 # | 2 # |
| 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 import time | 6 import time |
| 7 | 7 |
| 8 class Hardware: | 8 class Hardware: |
| 9 """Locks down and monitors hardware for benchmarking. | 9 """Locks down and monitors hardware for benchmarking. |
| 10 | 10 |
| 11 This is a common base for classes that can control the specific hardware | 11 This is a common base for classes that can control the specific hardware |
| 12 we are running on. Its purpose is to lock the hardware into a constant | 12 we are running on. Its purpose is to lock the hardware into a constant |
| 13 benchmarking mode for the duration of a 'with' block. e.g.: | 13 benchmarking mode for the duration of a 'with' block. e.g.: |
| 14 | 14 |
| 15 with hardware: | 15 with hardware: |
| 16 run_benchmark() | 16 run_benchmark() |
| 17 | 17 |
| 18 While benchmarking, the caller must call sanity_check() frequently to verify | 18 While benchmarking, the caller must call sanity_check() frequently to verify |
| 19 the hardware state has not changed. | 19 the hardware state has not changed. |
| 20 | 20 |
| 21 """ | 21 """ |
| 22 | 22 |
| 23 def __init__(self): | 23 def __init__(self): |
| 24 self.kick_in_time = 0 | 24 self.warmup_time = 0 |
| 25 | 25 |
| 26 def __enter__(self): | 26 def __enter__(self): |
| 27 return self | 27 return self |
| 28 | 28 |
| 29 def __exit__(self, exception_type, exception_value, traceback): | 29 def __exit__(self, exception_type, exception_value, traceback): |
| 30 pass | 30 pass |
| 31 | 31 |
| 32 def sanity_check(self): | 32 def sanity_check(self): |
| 33 """Raises a HardwareException if any hardware state is not as expected.""" | 33 """Raises a HardwareException if any hardware state is not as expected.""" |
| 34 pass | 34 pass |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 | 84 |
| 85 @staticmethod | 85 @staticmethod |
| 86 def check_all(expectations, stringvalues): | 86 def check_all(expectations, stringvalues): |
| 87 if len(stringvalues) != len(expectations): | 87 if len(stringvalues) != len(expectations): |
| 88 raise Exception("unexpected reading from hardware gauges " | 88 raise Exception("unexpected reading from hardware gauges " |
| 89 "(expected %i values):\n%s" % | 89 "(expected %i values):\n%s" % |
| 90 (len(expectations), '\n'.join(stringvalues))) | 90 (len(expectations), '\n'.join(stringvalues))) |
| 91 | 91 |
| 92 for value, expected in zip(stringvalues, expectations): | 92 for value, expected in zip(stringvalues, expectations): |
| 93 expected.check(value) | 93 expected.check(value) |
| OLD | NEW |