| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 | 2 |
| 3 # Copyright 2016 Google Inc. | 3 # Copyright 2016 Google Inc. |
| 4 # | 4 # |
| 5 # Use of this source code is governed by a BSD-style license that can be | 5 # Use of this source code is governed by a BSD-style license that can be |
| 6 # found in the LICENSE file. | 6 # found in the LICENSE file. |
| 7 | 7 |
| 8 from __future__ import print_function | 8 from __future__ import print_function |
| 9 from _adb import Adb | 9 from _adb import Adb |
| 10 from _benchresult import BenchResult | 10 from _benchresult import BenchResult |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 if FLAGS.adb: | 106 if FLAGS.adb: |
| 107 if FLAGS.device_serial is None: | 107 if FLAGS.device_serial is None: |
| 108 ARGV = ['adb', 'shell'] + ARGV | 108 ARGV = ['adb', 'shell'] + ARGV |
| 109 else: | 109 else: |
| 110 ARGV = ['adb', '-s', FLAGS.device_serial, 'shell'] + ARGV | 110 ARGV = ['adb', '-s', FLAGS.device_serial, 'shell'] + ARGV |
| 111 | 111 |
| 112 @classmethod | 112 @classmethod |
| 113 def print_header(cls): | 113 def print_header(cls): |
| 114 subprocess.call(cls.ARGV + ['--duration', '0']) | 114 subprocess.call(cls.ARGV + ['--duration', '0']) |
| 115 | 115 |
| 116 @classmethod |
| 117 def run_warmup(cls, warmup_time): |
| 118 if not warmup_time: |
| 119 return |
| 120 print('running %i second warmup...' % warmup_time) |
| 121 commandline = cls.ARGV + ['--duration', str(warmup_time * 1000), |
| 122 '--config', 'gpu', |
| 123 '--skp', 'warmup'] |
| 124 output = subprocess.check_output(commandline).decode('utf-8') |
| 125 # validate the warmup run output. |
| 126 for line in output.split('\n'): |
| 127 match = BenchResult.match(line.rstrip()) |
| 128 if match and match.bench == 'warmup': |
| 129 return |
| 130 raise Exception('Invalid warmup output:\n%s' % output) |
| 131 |
| 116 def __init__(self, skp, config, max_stddev, best_result=None): | 132 def __init__(self, skp, config, max_stddev, best_result=None): |
| 117 self.skp = skp | 133 self.skp = skp |
| 118 self.config = config | 134 self.config = config |
| 119 self.max_stddev = max_stddev | 135 self.max_stddev = max_stddev |
| 120 self.best_result = best_result | 136 self.best_result = best_result |
| 121 self._queue = Queue() | 137 self._queue = Queue() |
| 122 self._proc = None | 138 self._proc = None |
| 123 self._monitor = None | 139 self._monitor = None |
| 124 self._hw_poll_timer = None | 140 self._hw_poll_timer = None |
| 125 | 141 |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 print("stddev is too high for %s/%s (%s%%, max=%.2f%%), " | 239 print("stddev is too high for %s/%s (%s%%, max=%.2f%%), " |
| 224 "re-queuing with max=%.2f%%." % | 240 "re-queuing with max=%.2f%%." % |
| 225 (skpbench.best_result.config, skpbench.best_result.bench, | 241 (skpbench.best_result.config, skpbench.best_result.bench, |
| 226 skpbench.best_result.stddev, skpbench.max_stddev, | 242 skpbench.best_result.stddev, skpbench.max_stddev, |
| 227 retry_max_stddev), | 243 retry_max_stddev), |
| 228 file=sys.stderr) | 244 file=sys.stderr) |
| 229 benches.append((skpbench.skp, skpbench.config, retry_max_stddev, | 245 benches.append((skpbench.skp, skpbench.config, retry_max_stddev, |
| 230 skpbench.best_result)) | 246 skpbench.best_result)) |
| 231 | 247 |
| 232 except HardwareException as exception: | 248 except HardwareException as exception: |
| 249 if FLAGS.verbosity >= 5: |
| 250 hardware.print_debug_diagnostics() |
| 233 skpbench.terminate() | 251 skpbench.terminate() |
| 234 naptime = max(hardware.kick_in_time, exception.sleeptime) | |
| 235 if FLAGS.verbosity >= 1: | 252 if FLAGS.verbosity >= 1: |
| 236 print("%s; taking a %i second nap..." % | 253 print("%s; taking a %i second nap..." % |
| 237 (exception.message, naptime), file=sys.stderr) | 254 (exception.message, exception.sleeptime), file=sys.stderr) |
| 238 benches.appendleft(benchargs) # retry the same bench next time. | 255 benches.appendleft(benchargs) # retry the same bench next time. |
| 239 hardware.sleep(naptime - hardware.kick_in_time) | 256 hardware.sleep(exception.sleeptime) |
| 240 time.sleep(hardware.kick_in_time) | 257 SKPBench.run_warmup(hardware.warmup_time) |
| 241 | 258 |
| 242 | 259 |
| 243 def main(): | 260 def main(): |
| 244 # Delimiter is ',' or ' ', skip if nested inside parens (e.g. gpu(a=b,c=d)). | 261 # Delimiter is ',' or ' ', skip if nested inside parens (e.g. gpu(a=b,c=d)). |
| 245 DELIMITER = r'[, ](?!(?:[^(]*\([^)]*\))*[^()]*\))' | 262 DELIMITER = r'[, ](?!(?:[^(]*\([^)]*\))*[^()]*\))' |
| 246 configs = re.split(DELIMITER, FLAGS.config) | 263 configs = re.split(DELIMITER, FLAGS.config) |
| 247 skps = _path.find_skps(FLAGS.skps) | 264 skps = _path.find_skps(FLAGS.skps) |
| 248 | 265 |
| 249 if FLAGS.adb: | 266 if FLAGS.adb: |
| 250 adb = Adb(FLAGS.device_serial) | 267 adb = Adb(FLAGS.device_serial) |
| 251 model = adb.get_device_model() | 268 model = adb.get_device_model() |
| 252 if model == 'Pixel C': | 269 if model == 'Pixel C': |
| 253 from _hardware_pixel_c import HardwarePixelC | 270 from _hardware_pixel_c import HardwarePixelC |
| 254 hardware = HardwarePixelC(adb) | 271 hardware = HardwarePixelC(adb) |
| 255 else: | 272 else: |
| 256 from _hardware_android import HardwareAndroid | 273 from _hardware_android import HardwareAndroid |
| 257 print("WARNING: %s: don't know how to monitor this hardware; results " | 274 print("WARNING: %s: don't know how to monitor this hardware; results " |
| 258 "may be unreliable." % model, file=sys.stderr) | 275 "may be unreliable." % model, file=sys.stderr) |
| 259 hardware = HardwareAndroid(adb) | 276 hardware = HardwareAndroid(adb) |
| 260 else: | 277 else: |
| 261 hardware = Hardware() | 278 hardware = Hardware() |
| 262 | 279 |
| 263 with hardware: | 280 with hardware: |
| 264 if hardware.kick_in_time: | 281 SKPBench.run_warmup(hardware.warmup_time) |
| 265 print("sleeping %i seconds to allow hardware settings to kick in..." % | |
| 266 hardware.kick_in_time, file=sys.stderr) | |
| 267 time.sleep(hardware.kick_in_time) | |
| 268 run_benchmarks(configs, skps, hardware) | 282 run_benchmarks(configs, skps, hardware) |
| 269 | 283 |
| 270 | 284 |
| 271 if __name__ == '__main__': | 285 if __name__ == '__main__': |
| 272 main() | 286 main() |
| OLD | NEW |