139 ARGV = [FLAGS.skpbench,
'--verbosity', str(FLAGS.verbosity)]
141 ARGV.extend([
'--duration', str(FLAGS.duration)])
143 ARGV.extend([
'--sampleMs', str(FLAGS.sample_ms)])
145 ARGV.extend([
'--gpuClock',
'true'])
147 ARGV.extend([
'--fps',
'true'])
149 ARGV.extend([
'--pr'] + re.split(
r'[ ,]', FLAGS.pr))
151 ARGV.extend([
'--cc',
'true'])
153 ARGV.extend([
'--cachePathMasks',
'false'])
154 if FLAGS.allPathsVolatile:
155 ARGV.extend([
'--allPathsVolatile',
'true'])
156 if FLAGS.gpuThreads != -1:
157 ARGV.extend([
'--gpuThreads', str(FLAGS.gpuThreads)])
158 if FLAGS.internalSamples != -1:
159 ARGV.extend([
'--internalSamples', str(FLAGS.internalSamples)])
163 ARGV.extend([
'--ddl',
'true'])
164 if FLAGS.ddlNumRecordingThreads:
165 ARGV.extend([
'--ddlNumRecordingThreads',
166 str(FLAGS.ddlNumRecordingThreads)])
167 if FLAGS.ddlTilingWidthHeight:
168 ARGV.extend([
'--ddlTilingWidthHeight', str(FLAGS.ddlTilingWidthHeight)])
170 if FLAGS.dontReduceOpsTaskSplitting:
171 ARGV.extend([
'--dontReduceOpsTaskSplitting'])
173 if FLAGS.gpuResourceCacheLimit:
174 ARGV.extend([
'--gpuResourceCacheLimit', str(FLAGS.gpuResourceCacheLimit)])
177 if FLAGS.device_serial
is None:
178 ARGV[:0] = [FLAGS.adb_binary,
'shell']
180 ARGV[:0] = [FLAGS.adb_binary,
'-s', FLAGS.device_serial,
'shell']
184 commandline = cls.
ARGV + [
'--duration',
'0']
186 out = subprocess.check_output(commandline, stderr=subprocess.STDOUT, encoding=
'utf-8')
193 print(
'running %i second warmup...' % warmup_time, file=sys.stderr)
194 commandline = cls.
ARGV + [
'--duration', str(warmup_time * 1000),
198 output = subprocess.check_output(commandline, stderr=subprocess.STDOUT, encoding=
'utf-8')
201 for line
in output.split(
'\n'):
202 match = BenchResult.match(line.rstrip())
203 if match
and match.bench ==
'warmup':
205 raise Exception(
'Invalid warmup output:\n%s' % output)
207 def __init__(self, src, config, max_stddev, best_result=None):
220 def __exit__(self, exception_type, exception_value, traceback):
227 hardware.sanity_check()
230 commandline = self.
ARGV + [
'--config', self.
config,
232 '--suppressHeader',
'true']
234 pngfile = _path.join(FLAGS.write_path, self.
config,
235 _path.basename(self.
src) +
'.png')
236 commandline.extend([
'--png', pngfile])
238 self.
_proc = subprocess.Popen(commandline, stdout=subprocess.PIPE,
239 stderr=subprocess.STDOUT)
244 message = self.
_queue.get()
245 if message.message == Message.READLINE:
246 result = BenchResult.match(message.value)
248 hardware.sanity_check()
250 elif hardware.filter_line(message.value):
251 print(message.value, file=sys.stderr)
253 if message.message == Message.POLL_HARDWARE:
254 hardware.sanity_check()
257 if message.message == Message.EXIT:
260 if self.
_proc.returncode != 0:
261 raise Exception(
"skpbench exited with nonzero exit code %i" %
262 self.
_proc.returncode)
270 Timer(1,
lambda: self.
_queue.put(
Message(Message.POLL_HARDWARE)))
276 elif FLAGS.verbosity >= 2:
277 print(
"reusing previous result for %s/%s with lower stddev "
278 "(%s%% instead of %s%%)." %
279 (result.config, result.bench, self.
best_result.stddev,
280 result.stddev), file=sys.stderr)
300 benches = collections.deque([(src, config, FLAGS.max_stddev)
302 for config
in configs])
306 SKPBench.run_warmup(hardware.warmup_time, configs[0])
311 benchargs = benches.popleft()
312 with SKPBench(*benchargs)
as skpbench:
314 skpbench.execute(hardware)
315 if skpbench.best_result:
316 emit_result(skpbench.best_result.format(FLAGS.suffix),
319 print(
"WARNING: no result for %s with config %s" %
320 (skpbench.src, skpbench.config), file=sys.stderr)
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,
331 benches.append((skpbench.src, skpbench.config, retry_max_stddev,
332 skpbench.best_result))
334 except HardwareException
as exception:
336 if FLAGS.verbosity >= 4:
337 hardware.print_debug_diagnostics()
338 if FLAGS.verbosity >= 1:
339 print(
"%s; rebooting and taking a %i second nap..." %
340 (exception.message, exception.sleeptime), file=sys.stderr)
341 benches.appendleft(benchargs)
344 except HardwareException
as exception:
345 time.sleep(exception.sleeptime)
349 DELIMITER =
r'[, ](?!(?:[^(]*\([^)]*\))*[^()]*\))'
350 configs = re.split(DELIMITER, FLAGS.config)
351 srcs = _path.find_skps(FLAGS.srcs)
356 adb =
Adb(FLAGS.device_serial, FLAGS.adb_binary,
357 echo=(FLAGS.verbosity >= 5))
358 from _hardware_android
import HardwareAndroid
360 model = adb.check(
'getprop ro.product.model').strip()
361 if model ==
'Pixel C':
362 from _hardware_pixel_c
import HardwarePixelC
363 hardware = HardwarePixelC(adb)
364 elif model ==
'Pixel' or model ==
"Pixel XL":
365 from _hardware_pixel
import HardwarePixel
366 hardware = HardwarePixel(adb)
367 elif model ==
'Pixel 2':
368 from _hardware_pixel2
import HardwarePixel2
369 hardware = HardwarePixel2(adb)
370 elif model ==
'Nexus 6P':
371 from _hardware_nexus_6p
import HardwareNexus6P
372 hardware = HardwareNexus6P(adb)
374 print(
"WARNING: %s: don't know how to monitor this hardware; results "
375 "may be unreliable." % model, file=sys.stderr)
376 hardware = HardwareAndroid(adb)
378 if FLAGS.lock_clocks:
380 print(
"Entered benchmarking mode, not running benchmarks. Reboot to restore.");
383 if FLAGS.clock_speed:
384 hardware.setDesiredClock(FLAGS.clock_speed)
388 if FLAGS.resultsfile:
389 with open(FLAGS.resultsfile, mode=
'a+')
as resultsfile: