diff --git a/tools/skpbench/_adb.py b/tools/skpbench/_adb.py new file mode 100644 index 0000000000..6125c8d538 --- /dev/null +++ b/tools/skpbench/_adb.py @@ -0,0 +1,19 @@ +# Copyright 2016 Google Inc. +# +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +import subprocess + +def shell(cmd, device_serial=None): + if device_serial is None: + subprocess.call(['adb', 'shell', cmd]) + else: + subprocess.call(['adb', '-s', device_serial, 'shell', cmd]) + +def check(cmd, device_serial=None): + if device_serial is None: + out = subprocess.check_output(['adb', 'shell', cmd]) + else: + out = subprocess.check_output(['adb', '-s', device_serial, 'shell', cmd]) + return out.rstrip() diff --git a/tools/skpbench/_adb_path.py b/tools/skpbench/_adb_path.py new file mode 100644 index 0000000000..377ba12490 --- /dev/null +++ b/tools/skpbench/_adb_path.py @@ -0,0 +1,33 @@ +# Copyright 2016 Google Inc. +# +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +import _adb +import re +import subprocess + +__ADB_DEVICE_SERIAL = None + +def set_device_serial(device_serial): + global __ADB_DEVICE_SERIAL + __ADB_DEVICE_SERIAL = device_serial + +def join(*pathnames): + return '/'.join(pathnames) + +def basename(pathname): + return pathname.rsplit('/', maxsplit=1)[-1] + +def find_skps(skps): + escapedskps = [re.sub(r'([^a-zA-Z0-9_\*\?\[\!\]])', r'\\\1', x) # Keep globs. + for x in skps] + pathnames = _adb.check(''' + for PATHNAME in %s; do + if [ -d "$PATHNAME" ]; then + ls "$PATHNAME"/*.skp + else + echo "$PATHNAME" + fi + done''' % ' '.join(escapedskps), device_serial=__ADB_DEVICE_SERIAL) + return re.split('[\r\n]+', pathnames) diff --git a/tools/skpbench/_os_path.py b/tools/skpbench/_os_path.py new file mode 100644 index 0000000000..42b1c42bf2 --- /dev/null +++ b/tools/skpbench/_os_path.py @@ -0,0 +1,22 @@ +# Copyright 2016 Google Inc. +# +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +from os import path +import glob + +def join(*pathnames): + return path.join(*pathnames) + +def basename(pathname): + return pathname.basename(pathname) + +def find_skps(skps): + pathnames = list() + for skp in skps: + if (path.isdir(skp)): + pathnames.extend(glob.iglob(path.join(skp, '*.skp'))) + else: + pathnames.append(skp) + return pathnames diff --git a/tools/skpbench/skpbench.py b/tools/skpbench/skpbench.py index f547003573..94d68b28e4 100755 --- a/tools/skpbench/skpbench.py +++ b/tools/skpbench/skpbench.py @@ -8,7 +8,6 @@ from __future__ import print_function from _benchresult import BenchResult from argparse import ArgumentParser -from os import path from queue import Queue from threading import Thread import collections @@ -27,6 +26,10 @@ unacceptable stddev. """) +__argparse.add_argument('--adb', + action='store_true', help='execute skpbench over adb') +__argparse.add_argument('-s', '--device-serial', + help='if using adb, id of the specific device to target') __argparse.add_argument('-p', '--path', help='directory to execute ./skpbench from') __argparse.add_argument('-m', '--max-stddev', @@ -51,6 +54,11 @@ __argparse.add_argument('skps', help='.skp files or directories to expand for .skp files') FLAGS = __argparse.parse_args() +if FLAGS.adb: + import _adb_path as _path + _path.set_device_serial(FLAGS.device_serial) +else: + import _os_path as _path class StddevException(Exception): @@ -65,14 +73,19 @@ class Message: class SKPBench(Thread): ARGV = ['skpbench', '--verbosity', str(FLAGS.verbosity)] - if FLAGS.path: - ARGV[0] = path.join(FLAGS.path, ARGV[0]) if FLAGS.samples: ARGV.extend(['--samples', str(FLAGS.samples)]) if FLAGS.sample_ms: ARGV.extend(['--sampleMs', str(FLAGS.sample_ms)]) if FLAGS.fps: ARGV.extend(['--fps', 'true']) + if FLAGS.path: + ARGV[0] = _path.join(FLAGS.path, ARGV[0]) + if FLAGS.adb: + if FLAGS.device_serial is None: + ARGV = ['adb', 'shell'] + ARGV + else: + ARGV = ['adb', '-s', FLAGS.device_serial, 'shell'] + ARGV @classmethod def print_header(cls): @@ -124,8 +137,8 @@ class SKPBench(Thread): '--skp', self.skp, '--suppressHeader', 'true'] if (FLAGS.write_path): - pngfile = path.join(FLAGS.write_path, self.config, - path.basename(self.skp) + '.png') + pngfile = _path.join(FLAGS.write_path, self.config, + _path.basename(self.skp) + '.png') commandline.extend(['--png', pngfile]) if (FLAGS.verbosity >= 3): print(' '.join(commandline), file=sys.stderr) @@ -142,13 +155,7 @@ def main(): # Delimiter is "," or " ", skip if nested inside parens (e.g. gpu(a=b,c=d)). DELIMITER = r'[, ](?!(?:[^(]*\([^)]*\))*[^()]*\))' configs = re.split(DELIMITER, FLAGS.config) - - skps = list() - for skp in FLAGS.skps: - if (path.isdir(skp)): - skps.extend(glob.iglob(path.join(skp, '*.skp'))) - else: - skps.append(skp) + skps = _path.find_skps(FLAGS.skps) benches = collections.deque([(skp, config, FLAGS.max_stddev) for skp in skps