Last active
January 15, 2020 15:26
-
-
Save stefanhuber/4e432c77995f26230814fbd9ddac0cfe to your computer and use it in GitHub Desktop.
start instrumentation with vmstat
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import subprocess | |
def start_instrumentation(package, classname, background=True): | |
if background: | |
subprocess.call("adb shell nohup am instrument -w -e debug false -e class '{package}.{classname}' {package}/androidx.test.runner.AndroidJUnitRunner > /dev/null 2>&1".format(package=package, classname=classname)) | |
else: | |
subprocess.call("adb shell am instrument -w -e debug false -e class '{package}.{classname}' {package}/androidx.test.runner.AndroidJUnitRunner".format(package=package, classname=classname)) | |
def clear_batterystats(): | |
subprocess.call("adb shell dumpsys batterystats --reset", shell=False) | |
def install_apk(apk): | |
subprocess.call("adb install -r " + apk, shell=False) | |
clear_batterystats() | |
install_apk("apks/instrumentation.apk") | |
start_instrumentation("at.stefanhuber.instrumentation", "StartStopInstrumentedTest") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import threading | |
import time | |
import subprocess | |
device = "Huawei" | |
app = "firefox" | |
recording_time = 30 | |
def install_apk(apk): | |
subprocess.call("adb install -r " + apk, shell=False) | |
def start_vmstat(recording_time, filename): | |
subprocess.call("adb shell vmstat 1 " + str(recording_time) + " > /data/local/tmp/" + filename, shell=False) | |
def start_instrumentation(package, classname, background=True): | |
if background: | |
subprocess.call("adb shell nohup am instrument -w -e debug false -e class '{package}.{classname}' {package}/androidx.test.runner.AndroidJUnitRunner > /dev/null 2>&1".format(package=package, classname=classname)) | |
else: | |
subprocess.call("adb shell am instrument -w -e debug false -e class '{package}.{classname}' {package}/androidx.test.runner.AndroidJUnitRunner".format(package=package, classname=classname)) | |
def pull_data(file, target_folder): | |
subprocess.call("adb pull " + file + " " + target_folder, shell=False) | |
install_apk("./APK/app-debug.apk") | |
for index in range(1, 31): | |
identifier = "{}_{}_{}".format(device, app, index) | |
vmstat_filename = "vmstat_{}.txt".format(identifier) | |
systrace_thread = threading.Thread(target=lambda: start_vmstat(recording_time, vmstat_filename), name="perf-vmstat-thread") | |
systrace_thread.start() | |
time.sleep(2) | |
start_time = time.time() | |
start_instrumentation("at.stefanhuber.instrumentation", "PerformanceInstrumentedTest") | |
end_time = time.time() | |
print("duration: {}".format(end_time - start_time)) | |
time.sleep(5) | |
pull_data("/data/local/tmp/" + vmstat_filename, "./data/" + vmstat_filename) | |
time.sleep(15) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment