1#!/bin/bash 2# 3# Build benchmark app and run it, mimicking a user-initiated run 4# 5# Output is logged to a temporary folder and summarized in txt and JSON formats. 6# 7# Parameters 8# - number of runs 9 10NUMBER_RUNS=10 11 12if [ ! -z $1 ]; then 13 NUMBER_RUNS=$1 14fi 15 16if [[ -z "$ANDROID_BUILD_TOP" ]]; then 17 echo ANDROID_BUILD_TOP not set, bailing out 18 echo you must run lunch before running this script 19 exit 1 20fi 21 22set -e 23cd $ANDROID_BUILD_TOP 24 25LOGDIR=$(mktemp -d)/nnapi-logs 26mkdir -p $LOGDIR 27echo Creating logs in $LOGDIR 28 29adb -d root 30 31# Skip setup wizard and remount (read-write) 32if ! adb -d shell test -f /data/local.prop; then 33 adb -d shell 'echo ro.setupwizard.mode=DISABLED > /data/local.prop' 34 adb -d shell 'chmod 644 /data/local.prop' 35 adb -d shell 'settings put global device_provisioned 1*' 36 adb -d shell 'settings put secure user_setup_complete 1' 37 adb -d disable-verity 38 adb -d reboot 39 sleep 5 40 adb wait-for-usb-device remount 41fi 42 43# Build and install NNAPI runtime shared library 44make libneuralnetworks 45adb -d shell stop 46adb -d remount 47adb -d push $OUT/system/lib/libneuralnetworks.so /system/lib/libneuralnetworks.so 48adb -d push $OUT/system/lib64/libneuralnetworks.so /system/lib64/libneuralnetworks.so 49adb -d shell start 50 51# Build and install benchmark app 52make NeuralNetworksApiBenchmark 53adb -d install $OUT/data/app/NeuralNetworksApiBenchmark/NeuralNetworksApiBenchmark.apk 54 55# Enable menu key press through adb 56adb -d shell 'echo testing > /data/local/enable_menu_key' 57# Leave screen on (affects scheduling) 58adb -d shell settings put system screen_off_timeout 86400000 59# Stop background apps, seem to take ~10% CPU otherwise 60set +e 61adb -d shell 'pm disable com.google.android.googlequicksearchbox' 62adb shell 'pm list packages -f' | sed -e 's/.*=//' | sed 's/\r//g' | grep "com.breel.wallpapers" | while read pkg; do adb -d shell "pm disable $pkg"; done; 63set -e 64adb -d shell setprop debug.nn.cpuonly 0 65adb -d shell setprop debug.nn.vlog 0 66 67echo running $NUMBER_RUNS times 68 69# Run on CPU only 70LOGFILE=$LOGDIR/perf-cpu.txt 71echo "TFLite" | tee $LOGFILE 72for i in $(seq 1 $NUMBER_RUNS); do 73 echo "Run $i / $NUMBER_RUNS" | tee -a $LOGFILE 74 # Menukey - make sure screen is on 75 adb shell "input keyevent 82" 76 # Show homescreen 77 adb shell wm dismiss-keyguard 78 # Set the shell pid as a top-app and run tests 79 adb shell 'echo $$ > /dev/stune/top-app/tasks; am instrument -w -e size large -e class com.android.nn.benchmark.app.TFLiteTest com.android.nn.benchmark.app/androidx.test.runner.AndroidJUnitRunner' | tee -a $LOGFILE 80 sleep 10 # let CPU cool down 81done 82 83echo "CPU run data from 'parse_benchmark.py $LOGFILE'" 84$ANDROID_BUILD_TOP/packages/modules/NeuralNetworks/tools/parse_benchmark.py $LOGFILE 85 86# Run with driver 87LOGFILE=$LOGDIR/perf-driver.txt 88echo "Driver" | tee $LOGFILE 89for i in $(seq 1 $NUMBER_RUNS); do 90 echo "Run $i / $NUMBER_RUNS" | tee -a $LOGFILE 91 # Menukey - make sure screen is on 92 adb shell "input keyevent 82" 93 # Show homescreen 94 adb shell wm dismiss-keyguard 95 # Set the shell pid as a top-app and run tests 96 adb shell 'echo $$ > /dev/stune/top-app/tasks; am instrument -w -e size large -e class com.android.nn.benchmark.app.NNTest com.android.nn.benchmark.app/androidx.test.runner.AndroidJUnitRunner' | tee -a $LOGFILE 97done 98 99echo "Driver run data from 'parse_benchmark.py $LOGFILE'" 100$ANDROID_BUILD_TOP/packages/modules/NeuralNetworks/tools/parse_benchmark.py $LOGFILE 101