From ed7ece40c9a8bdee31fb6b7b2c1db1f3c2642787 Mon Sep 17 00:00:00 2001 From: Ahmed Khaled Date: Tue, 3 Feb 2026 17:38:24 +0200 Subject: [PATCH] fix: edit how metrics json file is located also made an attempt to make the gradle benchmark run faster --- .github/scripts/run_macrobenchmarks.sh | 37 +++++++++++++++++--------- .github/scripts/step_fit.py | 2 +- .github/workflows/Build.yaml | 2 +- 3 files changed, 27 insertions(+), 14 deletions(-) diff --git a/.github/scripts/run_macrobenchmarks.sh b/.github/scripts/run_macrobenchmarks.sh index abb929aab..339068d25 100644 --- a/.github/scripts/run_macrobenchmarks.sh +++ b/.github/scripts/run_macrobenchmarks.sh @@ -2,7 +2,7 @@ set -e OUTPUT_DIR="benchmarks/build/outputs/connected_android_test_additional_output" -JSON_REPORTS_DIR="$OUTPUT_DIR/json_reports" +JSON_REPORTS_DIR="benchmarks/build/json_reports" run_benchmark() { VERSION_LABEL="$1" # v1 or v2 @@ -15,23 +15,36 @@ run_benchmark() { # Clear app data to keep runs consistent adb shell pm clear com.google.samples.apps.nowinandroid || true + # Ensure clean slate so only one JSON exists after run + rm -rf "$OUTPUT_DIR" + mkdir -p "$OUTPUT_DIR" + # Run only the Startup benchmark + # We might need to replace gradle with adb later to run the benchmark faster + # but we will need to deal with making sure things are running correctly + # and locating the output JSON files. ./gradlew :benchmarks:connectedDemoBenchmarkAndroidTest \ - -Pandroid.testInstrumentationRunnerArguments.class=com.google.samples.apps.nowinandroid.startup.StartupBenchmark \ - -Pandroid.testInstrumentationRunnerArguments.androidx.benchmark.suppressErrors=EMULATOR - - mkdir -p "$JSON_REPORTS_DIR" - - # Find newest JSON result file - LATEST_JSON=$(find "$OUTPUT_DIR" -name "*.json" -type f | xargs ls -t | head -n 1) - - if [ -z "$LATEST_JSON" ]; then - echo "Error: No benchmark JSON file found" + --no-daemon \ + --no-build-cache \ + --rerun-tasks \ + -x assemble \ + -Pandroid.testInstrumentationRunnerArguments.class=com.google.samples.apps.nowinandroid.startup.StartupBenchmark \ + -Pandroid.testInstrumentationRunnerArguments.androidx.benchmark.suppressErrors=EMULATOR + + JSON_REPORT=$(find "$OUTPUT_DIR" -type f -name "*.json") + COUNT=$(echo "$JSON_REPORT" | wc -l | tr -d ' ') + + if [ "$COUNT" -ne 1 ]; then + echo "Error: Expected exactly 1 JSON file, found $COUNT" + find "$OUTPUT_DIR" -type f -name "*.json" exit 1 fi + # Create JSON reports directory if it doesn't exist + mkdir -p "$JSON_REPORTS_DIR" + NEW_JSON_NAME="$JSON_REPORTS_DIR/benchmark_${VERSION_LABEL}_run${RUN_NUMBER}.json" - cp "$LATEST_JSON" "$NEW_JSON_NAME" + cp "$JSON_REPORT" "$NEW_JSON_NAME" echo "Saved result to $NEW_JSON_NAME" } diff --git a/.github/scripts/step_fit.py b/.github/scripts/step_fit.py index 28ac5f948..9565d9362 100644 --- a/.github/scripts/step_fit.py +++ b/.github/scripts/step_fit.py @@ -4,7 +4,7 @@ import glob import os # ----------- CONFIG ----------- -JSON_REPORTS_DIR = "benchmarks/build/outputs/connected_android_test_additional_output/json_reports" +JSON_REPORTS_DIR = "benchmarks/build/json_reports" BENCHMARK_NAME = "startupPrecompiledWithBaselineProfile" METRIC_KEY = "timeToInitialDisplayMs" # ------------------------------ diff --git a/.github/workflows/Build.yaml b/.github/workflows/Build.yaml index 4e26ac85b..c0ed9ba4c 100644 --- a/.github/workflows/Build.yaml +++ b/.github/workflows/Build.yaml @@ -58,4 +58,4 @@ jobs: uses: actions/upload-artifact@v4 with: name: benchmark-results - path: benchmarks/build/outputs/connected_android_test_additional_output/json_reports/ \ No newline at end of file + path: benchmarks/build/json_reports/ \ No newline at end of file