Joel Fernandes b5fbd41b23 JankBench: make it build and run in Android build
JankBench is a tool heavily used for scheduler and graphics testing.
JankBench has been an android studio project and traditionally its APK
has been built outside of the Android tree using studio. This patch
makes it possible to build it using Android source tree without needing
studio.

Some library imports needed renaming and an xml file had a typo, also
resource IDs need to be 16-bits so I fixed that up. List fragments can't
be anonymous instantiations anymore so changed it to be non-anonymous.

Bug: 31544438
Test: Run all Jankbench benchmarks manually in the app.
Change-Id: Ib5e4351fcc72acdec20424ae30598c205e7803f7
Signed-off-by: Joel Fernandes <joelaf@google.com>
2017-12-22 20:23:30 +00:00

63 lines
1.9 KiB
Python

import subprocess
import re
import threading
ATRACE_PATH="/android/catapult/systrace/systrace/systrace.py"
class AdbError(RuntimeError):
def __init__(self, arg):
self.args = arg
def am(serial, cmd, args):
if not isinstance(args, list):
args = [args]
full_args = ["am"] + [cmd] + args
__call_adb(serial, full_args, False)
def pm(serial, cmd, args):
if not isinstance(args, list):
args = [args]
full_args = ["pm"] + [cmd] + args
__call_adb(serial, full_args, False)
def dumpsys(serial, topic):
return __call_adb(serial, ["dumpsys"] + [topic], True)
def trace(serial,
tags = ["gfx", "sched", "view", "freq", "am", "wm", "power", "load", "memreclaim"],
time = "10"):
args = [ATRACE_PATH, "-e", serial, "-t" + time, "-b32768"] + tags
subprocess.call(args)
def wake(serial):
output = dumpsys(serial, "power")
wakefulness = re.search('mWakefulness=([a-zA-Z]+)', output)
if wakefulness.group(1) != "Awake":
__call_adb(serial, ["input", "keyevent", "KEYCODE_POWER"], False)
def root(serial):
subprocess.call(["adb", "-s", serial, "root"])
def pull(serial, path, dest):
subprocess.call(["adb", "-s", serial, "wait-for-device", "pull"] + [path] + [dest])
def shell(serial, cmd):
__call_adb(serial, cmd, False)
def track_logcat(serial, awaited_string, callback):
threading.Thread(target=__track_logcat, name=serial + "-waiter", args=(serial, awaited_string, callback)).start()
def __call_adb(serial, args, block):
full_args = ["adb", "-s", serial, "wait-for-device", "shell"] + args
print full_args
output = None
try:
if block:
output = subprocess.check_output(full_args)
else:
subprocess.call(full_args)
except subprocess.CalledProcessError:
raise AdbError("Error calling " + " ".join(args))
return output