Home | History | Annotate | Download | only in tools
      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 
     10 NUMBER_RUNS=10
     11 
     12 if [ ! -z $1 ]; then
     13   NUMBER_RUNS=$1
     14 fi
     15 
     16 if [[ -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
     20 fi
     21 
     22 set -e
     23 cd $ANDROID_BUILD_TOP
     24 
     25 LOGDIR=$(mktemp -d)/nnapi-logs
     26 mkdir -p $LOGDIR
     27 echo Creating logs in $LOGDIR
     28 
     29 adb -d root
     30 
     31 # Skip setup wizard and remount (read-write)
     32 if ! 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
     41 fi
     42 
     43 # Build and install NNAPI runtime shared library
     44 make libneuralnetworks
     45 adb -d shell stop
     46 adb -d remount
     47 adb -d push $OUT/system/lib/libneuralnetworks.so /system/lib/libneuralnetworks.so
     48 adb -d push $OUT/system/lib64/libneuralnetworks.so /system/lib64/libneuralnetworks.so
     49 adb -d shell start
     50 
     51 # Build and install benchmark app
     52 make NeuralNetworksApiBenchmark
     53 adb -d install $OUT/data/app/NeuralNetworksApiBenchmark/NeuralNetworksApiBenchmark.apk
     54 
     55 # Enable menu key press through adb
     56 adb -d shell 'echo testing > /data/local/enable_menu_key'
     57 # Leave screen on (affects scheduling)
     58 adb -d shell settings put system screen_off_timeout 86400000
     59 # Stop background apps, seem to take ~10% CPU otherwise
     60 set +e
     61 adb -d shell 'pm disable com.google.android.googlequicksearchbox'
     62 adb 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;
     63 set -e
     64 adb -d shell setprop debug.nn.cpuonly 0
     65 adb -d shell setprop debug.nn.vlog 0
     66 
     67 echo running $NUMBER_RUNS times
     68 
     69 # Run on CPU only
     70 LOGFILE=$LOGDIR/perf-cpu.txt
     71 echo "TFLite" | tee $LOGFILE
     72 for 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
     81 done
     82 
     83 echo "CPU run data from 'parse_benchmark.py $LOGFILE'"
     84 $ANDROID_BUILD_TOP/frameworks/ml/nn/tools/parse_benchmark.py $LOGFILE
     85 
     86 # Run with driver
     87 LOGFILE=$LOGDIR/perf-driver.txt
     88 echo "Driver" | tee $LOGFILE
     89 for 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
     97 done
     98 
     99 echo "Driver run data from 'parse_benchmark.py $LOGFILE'"
    100 $ANDROID_BUILD_TOP/frameworks/ml/nn/tools/parse_benchmark.py $LOGFILE
    101