build_and_run_benchmark.sh 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. NUMBER_RUNS=10
  10. if [ ! -z $1 ]; then
  11. NUMBER_RUNS=$1
  12. fi
  13. if [[ -z "$ANDROID_BUILD_TOP" ]]; then
  14. echo ANDROID_BUILD_TOP not set, bailing out
  15. echo you must run lunch before running this script
  16. exit 1
  17. fi
  18. set -e
  19. cd $ANDROID_BUILD_TOP
  20. LOGDIR=$(mktemp -d)/nnapi-logs
  21. mkdir -p $LOGDIR
  22. echo Creating logs in $LOGDIR
  23. adb -d root
  24. # Skip setup wizard and remount (read-write)
  25. if ! adb -d shell test -f /data/local.prop; then
  26. adb -d shell 'echo ro.setupwizard.mode=DISABLED > /data/local.prop'
  27. adb -d shell 'chmod 644 /data/local.prop'
  28. adb -d shell 'settings put global device_provisioned 1*'
  29. adb -d shell 'settings put secure user_setup_complete 1'
  30. adb -d disable-verity
  31. adb -d reboot
  32. sleep 5
  33. adb wait-for-usb-device remount
  34. fi
  35. # Build and install NNAPI runtime shared library
  36. make libneuralnetworks
  37. adb -d shell stop
  38. adb -d remount
  39. adb -d push $OUT/system/lib/libneuralnetworks.so /system/lib/libneuralnetworks.so
  40. adb -d push $OUT/system/lib64/libneuralnetworks.so /system/lib64/libneuralnetworks.so
  41. adb -d shell start
  42. # Build and install benchmark app
  43. make NeuralNetworksApiBenchmark
  44. adb -d install $OUT/data/app/NeuralNetworksApiBenchmark/NeuralNetworksApiBenchmark.apk
  45. # Enable menu key press through adb
  46. adb -d shell 'echo testing > /data/local/enable_menu_key'
  47. # Leave screen on (affects scheduling)
  48. adb -d shell settings put system screen_off_timeout 86400000
  49. # Stop background apps, seem to take ~10% CPU otherwise
  50. set +e
  51. adb -d shell 'pm disable com.google.android.googlequicksearchbox'
  52. 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;
  53. set -e
  54. adb -d shell setprop debug.nn.cpuonly 0
  55. adb -d shell setprop debug.nn.vlog 0
  56. echo running $NUMBER_RUNS times
  57. # Run on CPU only
  58. LOGFILE=$LOGDIR/perf-cpu.txt
  59. echo "TFLite" | tee $LOGFILE
  60. for i in $(seq 1 $NUMBER_RUNS); do
  61. echo "Run $i / $NUMBER_RUNS" | tee -a $LOGFILE
  62. # Menukey - make sure screen is on
  63. adb shell "input keyevent 82"
  64. # Show homescreen
  65. adb shell wm dismiss-keyguard
  66. # Set the shell pid as a top-app and run tests
  67. 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
  68. sleep 10 # let CPU cool down
  69. done
  70. echo "CPU run data from 'parse_benchmark.py $LOGFILE'"
  71. $ANDROID_BUILD_TOP/frameworks/ml/nn/tools/parse_benchmark.py $LOGFILE
  72. # Run with driver
  73. LOGFILE=$LOGDIR/perf-driver.txt
  74. echo "Driver" | tee $LOGFILE
  75. for i in $(seq 1 $NUMBER_RUNS); do
  76. echo "Run $i / $NUMBER_RUNS" | tee -a $LOGFILE
  77. # Menukey - make sure screen is on
  78. adb shell "input keyevent 82"
  79. # Show homescreen
  80. adb shell wm dismiss-keyguard
  81. # Set the shell pid as a top-app and run tests
  82. 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
  83. done
  84. echo "Driver run data from 'parse_benchmark.py $LOGFILE'"
  85. $ANDROID_BUILD_TOP/frameworks/ml/nn/tools/parse_benchmark.py $LOGFILE