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 |
11 from _hardware import HardwareException, Hardware | 11 from _hardware import HardwareException, Hardware |
12 from argparse import ArgumentParser | 12 from argparse import ArgumentParser |
13 from multiprocessing import Queue | 13 from multiprocessing import Queue |
14 from threading import Thread, Timer | 14 from threading import Thread, Timer |
15 import collections | 15 import collections |
16 import glob | 16 import glob |
17 import math | 17 import math |
18 import re | 18 import re |
19 import subprocess | 19 import subprocess |
20 import sys | 20 import sys |
21 import time | 21 import time |
22 | 22 |
23 __argparse = ArgumentParser(description=''' | 23 __argparse = ArgumentParser(description=""" |
24 | 24 |
25 Executes the skpbench binary with various configs and skps. | 25 Executes the skpbench binary with various configs and skps. |
26 | 26 |
27 Also monitors the output in order to filter out and re-run results that have an | 27 Also monitors the output in order to filter out and re-run results that have an |
28 unacceptable stddev. | 28 unacceptable stddev. |
29 | 29 |
30 ''') | 30 """) |
31 | 31 |
32 __argparse.add_argument('--adb', | 32 __argparse.add_argument('--adb', |
33 action='store_true', help="execute skpbench over adb") | 33 action='store_true', help="execute skpbench over adb") |
34 __argparse.add_argument('-s', '--device-serial', | 34 __argparse.add_argument('-s', '--device-serial', |
35 help="if using adb, id of the specific device to target") | 35 help="if using adb, id of the specific device to target") |
36 __argparse.add_argument('-p', '--path', | 36 __argparse.add_argument('-p', '--path', |
37 help="directory to execute ./skpbench from") | 37 help="directory to execute ./skpbench from") |
38 __argparse.add_argument('-m', '--max-stddev', | 38 __argparse.add_argument('-m', '--max-stddev', |
39 type=float, default=4, | 39 type=float, default=4, |
40 help="initial max allowable relative standard deviation") | 40 help="initial max allowable relative standard deviation") |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 self.message = message | 75 self.message = message |
76 self.value = value | 76 self.value = value |
77 | 77 |
78 class SubprocessMonitor(Thread): | 78 class SubprocessMonitor(Thread): |
79 def __init__(self, queue, proc): | 79 def __init__(self, queue, proc): |
80 self._queue = queue | 80 self._queue = queue |
81 self._proc = proc | 81 self._proc = proc |
82 Thread.__init__(self) | 82 Thread.__init__(self) |
83 | 83 |
84 def run(self): | 84 def run(self): |
85 '''Runs on the background thread.''' | 85 """Runs on the background thread.""" |
86 for line in iter(self._proc.stdout.readline, b''): | 86 for line in iter(self._proc.stdout.readline, b''): |
87 self._queue.put(Message(Message.READLINE, line.decode('utf-8').rstrip())) | 87 self._queue.put(Message(Message.READLINE, line.decode('utf-8').rstrip())) |
88 self._queue.put(Message(Message.EXIT)) | 88 self._queue.put(Message(Message.EXIT)) |
89 | 89 |
90 class SKPBench: | 90 class SKPBench: |
91 ARGV = ['skpbench', '--verbosity', str(FLAGS.verbosity)] | 91 ARGV = ['skpbench', '--verbosity', str(FLAGS.verbosity)] |
92 if FLAGS.samples: | 92 if FLAGS.samples: |
93 ARGV.extend(['--samples', str(FLAGS.samples)]) | 93 ARGV.extend(['--samples', str(FLAGS.samples)]) |
94 if FLAGS.sample_ms: | 94 if FLAGS.sample_ms: |
95 ARGV.extend(['--sampleMs', str(FLAGS.sample_ms)]) | 95 ARGV.extend(['--sampleMs', str(FLAGS.sample_ms)]) |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 | 236 |
237 def main(): | 237 def main(): |
238 # Delimiter is ',' or ' ', skip if nested inside parens (e.g. gpu(a=b,c=d)). | 238 # Delimiter is ',' or ' ', skip if nested inside parens (e.g. gpu(a=b,c=d)). |
239 DELIMITER = r'[, ](?!(?:[^(]*\([^)]*\))*[^()]*\))' | 239 DELIMITER = r'[, ](?!(?:[^(]*\([^)]*\))*[^()]*\))' |
240 configs = re.split(DELIMITER, FLAGS.config) | 240 configs = re.split(DELIMITER, FLAGS.config) |
241 skps = _path.find_skps(FLAGS.skps) | 241 skps = _path.find_skps(FLAGS.skps) |
242 | 242 |
243 if FLAGS.adb: | 243 if FLAGS.adb: |
244 adb = Adb(FLAGS.device_serial) | 244 adb = Adb(FLAGS.device_serial) |
245 model = adb.get_device_model() | 245 model = adb.get_device_model() |
246 if False: | 246 if model == 'Pixel C': |
247 pass # TODO: unique subclasses tailored to individual platforms. | 247 from _hardware_pixel_c import HardwarePixelC |
| 248 hardware = HardwarePixelC(adb) |
248 else: | 249 else: |
249 from _hardware_android import HardwareAndroid | 250 from _hardware_android import HardwareAndroid |
250 print("WARNING: %s: don't know how to monitor this hardware; results " | 251 print("WARNING: %s: don't know how to monitor this hardware; results " |
251 "may be unreliable." % model, file=sys.stderr) | 252 "may be unreliable." % model, file=sys.stderr) |
252 hardware = HardwareAndroid(adb) | 253 hardware = HardwareAndroid(adb) |
253 else: | 254 else: |
254 hardware = Hardware() | 255 hardware = Hardware() |
255 | 256 |
256 with hardware: | 257 with hardware: |
257 if hardware.kick_in_time: | 258 if hardware.kick_in_time: |
258 print("sleeping %i seconds to allow hardware settings to kick in..." % | 259 print("sleeping %i seconds to allow hardware settings to kick in..." % |
259 hardware.kick_in_time, file=sys.stderr) | 260 hardware.kick_in_time, file=sys.stderr) |
260 time.sleep(hardware.kick_in_time) | 261 time.sleep(hardware.kick_in_time) |
261 run_benchmarks(configs, skps, hardware) | 262 run_benchmarks(configs, skps, hardware) |
262 | 263 |
263 | 264 |
264 if __name__ == '__main__': | 265 if __name__ == '__main__': |
265 main() | 266 main() |
OLD | NEW |