| 1 | #!/bin/bash |
| 2 | # Renderer bench on Android (docs/android-renderer-bench.md): runs the demo's |
| 3 | # `bench` autorun for one renderer, captures `dumpsys meminfo` of every process |
| 4 | # of the package while the widgets are held alive (the WebView renderer process |
| 5 | # is an isolated uid the app cannot measure itself), pulls the report. |
| 6 | # |
| 7 | # scripts/android-bench.sh webview 20 # cold process, no prewarm |
| 8 | # scripts/android-bench.sh webview 20 prewarm # a spare WebView loaded at launch first |
| 9 | # scripts/android-bench.sh blitz 20 |
| 10 | # scripts/android-bench.sh none 20 # engine + validator only (NullRenderer in Bench.kt): the renderer cost is the difference |
| 11 | # CORPUS=common scripts/android-bench.sh litehtml 20 # the common-profile corpus: every renderer draws the same picture |
| 12 | # |
| 13 | # Output: reports/android-bench/<renderer>[-prewarm]-<count>.json and .meminfo.txt. |
| 14 | # Needs: a booted emulator/device, the demo installed (cd apps/android && ./gradlew :demo:installDebug). |
| 15 | # Several devices attached: ANDROID_SERIAL=<serial> TAG=phone scripts/android-bench.sh … (adb honours ANDROID_SERIAL). |
| 16 | set -euo pipefail |
| 17 | RENDERER=${1:-webview}; COUNT=${2:-10}; PREWARM=${3:-}; HOLD=${4:-8}; POOLS=${POOLS:-} # POOLS=1: validator pool (WidgetHost.Options.pools) with POOL_PREWARM validators built at launch |
| 18 | CORPUS=${CORPUS:-feed} # CORPUS=common: the renderer-comparison corpus (corpus/common/README.md) instead of compat + generated |
| 19 | PKG=org.telegram.widgetsandbox.demo |
| 20 | ADB=${ADB:-$HOME/Library/Android/sdk/platform-tools/adb} |
| 21 | OUT=reports/android-bench; mkdir -p "$OUT" |
| 22 | NAME="$RENDERER${PREWARM:+-prewarm}${POOLS:+-pools}$([ "$CORPUS" = feed ] || echo "-$CORPUS")-$COUNT${TAG:+-$TAG}" # TAG=phone keeps a device's reports apart from the emulator's |
| 23 | EXTRA="--es renderer $RENDERER --ei count $COUNT --ei hold $HOLD${PREWARM:+ --ez prewarm true}${POOLS:+ --ez pools true --ei prewarmValidators ${POOL_PREWARM:-4}} --es corpus $CORPUS" |
| 24 |
| 25 | $ADB shell am force-stop $PKG; $ADB shell input keyevent KEYCODE_WAKEUP; sleep 2 |
| 26 | $ADB logcat -c |
| 27 | $ADB shell am start -W -n $PKG/.MainActivity --es autorun bench $EXTRA > /dev/null |
| 28 | wait_phase() { for i in $(seq 1 600); do if $ADB logcat -d -s TwidgetBench 2>/dev/null | grep -q "phase=$1"; then return 0; fi; sleep 0.5; done; echo "timeout waiting for phase=$1" >&2; return 1; } |
| 29 | wait_phase live |
| 30 | # Every process whose name starts with the package: the app and (WebView) :sandboxed_process0. |
| 31 | { echo "== ps"; $ADB shell "ps -A | grep -i twidget"; echo "== dumpsys meminfo"; $ADB shell dumpsys meminfo; } > "$OUT/$NAME.meminfo.txt" |
| 32 | # The WebView renderer runs as com.google.android.webview:sandboxed_process0 under an isolated uid; it is part of the widget's cost. |
| 33 | echo "== PSS by process ($NAME)"; grep -E "^ {4,5}[0-9,]+K: ($PKG|com.google.android.webview:sandboxed)" "$OUT/$NAME.meminfo.txt" || true |
| 34 | wait_phase done |
| 35 | $ADB shell run-as $PKG cat files/bench-report.json > "$OUT/$NAME.json" |
| 36 | echo "report: $OUT/$NAME.json" |
| 37 |