blob: 18219eaf65c4b615b7c136301ec4d8838dad24c5 [file] [log] [blame]
csmartdalton4b5179b2016-09-19 11:03:58 -07001#!/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
8from __future__ import print_function
csmartdaltond7a9db62016-09-22 05:10:02 -07009from _adb import Adb
csmartdalton4b5179b2016-09-19 11:03:58 -070010from _benchresult import BenchResult
csmartdaltond7a9db62016-09-22 05:10:02 -070011from _hardware import HardwareException, Hardware
csmartdalton4b5179b2016-09-19 11:03:58 -070012from argparse import ArgumentParser
csmartdalton5745d792016-09-22 12:37:21 -070013from multiprocessing import Queue
csmartdaltond7a9db62016-09-22 05:10:02 -070014from threading import Thread, Timer
csmartdalton4b5179b2016-09-19 11:03:58 -070015import collections
16import glob
17import math
18import re
19import subprocess
20import sys
csmartdaltond7a9db62016-09-22 05:10:02 -070021import time
csmartdalton4b5179b2016-09-19 11:03:58 -070022
csmartdaltonbf41fa82016-09-23 11:36:11 -070023__argparse = ArgumentParser(description="""
csmartdalton4b5179b2016-09-19 11:03:58 -070024
25Executes the skpbench binary with various configs and skps.
26
27Also monitors the output in order to filter out and re-run results that have an
28unacceptable stddev.
29
csmartdaltonbf41fa82016-09-23 11:36:11 -070030""")
csmartdalton4b5179b2016-09-19 11:03:58 -070031
csmartdalton2087dda2016-11-09 16:34:53 -050032__argparse.add_argument('skpbench',
Kevin Lubick9c2249f2016-11-10 14:19:00 -050033 help="path to the skpbench binary")
csmartdalton0262b5c2016-09-19 12:04:56 -070034__argparse.add_argument('--adb',
Kevin Lubick9c2249f2016-11-10 14:19:00 -050035 action='store_true', help="execute skpbench over adb")
Chris Daltonacb549f2017-10-19 14:11:58 -060036__argparse.add_argument('--adb_binary', default='adb',
37 help="The name of the adb binary to use.")
csmartdalton0262b5c2016-09-19 12:04:56 -070038__argparse.add_argument('-s', '--device-serial',
Kevin Lubick9c2249f2016-11-10 14:19:00 -050039 help="if using adb, ID of the specific device to target "
40 "(only required if more than 1 device is attached)")
csmartdalton4b5179b2016-09-19 11:03:58 -070041__argparse.add_argument('-m', '--max-stddev',
Kevin Lubick9c2249f2016-11-10 14:19:00 -050042 type=float, default=4,
43 help="initial max allowable relative standard deviation")
csmartdalton4b5179b2016-09-19 11:03:58 -070044__argparse.add_argument('-x', '--suffix',
Kevin Lubick9c2249f2016-11-10 14:19:00 -050045 help="suffix to append on config (e.g. '_before', '_after')")
csmartdalton4b5179b2016-09-19 11:03:58 -070046__argparse.add_argument('-w','--write-path',
Kevin Lubick9c2249f2016-11-10 14:19:00 -050047 help="directory to save .png proofs to disk.")
csmartdalton4b5179b2016-09-19 11:03:58 -070048__argparse.add_argument('-v','--verbosity',
Kevin Lubick9c2249f2016-11-10 14:19:00 -050049 type=int, default=1, help="level of verbosity (0=none to 5=debug)")
csmartdalton037adf32016-09-28 13:56:01 -070050__argparse.add_argument('-d', '--duration',
Kevin Lubick9c2249f2016-11-10 14:19:00 -050051 type=int, help="number of milliseconds to run each benchmark")
csmartdalton037adf32016-09-28 13:56:01 -070052__argparse.add_argument('-l', '--sample-ms',
Kevin Lubick9c2249f2016-11-10 14:19:00 -050053 type=int, help="duration of a sample (minimum)")
csmartdaltonc6618dd2016-10-05 08:42:03 -070054__argparse.add_argument('--gpu',
Kevin Lubick9c2249f2016-11-10 14:19:00 -050055 action='store_true',
56 help="perform timing on the gpu clock instead of cpu (gpu work only)")
csmartdalton4b5179b2016-09-19 11:03:58 -070057__argparse.add_argument('--fps',
Kevin Lubick9c2249f2016-11-10 14:19:00 -050058 action='store_true', help="use fps instead of ms")
Chris Daltonacb549f2017-10-19 14:11:58 -060059__argparse.add_argument('--pr',
60 help="comma- or space-separated list of GPU path renderers, including: "
Robert Phillips84fd1c22021-03-23 13:18:36 -040061 "[[~]all [~]default [~]dashline [~]msaa [~]aaconvex "
Chris Daltonacb549f2017-10-19 14:11:58 -060062 "[~]aalinearizing [~]small [~]tess]")
Chris Daltona8fbeba2019-03-30 00:31:23 -060063__argparse.add_argument('--cc',
64 action='store_true', help="allow coverage counting shortcuts to render paths")
Chris Daltonacb549f2017-10-19 14:11:58 -060065__argparse.add_argument('--nocache',
66 action='store_true', help="disable caching of path mask textures")
Chris Dalton9278f102020-09-24 11:42:47 -060067__argparse.add_argument('--allPathsVolatile',
68 action='store_true',
69 help="Causes all GPU paths to be processed as if 'setIsVolatile' had been called.")
csmartdalton4b5179b2016-09-19 11:03:58 -070070__argparse.add_argument('-c', '--config',
Brian Salomon50f66d82017-03-17 14:32:05 -040071 default='gl', help="comma- or space-separated list of GPU configs")
csmartdalton49df7702016-11-10 10:36:28 -050072__argparse.add_argument('-a', '--resultsfile',
Kevin Lubick9c2249f2016-11-10 14:19:00 -050073 help="optional file to append results into")
Robert Phillips9619c492018-05-31 08:12:33 -040074__argparse.add_argument('--ddl',
75 action='store_true', help="record the skp into DDLs before rendering")
Nathaniel Nifongba4c3082021-02-09 08:58:00 -050076__argparse.add_argument('--lock-clocks',
77 action='store_true', help="Put device in benchmarking mode (locked clocks, no other processes)")
78__argparse.add_argument('--clock-speed',
79 type=float, default=66.0, help="A number between 0 and 100 indicating how fast to lock the CPU and GPU clock."
80 "Valid speeds are chosen from their respective available frequencies list.")
Adlai Hollere5c379d2020-05-18 10:21:53 -040081__argparse.add_argument('--ddlNumRecordingThreads',
Robert Phillips9619c492018-05-31 08:12:33 -040082 type=int, default=0,
Adlai Hollere5c379d2020-05-18 10:21:53 -040083 help="number of DDL recording threads (0=num_cores)")
Robert Phillips9619c492018-05-31 08:12:33 -040084__argparse.add_argument('--ddlTilingWidthHeight',
85 type=int, default=0, help="number of tiles along one edge when in DDL mode")
Adlai Hollerd37a0852021-04-22 11:08:12 -040086__argparse.add_argument('--dontReduceOpsTaskSplitting',
87 action='store_true', help="don't reorder GPU tasks to reduce render target swaps")
Robert Phillipsd5506cb2018-06-26 08:49:38 -040088__argparse.add_argument('--gpuThreads',
89 type=int, default=-1,
90 help="Create this many extra threads to assist with GPU work, including"
91 " software path rendering. Defaults to two.")
Chris Dalton9278f102020-09-24 11:42:47 -060092__argparse.add_argument('--internalSamples',
93 type=int, default=-1,
Chris Dalton57ab06c2021-04-22 12:57:28 -060094 help="Number of samples for internal draws that use MSAA.")
Chris Daltona4f5ce02018-06-26 10:13:06 -060095__argparse.add_argument('srcs',
Kevin Lubick9c2249f2016-11-10 14:19:00 -050096 nargs='+',
Chris Daltona4f5ce02018-06-26 10:13:06 -060097 help=".skp files or directories to expand for .skp files, and/or .svg files")
Adlai Holler53a65b22021-04-19 11:04:21 -040098__argparse.add_argument('--gpuResourceCacheLimit',
99 type=int, default=-1,
100 help="Maximum number of bytes to use for budgeted GPU resources.")
csmartdalton4b5179b2016-09-19 11:03:58 -0700101
102FLAGS = __argparse.parse_args()
csmartdalton0262b5c2016-09-19 12:04:56 -0700103if FLAGS.adb:
104 import _adb_path as _path
Kevin Lubickcccaef12017-10-13 08:15:09 -0400105 _path.init(FLAGS.device_serial, FLAGS.adb_binary)
csmartdalton0262b5c2016-09-19 12:04:56 -0700106else:
107 import _os_path as _path
csmartdalton4b5179b2016-09-19 11:03:58 -0700108
csmartdalton5772eaa2016-10-11 18:28:54 -0700109def dump_commandline_if_verbose(commandline):
csmartdaltone4fd0782016-11-09 08:41:23 -0800110 if FLAGS.verbosity >= 5:
csmartdalton5772eaa2016-10-11 18:28:54 -0700111 quoted = ['\'%s\'' % re.sub(r'([\\\'])', r'\\\1', x) for x in commandline]
112 print(' '.join(quoted), file=sys.stderr)
113
csmartdalton4b5179b2016-09-19 11:03:58 -0700114
115class StddevException(Exception):
116 pass
117
118class Message:
119 READLINE = 0,
csmartdaltond7a9db62016-09-22 05:10:02 -0700120 POLL_HARDWARE = 1,
121 EXIT = 2
csmartdalton4b5179b2016-09-19 11:03:58 -0700122 def __init__(self, message, value=None):
123 self.message = message
124 self.value = value
125
csmartdaltond7a9db62016-09-22 05:10:02 -0700126class SubprocessMonitor(Thread):
127 def __init__(self, queue, proc):
128 self._queue = queue
129 self._proc = proc
130 Thread.__init__(self)
131
132 def run(self):
csmartdaltonbf41fa82016-09-23 11:36:11 -0700133 """Runs on the background thread."""
csmartdaltond7a9db62016-09-22 05:10:02 -0700134 for line in iter(self._proc.stdout.readline, b''):
135 self._queue.put(Message(Message.READLINE, line.decode('utf-8').rstrip()))
136 self._queue.put(Message(Message.EXIT))
137
138class SKPBench:
csmartdalton2087dda2016-11-09 16:34:53 -0500139 ARGV = [FLAGS.skpbench, '--verbosity', str(FLAGS.verbosity)]
csmartdalton037adf32016-09-28 13:56:01 -0700140 if FLAGS.duration:
141 ARGV.extend(['--duration', str(FLAGS.duration)])
csmartdalton4b5179b2016-09-19 11:03:58 -0700142 if FLAGS.sample_ms:
143 ARGV.extend(['--sampleMs', str(FLAGS.sample_ms)])
csmartdaltonc6618dd2016-10-05 08:42:03 -0700144 if FLAGS.gpu:
145 ARGV.extend(['--gpuClock', 'true'])
csmartdalton4b5179b2016-09-19 11:03:58 -0700146 if FLAGS.fps:
147 ARGV.extend(['--fps', 'true'])
Chris Daltonacb549f2017-10-19 14:11:58 -0600148 if FLAGS.pr:
149 ARGV.extend(['--pr'] + re.split(r'[ ,]', FLAGS.pr))
Chris Daltona8fbeba2019-03-30 00:31:23 -0600150 if FLAGS.cc:
151 ARGV.extend(['--cc', 'true'])
Chris Daltonacb549f2017-10-19 14:11:58 -0600152 if FLAGS.nocache:
153 ARGV.extend(['--cachePathMasks', 'false'])
Chris Dalton9278f102020-09-24 11:42:47 -0600154 if FLAGS.allPathsVolatile:
155 ARGV.extend(['--allPathsVolatile', 'true'])
Robert Phillipsd5506cb2018-06-26 08:49:38 -0400156 if FLAGS.gpuThreads != -1:
157 ARGV.extend(['--gpuThreads', str(FLAGS.gpuThreads)])
Chris Dalton9278f102020-09-24 11:42:47 -0600158 if FLAGS.internalSamples != -1:
159 ARGV.extend(['--internalSamples', str(FLAGS.internalSamples)])
Robert Phillips9619c492018-05-31 08:12:33 -0400160
161 # DDL parameters
162 if FLAGS.ddl:
163 ARGV.extend(['--ddl', 'true'])
Adlai Hollere5c379d2020-05-18 10:21:53 -0400164 if FLAGS.ddlNumRecordingThreads:
165 ARGV.extend(['--ddlNumRecordingThreads',
166 str(FLAGS.ddlNumRecordingThreads)])
Robert Phillips9619c492018-05-31 08:12:33 -0400167 if FLAGS.ddlTilingWidthHeight:
168 ARGV.extend(['--ddlTilingWidthHeight', str(FLAGS.ddlTilingWidthHeight)])
169
Adlai Hollerd37a0852021-04-22 11:08:12 -0400170 if FLAGS.dontReduceOpsTaskSplitting:
171 ARGV.extend(['--dontReduceOpsTaskSplitting'])
Adlai Holler79426192021-02-12 12:17:20 -0500172
Adlai Holler53a65b22021-04-19 11:04:21 -0400173 if FLAGS.gpuResourceCacheLimit:
174 ARGV.extend(['--gpuResourceCacheLimit', str(FLAGS.gpuResourceCacheLimit)])
175
csmartdalton0262b5c2016-09-19 12:04:56 -0700176 if FLAGS.adb:
177 if FLAGS.device_serial is None:
Kevin Lubickcccaef12017-10-13 08:15:09 -0400178 ARGV[:0] = [FLAGS.adb_binary, 'shell']
csmartdalton0262b5c2016-09-19 12:04:56 -0700179 else:
Kevin Lubickcccaef12017-10-13 08:15:09 -0400180 ARGV[:0] = [FLAGS.adb_binary, '-s', FLAGS.device_serial, 'shell']
csmartdalton4b5179b2016-09-19 11:03:58 -0700181
182 @classmethod
csmartdalton49df7702016-11-10 10:36:28 -0500183 def get_header(cls, outfile=sys.stdout):
csmartdalton5772eaa2016-10-11 18:28:54 -0700184 commandline = cls.ARGV + ['--duration', '0']
185 dump_commandline_if_verbose(commandline)
Kevin Lubick60687692022-05-18 09:49:35 -0400186 out = subprocess.check_output(commandline, stderr=subprocess.STDOUT, encoding='utf-8')
csmartdalton49df7702016-11-10 10:36:28 -0500187 return out.rstrip()
csmartdalton5772eaa2016-10-11 18:28:54 -0700188
189 @classmethod
Brian Salomon50f66d82017-03-17 14:32:05 -0400190 def run_warmup(cls, warmup_time, config):
csmartdalton5772eaa2016-10-11 18:28:54 -0700191 if not warmup_time:
192 return
csmartdalton310d72c2016-10-18 09:19:50 -0700193 print('running %i second warmup...' % warmup_time, file=sys.stderr)
csmartdalton5772eaa2016-10-11 18:28:54 -0700194 commandline = cls.ARGV + ['--duration', str(warmup_time * 1000),
Brian Salomon50f66d82017-03-17 14:32:05 -0400195 '--config', config,
Chris Daltona4f5ce02018-06-26 10:13:06 -0600196 '--src', 'warmup']
csmartdalton5772eaa2016-10-11 18:28:54 -0700197 dump_commandline_if_verbose(commandline)
Kevin Lubick60687692022-05-18 09:49:35 -0400198 output = subprocess.check_output(commandline, stderr=subprocess.STDOUT, encoding='utf-8')
csmartdaltonf2b024d2016-11-09 13:25:23 -0800199
csmartdalton5772eaa2016-10-11 18:28:54 -0700200 # validate the warmup run output.
Kevin Lubick60687692022-05-18 09:49:35 -0400201 for line in output.split('\n'):
csmartdalton5772eaa2016-10-11 18:28:54 -0700202 match = BenchResult.match(line.rstrip())
203 if match and match.bench == 'warmup':
204 return
205 raise Exception('Invalid warmup output:\n%s' % output)
csmartdalton4b5179b2016-09-19 11:03:58 -0700206
Chris Daltona4f5ce02018-06-26 10:13:06 -0600207 def __init__(self, src, config, max_stddev, best_result=None):
208 self.src = src
csmartdalton4b5179b2016-09-19 11:03:58 -0700209 self.config = config
210 self.max_stddev = max_stddev
211 self.best_result = best_result
212 self._queue = Queue()
csmartdaltond7a9db62016-09-22 05:10:02 -0700213 self._proc = None
214 self._monitor = None
215 self._hw_poll_timer = None
csmartdalton4b5179b2016-09-19 11:03:58 -0700216
csmartdaltond7a9db62016-09-22 05:10:02 -0700217 def __enter__(self):
218 return self
219
220 def __exit__(self, exception_type, exception_value, traceback):
221 if self._proc:
222 self.terminate()
223 if self._hw_poll_timer:
224 self._hw_poll_timer.cancel()
225
226 def execute(self, hardware):
227 hardware.sanity_check()
228 self._schedule_hardware_poll()
229
230 commandline = self.ARGV + ['--config', self.config,
Chris Daltona4f5ce02018-06-26 10:13:06 -0600231 '--src', self.src,
csmartdaltond7a9db62016-09-22 05:10:02 -0700232 '--suppressHeader', 'true']
233 if FLAGS.write_path:
234 pngfile = _path.join(FLAGS.write_path, self.config,
Chris Daltona4f5ce02018-06-26 10:13:06 -0600235 _path.basename(self.src) + '.png')
csmartdaltond7a9db62016-09-22 05:10:02 -0700236 commandline.extend(['--png', pngfile])
csmartdalton5772eaa2016-10-11 18:28:54 -0700237 dump_commandline_if_verbose(commandline)
csmartdaltonf2b024d2016-11-09 13:25:23 -0800238 self._proc = subprocess.Popen(commandline, stdout=subprocess.PIPE,
239 stderr=subprocess.STDOUT)
csmartdaltond7a9db62016-09-22 05:10:02 -0700240 self._monitor = SubprocessMonitor(self._queue, self._proc)
241 self._monitor.start()
242
csmartdalton4b5179b2016-09-19 11:03:58 -0700243 while True:
244 message = self._queue.get()
245 if message.message == Message.READLINE:
246 result = BenchResult.match(message.value)
247 if result:
csmartdaltond7a9db62016-09-22 05:10:02 -0700248 hardware.sanity_check()
249 self._process_result(result)
csmartdaltonf2b024d2016-11-09 13:25:23 -0800250 elif hardware.filter_line(message.value):
csmartdalton310d72c2016-10-18 09:19:50 -0700251 print(message.value, file=sys.stderr)
csmartdalton4b5179b2016-09-19 11:03:58 -0700252 continue
csmartdaltond7a9db62016-09-22 05:10:02 -0700253 if message.message == Message.POLL_HARDWARE:
254 hardware.sanity_check()
255 self._schedule_hardware_poll()
256 continue
csmartdalton4b5179b2016-09-19 11:03:58 -0700257 if message.message == Message.EXIT:
csmartdaltond7a9db62016-09-22 05:10:02 -0700258 self._monitor.join()
259 self._proc.wait()
260 if self._proc.returncode != 0:
261 raise Exception("skpbench exited with nonzero exit code %i" %
262 self._proc.returncode)
263 self._proc = None
csmartdalton4b5179b2016-09-19 11:03:58 -0700264 break
265
csmartdaltond7a9db62016-09-22 05:10:02 -0700266 def _schedule_hardware_poll(self):
267 if self._hw_poll_timer:
268 self._hw_poll_timer.cancel()
269 self._hw_poll_timer = \
270 Timer(1, lambda: self._queue.put(Message(Message.POLL_HARDWARE)))
271 self._hw_poll_timer.start()
272
273 def _process_result(self, result):
csmartdalton4b5179b2016-09-19 11:03:58 -0700274 if not self.best_result or result.stddev <= self.best_result.stddev:
275 self.best_result = result
csmartdaltond7a9db62016-09-22 05:10:02 -0700276 elif FLAGS.verbosity >= 2:
277 print("reusing previous result for %s/%s with lower stddev "
278 "(%s%% instead of %s%%)." %
csmartdalton4b5179b2016-09-19 11:03:58 -0700279 (result.config, result.bench, self.best_result.stddev,
280 result.stddev), file=sys.stderr)
281 if self.max_stddev and self.best_result.stddev > self.max_stddev:
282 raise StddevException()
csmartdalton4b5179b2016-09-19 11:03:58 -0700283
csmartdaltond7a9db62016-09-22 05:10:02 -0700284 def terminate(self):
285 if self._proc:
csmartdaltonc6618dd2016-10-05 08:42:03 -0700286 self._proc.terminate()
csmartdaltond7a9db62016-09-22 05:10:02 -0700287 self._monitor.join()
288 self._proc.wait()
289 self._proc = None
csmartdalton4b5179b2016-09-19 11:03:58 -0700290
csmartdalton49df7702016-11-10 10:36:28 -0500291def emit_result(line, resultsfile=None):
292 print(line)
293 sys.stdout.flush()
294 if resultsfile:
295 print(line, file=resultsfile)
296 resultsfile.flush()
csmartdalton4b5179b2016-09-19 11:03:58 -0700297
Chris Daltona4f5ce02018-06-26 10:13:06 -0600298def run_benchmarks(configs, srcs, hardware, resultsfile=None):
Chris Dalton34d90552017-10-20 09:58:32 -0600299 hasheader = False
Chris Daltona4f5ce02018-06-26 10:13:06 -0600300 benches = collections.deque([(src, config, FLAGS.max_stddev)
301 for src in srcs
csmartdalton4b5179b2016-09-19 11:03:58 -0700302 for config in configs])
303 while benches:
Chris Dalton34d90552017-10-20 09:58:32 -0600304 try:
305 with hardware:
Brian Salomon50f66d82017-03-17 14:32:05 -0400306 SKPBench.run_warmup(hardware.warmup_time, configs[0])
Chris Dalton34d90552017-10-20 09:58:32 -0600307 if not hasheader:
308 emit_result(SKPBench.get_header(), resultsfile)
309 hasheader = True
310 while benches:
311 benchargs = benches.popleft()
312 with SKPBench(*benchargs) as skpbench:
313 try:
314 skpbench.execute(hardware)
315 if skpbench.best_result:
316 emit_result(skpbench.best_result.format(FLAGS.suffix),
317 resultsfile)
318 else:
319 print("WARNING: no result for %s with config %s" %
Chris Daltona4f5ce02018-06-26 10:13:06 -0600320 (skpbench.src, skpbench.config), file=sys.stderr)
Chris Dalton34d90552017-10-20 09:58:32 -0600321
322 except StddevException:
323 retry_max_stddev = skpbench.max_stddev * math.sqrt(2)
324 if FLAGS.verbosity >= 1:
325 print("stddev is too high for %s/%s (%s%%, max=%.2f%%), "
326 "re-queuing with max=%.2f%%." %
327 (skpbench.best_result.config, skpbench.best_result.bench,
328 skpbench.best_result.stddev, skpbench.max_stddev,
329 retry_max_stddev),
330 file=sys.stderr)
Chris Daltona4f5ce02018-06-26 10:13:06 -0600331 benches.append((skpbench.src, skpbench.config, retry_max_stddev,
Chris Dalton34d90552017-10-20 09:58:32 -0600332 skpbench.best_result))
333
334 except HardwareException as exception:
335 skpbench.terminate()
336 if FLAGS.verbosity >= 4:
337 hardware.print_debug_diagnostics()
338 if FLAGS.verbosity >= 1:
Chris Dalton49b7ed32017-10-23 17:19:37 -0600339 print("%s; rebooting and taking a %i second nap..." %
Chris Dalton34d90552017-10-20 09:58:32 -0600340 (exception.message, exception.sleeptime), file=sys.stderr)
341 benches.appendleft(benchargs) # retry the same bench next time.
342 raise # wake hw up from benchmarking mode before the nap.
343
344 except HardwareException as exception:
345 time.sleep(exception.sleeptime)
csmartdaltond7a9db62016-09-22 05:10:02 -0700346
csmartdaltond7a9db62016-09-22 05:10:02 -0700347def main():
348 # Delimiter is ',' or ' ', skip if nested inside parens (e.g. gpu(a=b,c=d)).
349 DELIMITER = r'[, ](?!(?:[^(]*\([^)]*\))*[^()]*\))'
350 configs = re.split(DELIMITER, FLAGS.config)
Chris Daltona4f5ce02018-06-26 10:13:06 -0600351 srcs = _path.find_skps(FLAGS.srcs)
Nathaniel Nifongf7cf7942019-09-11 14:00:20 -0400352 assert srcs
csmartdaltond7a9db62016-09-22 05:10:02 -0700353
Nathaniel Nifongba4c3082021-02-09 08:58:00 -0500354
csmartdaltond7a9db62016-09-22 05:10:02 -0700355 if FLAGS.adb:
Kevin Lubickcccaef12017-10-13 08:15:09 -0400356 adb = Adb(FLAGS.device_serial, FLAGS.adb_binary,
357 echo=(FLAGS.verbosity >= 5))
Nathaniel Nifongba4c3082021-02-09 08:58:00 -0500358 from _hardware_android import HardwareAndroid
359
csmartdaltone4fd0782016-11-09 08:41:23 -0800360 model = adb.check('getprop ro.product.model').strip()
csmartdaltonbf41fa82016-09-23 11:36:11 -0700361 if model == 'Pixel C':
362 from _hardware_pixel_c import HardwarePixelC
363 hardware = HardwarePixelC(adb)
Herb Derby4c3486e2020-10-05 11:20:43 -0400364 elif model == 'Pixel' or model == "Pixel XL":
Chris Dalton34d90552017-10-20 09:58:32 -0600365 from _hardware_pixel import HardwarePixel
366 hardware = HardwarePixel(adb)
Chris Dalton117d9722018-04-27 17:10:39 -0600367 elif model == 'Pixel 2':
368 from _hardware_pixel2 import HardwarePixel2
369 hardware = HardwarePixel2(adb)
csmartdalton310d72c2016-10-18 09:19:50 -0700370 elif model == 'Nexus 6P':
371 from _hardware_nexus_6p import HardwareNexus6P
372 hardware = HardwareNexus6P(adb)
Chris Dalton9278f102020-09-24 11:42:47 -0600373 else:
csmartdaltond7a9db62016-09-22 05:10:02 -0700374 print("WARNING: %s: don't know how to monitor this hardware; results "
375 "may be unreliable." % model, file=sys.stderr)
376 hardware = HardwareAndroid(adb)
Nathaniel Nifongba4c3082021-02-09 08:58:00 -0500377
378 if FLAGS.lock_clocks:
379 hardware.__enter__()
380 print("Entered benchmarking mode, not running benchmarks. Reboot to restore.");
381 return;
382
383 if FLAGS.clock_speed:
384 hardware.setDesiredClock(FLAGS.clock_speed)
csmartdaltond7a9db62016-09-22 05:10:02 -0700385 else:
386 hardware = Hardware()
387
Chris Dalton34d90552017-10-20 09:58:32 -0600388 if FLAGS.resultsfile:
389 with open(FLAGS.resultsfile, mode='a+') as resultsfile:
Chris Daltona4f5ce02018-06-26 10:13:06 -0600390 run_benchmarks(configs, srcs, hardware, resultsfile=resultsfile)
Chris Dalton34d90552017-10-20 09:58:32 -0600391 else:
Chris Daltona4f5ce02018-06-26 10:13:06 -0600392 run_benchmarks(configs, srcs, hardware)
csmartdalton4b5179b2016-09-19 11:03:58 -0700393
394
395if __name__ == '__main__':
396 main()