summaryrefslogtreecommitdiffstats
path: root/mobile/android/fenix/tools/run_benchmark.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-15 03:34:50 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-15 03:34:50 +0000
commitdef92d1b8e9d373e2f6f27c366d578d97d8960c6 (patch)
tree2ef34b9ad8bb9a9220e05d60352558b15f513894 /mobile/android/fenix/tools/run_benchmark.py
parentAdding debian version 125.0.3-1. (diff)
downloadfirefox-def92d1b8e9d373e2f6f27c366d578d97d8960c6.tar.xz
firefox-def92d1b8e9d373e2f6f27c366d578d97d8960c6.zip
Merging upstream version 126.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'mobile/android/fenix/tools/run_benchmark.py')
-rw-r--r--mobile/android/fenix/tools/run_benchmark.py77
1 files changed, 77 insertions, 0 deletions
diff --git a/mobile/android/fenix/tools/run_benchmark.py b/mobile/android/fenix/tools/run_benchmark.py
new file mode 100644
index 0000000000..527ef2c932
--- /dev/null
+++ b/mobile/android/fenix/tools/run_benchmark.py
@@ -0,0 +1,77 @@
+# 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/.
+
+import argparse
+import os
+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)
+"""
+
+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"
+file_url = "file:///"
+
+
+def parse_args():
+ parser = argparse.ArgumentParser(description=DESCRIPTION)
+ 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.",
+ )
+ return parser.parse_args()
+
+
+def run_benchmark(class_to_test):
+ args = ["./gradlew", "-Pbenchmark", "app:connectedCheck"]
+ if class_to_test:
+ args.append(
+ "-Pandroid.testInstrumentationRunnerArguments.class={clazz}".format(
+ clazz=class_to_test
+ )
+ )
+ subprocess.run(args, check=True, text=True)
+
+
+def fetch_benchmark_results():
+ subprocess.run(
+ ["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))
+ )
+ )
+
+
+def open_in_browser():
+ 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)
+
+
+def main():
+ args = parse_args()
+ run_benchmark(args.class_to_test)
+ fetch_benchmark_results()
+ if args.open_file_in_browser:
+ open_in_browser()
+
+
+if __name__ == "__main__":
+ main()