Skip to content

Instantly share code, notes, and snippets.

@sphrak
Last active March 31, 2022 11:58
Show Gist options
  • Save sphrak/646acac19490f0c5e78ac4b6d9cb6a44 to your computer and use it in GitHub Desktop.
Save sphrak/646acac19490f0c5e78ac4b6d9cb6a44 to your computer and use it in GitHub Desktop.
measure android app startup time
#!/bin/bash
# Simple bash script runs adb to measure startup time of android apps
trap ctrl_c INT
time=()
function ctrl_c() {
total=0
for i in "${time[@]}"; do
total=$(($total + $i))
done
avg=$(expr $total / ${#time[@]})
echo "Ran ${#time[@]} cold starts with an avg upstart time of ${avg} millis"
exit 0
}
function run_adb() {
adb shell am start -S -W $PKG_NAME/$ACTIVITY_PATH -c android.intent.category.LAUNCHER -a android.intent.action.MAIN
}
MAX_COUNT=64
COUNT=0
PKG_NAME=$1
ACTIVITY_PATH=$2
if [ -z $PKG_NAME ] || [ -z $ACTIVITY_PATH ]; then
echo "usage: ./benchmark.sh tld.example.name package.path.to.activity"
exit 1
fi
while [ $COUNT -le $MAX_COUNT ]; do
value=$(run_adb | cut -d$'\n' -f6 | cut -d' ' -f2)
time+=($value)
let COUNT=COUNT+1
echo "Test $COUNT took: $value ms"
done
ctrl_c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment