2021-10-08 00:39:36 +00:00
|
|
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
|
|
|
2023-04-05 21:44:36 +00:00
|
|
|
import argparse
|
|
|
|
import os
|
2021-10-08 00:39:36 +00:00
|
|
|
import subprocess
|
|
|
|
import webbrowser
|
|
|
|
|
|
|
|
DESCRIPTION = """ This script is made to run benchmark tests on Fenix. It'll open
|
|
|
|
the JSON output file in firefox (or another browser of your choice if you pass the string in)
|
|
|
|
"""
|
|
|
|
|
2023-04-05 21:44:36 +00:00
|
|
|
ff_browser = "firefox"
|
|
|
|
target_directory = "{cwd}/app/build/".format(cwd=os.getcwd())
|
|
|
|
output_path = "/storage/emulated/0/benchmark/"
|
|
|
|
output_file = "org.mozilla.fenix-benchmarkData.json"
|
2021-10-08 00:39:36 +00:00
|
|
|
file_url = "file:///"
|
|
|
|
|
|
|
|
|
|
|
|
def parse_args():
|
|
|
|
parser = argparse.ArgumentParser(description=DESCRIPTION)
|
2023-04-05 21:44:36 +00:00
|
|
|
parser.add_argument(
|
|
|
|
"class_to_test",
|
|
|
|
help="Path to the class to test. Format it as 'org.mozilla.fenix.[path_to_benchmark_test",
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
"--open_file_in_browser",
|
|
|
|
help="Open the JSON file in the browser once the tests are done.",
|
|
|
|
)
|
2021-10-08 00:39:36 +00:00
|
|
|
return parser.parse_args()
|
|
|
|
|
|
|
|
|
|
|
|
def run_benchmark(class_to_test):
|
2023-04-05 21:44:36 +00:00
|
|
|
args = ["./gradlew", "-Pbenchmark", "app:connectedCheck"]
|
2021-10-08 00:39:36 +00:00
|
|
|
if class_to_test:
|
2023-04-05 21:44:36 +00:00
|
|
|
args.append(
|
|
|
|
"-Pandroid.testInstrumentationRunnerArguments.class={clazz}".format(
|
|
|
|
clazz=class_to_test
|
|
|
|
)
|
|
|
|
)
|
2021-10-08 00:39:36 +00:00
|
|
|
subprocess.run(args, check=True, text=True)
|
|
|
|
|
|
|
|
|
|
|
|
def fetch_benchmark_results():
|
|
|
|
subprocess.run(
|
2023-04-05 21:44:36 +00:00
|
|
|
["adb", "pull", "{path}{file}".format(path=output_path, file=output_file)],
|
|
|
|
cwd=target_directory,
|
|
|
|
check=True,
|
|
|
|
text=True,
|
|
|
|
)
|
|
|
|
print(
|
|
|
|
"The benchmark results can be seen here: {file_path}".format(
|
|
|
|
file_path=os.path.abspath("./{file}".format(file=file_url))
|
|
|
|
)
|
|
|
|
)
|
2021-10-08 00:39:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
def open_in_browser():
|
2023-04-05 21:44:36 +00:00
|
|
|
abs_path = os.path.abspath(
|
|
|
|
"{target_directory}{file}".format(
|
|
|
|
target_directory=target_directory, file=output_file
|
|
|
|
)
|
|
|
|
)
|
|
|
|
webbrowser.get(ff_browser).open_new(file_url + abs_path)
|
2021-10-08 00:39:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
args = parse_args()
|
|
|
|
run_benchmark(args.class_to_test)
|
|
|
|
fetch_benchmark_results()
|
2021-10-12 17:54:27 +00:00
|
|
|
if args.open_file_in_browser:
|
|
|
|
open_in_browser()
|
2021-10-08 00:39:36 +00:00
|
|
|
|
|
|
|
|
2023-04-05 21:44:36 +00:00
|
|
|
if __name__ == "__main__":
|
2021-10-08 00:39:36 +00:00
|
|
|
main()
|