csmartdalton | 4b5179b | 2016-09-19 11:03:58 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | # Copyright 2016 Google Inc. |
| 4 | # |
| 5 | # Use of this source code is governed by a BSD-style license that can be |
| 6 | # found in the LICENSE file. |
| 7 | |
| 8 | from __future__ import print_function |
csmartdalton | d7a9db6 | 2016-09-22 05:10:02 -0700 | [diff] [blame] | 9 | from _adb import Adb |
csmartdalton | 4b5179b | 2016-09-19 11:03:58 -0700 | [diff] [blame] | 10 | from _benchresult import BenchResult |
csmartdalton | d7a9db6 | 2016-09-22 05:10:02 -0700 | [diff] [blame] | 11 | from _hardware import HardwareException, Hardware |
csmartdalton | 4b5179b | 2016-09-19 11:03:58 -0700 | [diff] [blame] | 12 | from argparse import ArgumentParser |
csmartdalton | 5745d79 | 2016-09-22 12:37:21 -0700 | [diff] [blame] | 13 | from multiprocessing import Queue |
csmartdalton | d7a9db6 | 2016-09-22 05:10:02 -0700 | [diff] [blame] | 14 | from threading import Thread, Timer |
csmartdalton | 4b5179b | 2016-09-19 11:03:58 -0700 | [diff] [blame] | 15 | import collections |
| 16 | import glob |
| 17 | import math |
| 18 | import re |
| 19 | import subprocess |
| 20 | import sys |
csmartdalton | d7a9db6 | 2016-09-22 05:10:02 -0700 | [diff] [blame] | 21 | import time |
csmartdalton | 4b5179b | 2016-09-19 11:03:58 -0700 | [diff] [blame] | 22 | |
csmartdalton | bf41fa8 | 2016-09-23 11:36:11 -0700 | [diff] [blame] | 23 | __argparse = ArgumentParser(description=""" |
csmartdalton | 4b5179b | 2016-09-19 11:03:58 -0700 | [diff] [blame] | 24 | |
| 25 | Executes the skpbench binary with various configs and skps. |
| 26 | |
| 27 | Also monitors the output in order to filter out and re-run results that have an |
| 28 | unacceptable stddev. |
| 29 | |
csmartdalton | bf41fa8 | 2016-09-23 11:36:11 -0700 | [diff] [blame] | 30 | """) |
csmartdalton | 4b5179b | 2016-09-19 11:03:58 -0700 | [diff] [blame] | 31 | |
csmartdalton | 2087dda | 2016-11-09 16:34:53 -0500 | [diff] [blame] | 32 | __argparse.add_argument('skpbench', |
Kevin Lubick | 9c2249f | 2016-11-10 14:19:00 -0500 | [diff] [blame] | 33 | help="path to the skpbench binary") |
csmartdalton | 0262b5c | 2016-09-19 12:04:56 -0700 | [diff] [blame] | 34 | __argparse.add_argument('--adb', |
Kevin Lubick | 9c2249f | 2016-11-10 14:19:00 -0500 | [diff] [blame] | 35 | action='store_true', help="execute skpbench over adb") |
csmartdalton | 0262b5c | 2016-09-19 12:04:56 -0700 | [diff] [blame] | 36 | __argparse.add_argument('-s', '--device-serial', |
Kevin Lubick | 9c2249f | 2016-11-10 14:19:00 -0500 | [diff] [blame] | 37 | help="if using adb, ID of the specific device to target " |
| 38 | "(only required if more than 1 device is attached)") |
csmartdalton | 4b5179b | 2016-09-19 11:03:58 -0700 | [diff] [blame] | 39 | __argparse.add_argument('-m', '--max-stddev', |
Kevin Lubick | 9c2249f | 2016-11-10 14:19:00 -0500 | [diff] [blame] | 40 | type=float, default=4, |
| 41 | help="initial max allowable relative standard deviation") |
csmartdalton | 4b5179b | 2016-09-19 11:03:58 -0700 | [diff] [blame] | 42 | __argparse.add_argument('-x', '--suffix', |
Kevin Lubick | 9c2249f | 2016-11-10 14:19:00 -0500 | [diff] [blame] | 43 | help="suffix to append on config (e.g. '_before', '_after')") |
csmartdalton | 4b5179b | 2016-09-19 11:03:58 -0700 | [diff] [blame] | 44 | __argparse.add_argument('-w','--write-path', |
Kevin Lubick | 9c2249f | 2016-11-10 14:19:00 -0500 | [diff] [blame] | 45 | help="directory to save .png proofs to disk.") |
csmartdalton | 4b5179b | 2016-09-19 11:03:58 -0700 | [diff] [blame] | 46 | __argparse.add_argument('-v','--verbosity', |
Kevin Lubick | 9c2249f | 2016-11-10 14:19:00 -0500 | [diff] [blame] | 47 | type=int, default=1, help="level of verbosity (0=none to 5=debug)") |
csmartdalton | 037adf3 | 2016-09-28 13:56:01 -0700 | [diff] [blame] | 48 | __argparse.add_argument('-d', '--duration', |
Kevin Lubick | 9c2249f | 2016-11-10 14:19:00 -0500 | [diff] [blame] | 49 | type=int, help="number of milliseconds to run each benchmark") |
csmartdalton | 037adf3 | 2016-09-28 13:56:01 -0700 | [diff] [blame] | 50 | __argparse.add_argument('-l', '--sample-ms', |
Kevin Lubick | 9c2249f | 2016-11-10 14:19:00 -0500 | [diff] [blame] | 51 | type=int, help="duration of a sample (minimum)") |
csmartdalton | c6618dd | 2016-10-05 08:42:03 -0700 | [diff] [blame] | 52 | __argparse.add_argument('--gpu', |
Kevin Lubick | 9c2249f | 2016-11-10 14:19:00 -0500 | [diff] [blame] | 53 | action='store_true', |
| 54 | help="perform timing on the gpu clock instead of cpu (gpu work only)") |
csmartdalton | 4b5179b | 2016-09-19 11:03:58 -0700 | [diff] [blame] | 55 | __argparse.add_argument('--fps', |
Kevin Lubick | 9c2249f | 2016-11-10 14:19:00 -0500 | [diff] [blame] | 56 | action='store_true', help="use fps instead of ms") |
csmartdalton | 4b5179b | 2016-09-19 11:03:58 -0700 | [diff] [blame] | 57 | __argparse.add_argument('-c', '--config', |
Brian Salomon | 50f66d8 | 2017-03-17 14:32:05 -0400 | [diff] [blame] | 58 | default='gl', help="comma- or space-separated list of GPU configs") |
csmartdalton | 49df770 | 2016-11-10 10:36:28 -0500 | [diff] [blame] | 59 | __argparse.add_argument('-a', '--resultsfile', |
Kevin Lubick | 9c2249f | 2016-11-10 14:19:00 -0500 | [diff] [blame] | 60 | help="optional file to append results into") |
csmartdalton | 4b5179b | 2016-09-19 11:03:58 -0700 | [diff] [blame] | 61 | __argparse.add_argument('skps', |
Kevin Lubick | 9c2249f | 2016-11-10 14:19:00 -0500 | [diff] [blame] | 62 | nargs='+', |
| 63 | help=".skp files or directories to expand for .skp files") |
csmartdalton | 4b5179b | 2016-09-19 11:03:58 -0700 | [diff] [blame] | 64 | |
| 65 | FLAGS = __argparse.parse_args() |
csmartdalton | 0262b5c | 2016-09-19 12:04:56 -0700 | [diff] [blame] | 66 | if FLAGS.adb: |
| 67 | import _adb_path as _path |
csmartdalton | d7a9db6 | 2016-09-22 05:10:02 -0700 | [diff] [blame] | 68 | _path.init(FLAGS.device_serial) |
csmartdalton | 0262b5c | 2016-09-19 12:04:56 -0700 | [diff] [blame] | 69 | else: |
| 70 | import _os_path as _path |
csmartdalton | 4b5179b | 2016-09-19 11:03:58 -0700 | [diff] [blame] | 71 | |
csmartdalton | 5772eaa | 2016-10-11 18:28:54 -0700 | [diff] [blame] | 72 | def dump_commandline_if_verbose(commandline): |
csmartdalton | e4fd078 | 2016-11-09 08:41:23 -0800 | [diff] [blame] | 73 | if FLAGS.verbosity >= 5: |
csmartdalton | 5772eaa | 2016-10-11 18:28:54 -0700 | [diff] [blame] | 74 | quoted = ['\'%s\'' % re.sub(r'([\\\'])', r'\\\1', x) for x in commandline] |
| 75 | print(' '.join(quoted), file=sys.stderr) |
| 76 | |
csmartdalton | 4b5179b | 2016-09-19 11:03:58 -0700 | [diff] [blame] | 77 | |
| 78 | class StddevException(Exception): |
| 79 | pass |
| 80 | |
| 81 | class Message: |
| 82 | READLINE = 0, |
csmartdalton | d7a9db6 | 2016-09-22 05:10:02 -0700 | [diff] [blame] | 83 | POLL_HARDWARE = 1, |
| 84 | EXIT = 2 |
csmartdalton | 4b5179b | 2016-09-19 11:03:58 -0700 | [diff] [blame] | 85 | def __init__(self, message, value=None): |
| 86 | self.message = message |
| 87 | self.value = value |
| 88 | |
csmartdalton | d7a9db6 | 2016-09-22 05:10:02 -0700 | [diff] [blame] | 89 | class SubprocessMonitor(Thread): |
| 90 | def __init__(self, queue, proc): |
| 91 | self._queue = queue |
| 92 | self._proc = proc |
| 93 | Thread.__init__(self) |
| 94 | |
| 95 | def run(self): |
csmartdalton | bf41fa8 | 2016-09-23 11:36:11 -0700 | [diff] [blame] | 96 | """Runs on the background thread.""" |
csmartdalton | d7a9db6 | 2016-09-22 05:10:02 -0700 | [diff] [blame] | 97 | for line in iter(self._proc.stdout.readline, b''): |
| 98 | self._queue.put(Message(Message.READLINE, line.decode('utf-8').rstrip())) |
| 99 | self._queue.put(Message(Message.EXIT)) |
| 100 | |
| 101 | class SKPBench: |
csmartdalton | 2087dda | 2016-11-09 16:34:53 -0500 | [diff] [blame] | 102 | ARGV = [FLAGS.skpbench, '--verbosity', str(FLAGS.verbosity)] |
csmartdalton | 037adf3 | 2016-09-28 13:56:01 -0700 | [diff] [blame] | 103 | if FLAGS.duration: |
| 104 | ARGV.extend(['--duration', str(FLAGS.duration)]) |
csmartdalton | 4b5179b | 2016-09-19 11:03:58 -0700 | [diff] [blame] | 105 | if FLAGS.sample_ms: |
| 106 | ARGV.extend(['--sampleMs', str(FLAGS.sample_ms)]) |
csmartdalton | c6618dd | 2016-10-05 08:42:03 -0700 | [diff] [blame] | 107 | if FLAGS.gpu: |
| 108 | ARGV.extend(['--gpuClock', 'true']) |
csmartdalton | 4b5179b | 2016-09-19 11:03:58 -0700 | [diff] [blame] | 109 | if FLAGS.fps: |
| 110 | ARGV.extend(['--fps', 'true']) |
csmartdalton | 0262b5c | 2016-09-19 12:04:56 -0700 | [diff] [blame] | 111 | if FLAGS.adb: |
| 112 | if FLAGS.device_serial is None: |
csmartdalton | 2087dda | 2016-11-09 16:34:53 -0500 | [diff] [blame] | 113 | ARGV[:0] = ['adb', 'shell'] |
csmartdalton | 0262b5c | 2016-09-19 12:04:56 -0700 | [diff] [blame] | 114 | else: |
csmartdalton | 2087dda | 2016-11-09 16:34:53 -0500 | [diff] [blame] | 115 | ARGV[:0] = ['adb', '-s', FLAGS.device_serial, 'shell'] |
csmartdalton | 4b5179b | 2016-09-19 11:03:58 -0700 | [diff] [blame] | 116 | |
| 117 | @classmethod |
csmartdalton | 49df770 | 2016-11-10 10:36:28 -0500 | [diff] [blame] | 118 | def get_header(cls, outfile=sys.stdout): |
csmartdalton | 5772eaa | 2016-10-11 18:28:54 -0700 | [diff] [blame] | 119 | commandline = cls.ARGV + ['--duration', '0'] |
| 120 | dump_commandline_if_verbose(commandline) |
csmartdalton | 49df770 | 2016-11-10 10:36:28 -0500 | [diff] [blame] | 121 | out = subprocess.check_output(commandline, stderr=subprocess.STDOUT) |
| 122 | return out.rstrip() |
csmartdalton | 5772eaa | 2016-10-11 18:28:54 -0700 | [diff] [blame] | 123 | |
| 124 | @classmethod |
Brian Salomon | 50f66d8 | 2017-03-17 14:32:05 -0400 | [diff] [blame] | 125 | def run_warmup(cls, warmup_time, config): |
csmartdalton | 5772eaa | 2016-10-11 18:28:54 -0700 | [diff] [blame] | 126 | if not warmup_time: |
| 127 | return |
csmartdalton | 310d72c | 2016-10-18 09:19:50 -0700 | [diff] [blame] | 128 | print('running %i second warmup...' % warmup_time, file=sys.stderr) |
csmartdalton | 5772eaa | 2016-10-11 18:28:54 -0700 | [diff] [blame] | 129 | commandline = cls.ARGV + ['--duration', str(warmup_time * 1000), |
Brian Salomon | 50f66d8 | 2017-03-17 14:32:05 -0400 | [diff] [blame] | 130 | '--config', config, |
csmartdalton | 5772eaa | 2016-10-11 18:28:54 -0700 | [diff] [blame] | 131 | '--skp', 'warmup'] |
| 132 | dump_commandline_if_verbose(commandline) |
csmartdalton | f2b024d | 2016-11-09 13:25:23 -0800 | [diff] [blame] | 133 | output = subprocess.check_output(commandline, stderr=subprocess.STDOUT) |
| 134 | |
csmartdalton | 5772eaa | 2016-10-11 18:28:54 -0700 | [diff] [blame] | 135 | # validate the warmup run output. |
csmartdalton | f2b024d | 2016-11-09 13:25:23 -0800 | [diff] [blame] | 136 | for line in output.decode('utf-8').split('\n'): |
csmartdalton | 5772eaa | 2016-10-11 18:28:54 -0700 | [diff] [blame] | 137 | match = BenchResult.match(line.rstrip()) |
| 138 | if match and match.bench == 'warmup': |
| 139 | return |
| 140 | raise Exception('Invalid warmup output:\n%s' % output) |
csmartdalton | 4b5179b | 2016-09-19 11:03:58 -0700 | [diff] [blame] | 141 | |
| 142 | def __init__(self, skp, config, max_stddev, best_result=None): |
| 143 | self.skp = skp |
| 144 | self.config = config |
| 145 | self.max_stddev = max_stddev |
| 146 | self.best_result = best_result |
| 147 | self._queue = Queue() |
csmartdalton | d7a9db6 | 2016-09-22 05:10:02 -0700 | [diff] [blame] | 148 | self._proc = None |
| 149 | self._monitor = None |
| 150 | self._hw_poll_timer = None |
csmartdalton | 4b5179b | 2016-09-19 11:03:58 -0700 | [diff] [blame] | 151 | |
csmartdalton | d7a9db6 | 2016-09-22 05:10:02 -0700 | [diff] [blame] | 152 | def __enter__(self): |
| 153 | return self |
| 154 | |
| 155 | def __exit__(self, exception_type, exception_value, traceback): |
| 156 | if self._proc: |
| 157 | self.terminate() |
| 158 | if self._hw_poll_timer: |
| 159 | self._hw_poll_timer.cancel() |
| 160 | |
| 161 | def execute(self, hardware): |
| 162 | hardware.sanity_check() |
| 163 | self._schedule_hardware_poll() |
| 164 | |
| 165 | commandline = self.ARGV + ['--config', self.config, |
| 166 | '--skp', self.skp, |
| 167 | '--suppressHeader', 'true'] |
| 168 | if FLAGS.write_path: |
| 169 | pngfile = _path.join(FLAGS.write_path, self.config, |
| 170 | _path.basename(self.skp) + '.png') |
| 171 | commandline.extend(['--png', pngfile]) |
csmartdalton | 5772eaa | 2016-10-11 18:28:54 -0700 | [diff] [blame] | 172 | dump_commandline_if_verbose(commandline) |
csmartdalton | f2b024d | 2016-11-09 13:25:23 -0800 | [diff] [blame] | 173 | self._proc = subprocess.Popen(commandline, stdout=subprocess.PIPE, |
| 174 | stderr=subprocess.STDOUT) |
csmartdalton | d7a9db6 | 2016-09-22 05:10:02 -0700 | [diff] [blame] | 175 | self._monitor = SubprocessMonitor(self._queue, self._proc) |
| 176 | self._monitor.start() |
| 177 | |
csmartdalton | 4b5179b | 2016-09-19 11:03:58 -0700 | [diff] [blame] | 178 | while True: |
| 179 | message = self._queue.get() |
| 180 | if message.message == Message.READLINE: |
| 181 | result = BenchResult.match(message.value) |
| 182 | if result: |
csmartdalton | d7a9db6 | 2016-09-22 05:10:02 -0700 | [diff] [blame] | 183 | hardware.sanity_check() |
| 184 | self._process_result(result) |
csmartdalton | f2b024d | 2016-11-09 13:25:23 -0800 | [diff] [blame] | 185 | elif hardware.filter_line(message.value): |
csmartdalton | 310d72c | 2016-10-18 09:19:50 -0700 | [diff] [blame] | 186 | print(message.value, file=sys.stderr) |
csmartdalton | 4b5179b | 2016-09-19 11:03:58 -0700 | [diff] [blame] | 187 | continue |
csmartdalton | d7a9db6 | 2016-09-22 05:10:02 -0700 | [diff] [blame] | 188 | if message.message == Message.POLL_HARDWARE: |
| 189 | hardware.sanity_check() |
| 190 | self._schedule_hardware_poll() |
| 191 | continue |
csmartdalton | 4b5179b | 2016-09-19 11:03:58 -0700 | [diff] [blame] | 192 | if message.message == Message.EXIT: |
csmartdalton | d7a9db6 | 2016-09-22 05:10:02 -0700 | [diff] [blame] | 193 | self._monitor.join() |
| 194 | self._proc.wait() |
| 195 | if self._proc.returncode != 0: |
| 196 | raise Exception("skpbench exited with nonzero exit code %i" % |
| 197 | self._proc.returncode) |
| 198 | self._proc = None |
csmartdalton | 4b5179b | 2016-09-19 11:03:58 -0700 | [diff] [blame] | 199 | break |
| 200 | |
csmartdalton | d7a9db6 | 2016-09-22 05:10:02 -0700 | [diff] [blame] | 201 | def _schedule_hardware_poll(self): |
| 202 | if self._hw_poll_timer: |
| 203 | self._hw_poll_timer.cancel() |
| 204 | self._hw_poll_timer = \ |
| 205 | Timer(1, lambda: self._queue.put(Message(Message.POLL_HARDWARE))) |
| 206 | self._hw_poll_timer.start() |
| 207 | |
| 208 | def _process_result(self, result): |
csmartdalton | 4b5179b | 2016-09-19 11:03:58 -0700 | [diff] [blame] | 209 | if not self.best_result or result.stddev <= self.best_result.stddev: |
| 210 | self.best_result = result |
csmartdalton | d7a9db6 | 2016-09-22 05:10:02 -0700 | [diff] [blame] | 211 | elif FLAGS.verbosity >= 2: |
| 212 | print("reusing previous result for %s/%s with lower stddev " |
| 213 | "(%s%% instead of %s%%)." % |
csmartdalton | 4b5179b | 2016-09-19 11:03:58 -0700 | [diff] [blame] | 214 | (result.config, result.bench, self.best_result.stddev, |
| 215 | result.stddev), file=sys.stderr) |
| 216 | if self.max_stddev and self.best_result.stddev > self.max_stddev: |
| 217 | raise StddevException() |
csmartdalton | 4b5179b | 2016-09-19 11:03:58 -0700 | [diff] [blame] | 218 | |
csmartdalton | d7a9db6 | 2016-09-22 05:10:02 -0700 | [diff] [blame] | 219 | def terminate(self): |
| 220 | if self._proc: |
csmartdalton | c6618dd | 2016-10-05 08:42:03 -0700 | [diff] [blame] | 221 | self._proc.terminate() |
csmartdalton | d7a9db6 | 2016-09-22 05:10:02 -0700 | [diff] [blame] | 222 | self._monitor.join() |
| 223 | self._proc.wait() |
| 224 | self._proc = None |
csmartdalton | 4b5179b | 2016-09-19 11:03:58 -0700 | [diff] [blame] | 225 | |
csmartdalton | 49df770 | 2016-11-10 10:36:28 -0500 | [diff] [blame] | 226 | def emit_result(line, resultsfile=None): |
| 227 | print(line) |
| 228 | sys.stdout.flush() |
| 229 | if resultsfile: |
| 230 | print(line, file=resultsfile) |
| 231 | resultsfile.flush() |
csmartdalton | 4b5179b | 2016-09-19 11:03:58 -0700 | [diff] [blame] | 232 | |
csmartdalton | 49df770 | 2016-11-10 10:36:28 -0500 | [diff] [blame] | 233 | def run_benchmarks(configs, skps, hardware, resultsfile=None): |
| 234 | emit_result(SKPBench.get_header(), resultsfile) |
csmartdalton | 4b5179b | 2016-09-19 11:03:58 -0700 | [diff] [blame] | 235 | benches = collections.deque([(skp, config, FLAGS.max_stddev) |
| 236 | for skp in skps |
| 237 | for config in configs]) |
| 238 | while benches: |
| 239 | benchargs = benches.popleft() |
csmartdalton | d7a9db6 | 2016-09-22 05:10:02 -0700 | [diff] [blame] | 240 | with SKPBench(*benchargs) as skpbench: |
| 241 | try: |
| 242 | skpbench.execute(hardware) |
| 243 | if skpbench.best_result: |
csmartdalton | 49df770 | 2016-11-10 10:36:28 -0500 | [diff] [blame] | 244 | emit_result(skpbench.best_result.format(FLAGS.suffix), resultsfile) |
csmartdalton | d7a9db6 | 2016-09-22 05:10:02 -0700 | [diff] [blame] | 245 | else: |
| 246 | print("WARNING: no result for %s with config %s" % |
| 247 | (skpbench.skp, skpbench.config), file=sys.stderr) |
csmartdalton | 4b5179b | 2016-09-19 11:03:58 -0700 | [diff] [blame] | 248 | |
csmartdalton | d7a9db6 | 2016-09-22 05:10:02 -0700 | [diff] [blame] | 249 | except StddevException: |
| 250 | retry_max_stddev = skpbench.max_stddev * math.sqrt(2) |
csmartdalton | 6904b19 | 2016-09-29 06:23:23 -0700 | [diff] [blame] | 251 | if FLAGS.verbosity >= 1: |
csmartdalton | d7a9db6 | 2016-09-22 05:10:02 -0700 | [diff] [blame] | 252 | print("stddev is too high for %s/%s (%s%%, max=%.2f%%), " |
| 253 | "re-queuing with max=%.2f%%." % |
| 254 | (skpbench.best_result.config, skpbench.best_result.bench, |
| 255 | skpbench.best_result.stddev, skpbench.max_stddev, |
| 256 | retry_max_stddev), |
| 257 | file=sys.stderr) |
| 258 | benches.append((skpbench.skp, skpbench.config, retry_max_stddev, |
| 259 | skpbench.best_result)) |
| 260 | |
| 261 | except HardwareException as exception: |
csmartdalton | 310d72c | 2016-10-18 09:19:50 -0700 | [diff] [blame] | 262 | skpbench.terminate() |
csmartdalton | e4fd078 | 2016-11-09 08:41:23 -0800 | [diff] [blame] | 263 | if FLAGS.verbosity >= 4: |
csmartdalton | 2a96101 | 2016-10-11 12:15:13 -0700 | [diff] [blame] | 264 | hardware.print_debug_diagnostics() |
csmartdalton | d7a9db6 | 2016-09-22 05:10:02 -0700 | [diff] [blame] | 265 | if FLAGS.verbosity >= 1: |
| 266 | print("%s; taking a %i second nap..." % |
csmartdalton | 5772eaa | 2016-10-11 18:28:54 -0700 | [diff] [blame] | 267 | (exception.message, exception.sleeptime), file=sys.stderr) |
csmartdalton | d7a9db6 | 2016-09-22 05:10:02 -0700 | [diff] [blame] | 268 | benches.appendleft(benchargs) # retry the same bench next time. |
csmartdalton | 5772eaa | 2016-10-11 18:28:54 -0700 | [diff] [blame] | 269 | hardware.sleep(exception.sleeptime) |
csmartdalton | e4fd078 | 2016-11-09 08:41:23 -0800 | [diff] [blame] | 270 | if FLAGS.verbosity >= 4: |
csmartdalton | 310d72c | 2016-10-18 09:19:50 -0700 | [diff] [blame] | 271 | hardware.print_debug_diagnostics() |
Brian Salomon | 50f66d8 | 2017-03-17 14:32:05 -0400 | [diff] [blame] | 272 | SKPBench.run_warmup(hardware.warmup_time, configs[0]) |
csmartdalton | d7a9db6 | 2016-09-22 05:10:02 -0700 | [diff] [blame] | 273 | |
csmartdalton | d7a9db6 | 2016-09-22 05:10:02 -0700 | [diff] [blame] | 274 | def main(): |
| 275 | # Delimiter is ',' or ' ', skip if nested inside parens (e.g. gpu(a=b,c=d)). |
| 276 | DELIMITER = r'[, ](?!(?:[^(]*\([^)]*\))*[^()]*\))' |
| 277 | configs = re.split(DELIMITER, FLAGS.config) |
| 278 | skps = _path.find_skps(FLAGS.skps) |
| 279 | |
| 280 | if FLAGS.adb: |
csmartdalton | a115129 | 2016-11-09 15:37:48 -0500 | [diff] [blame] | 281 | adb = Adb(FLAGS.device_serial, echo=(FLAGS.verbosity >= 5)) |
csmartdalton | e4fd078 | 2016-11-09 08:41:23 -0800 | [diff] [blame] | 282 | model = adb.check('getprop ro.product.model').strip() |
csmartdalton | bf41fa8 | 2016-09-23 11:36:11 -0700 | [diff] [blame] | 283 | if model == 'Pixel C': |
| 284 | from _hardware_pixel_c import HardwarePixelC |
| 285 | hardware = HardwarePixelC(adb) |
csmartdalton | 310d72c | 2016-10-18 09:19:50 -0700 | [diff] [blame] | 286 | elif model == 'Nexus 6P': |
| 287 | from _hardware_nexus_6p import HardwareNexus6P |
| 288 | hardware = HardwareNexus6P(adb) |
csmartdalton | d7a9db6 | 2016-09-22 05:10:02 -0700 | [diff] [blame] | 289 | else: |
| 290 | from _hardware_android import HardwareAndroid |
| 291 | print("WARNING: %s: don't know how to monitor this hardware; results " |
| 292 | "may be unreliable." % model, file=sys.stderr) |
| 293 | hardware = HardwareAndroid(adb) |
| 294 | else: |
| 295 | hardware = Hardware() |
| 296 | |
| 297 | with hardware: |
Brian Salomon | 50f66d8 | 2017-03-17 14:32:05 -0400 | [diff] [blame] | 298 | SKPBench.run_warmup(hardware.warmup_time, configs[0]) |
csmartdalton | 49df770 | 2016-11-10 10:36:28 -0500 | [diff] [blame] | 299 | if FLAGS.resultsfile: |
| 300 | with open(FLAGS.resultsfile, mode='a+') as resultsfile: |
| 301 | run_benchmarks(configs, skps, hardware, resultsfile=resultsfile) |
| 302 | else: |
| 303 | run_benchmarks(configs, skps, hardware) |
csmartdalton | 4b5179b | 2016-09-19 11:03:58 -0700 | [diff] [blame] | 304 | |
| 305 | |
| 306 | if __name__ == '__main__': |
| 307 | main() |