run_benchmarks.sh 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. #!/bin/sh
  2. # A utility script that runs benchmark on Android device
  3. #
  4. # Note: Only one Android device can be connected when running this script
  5. #
  6. # Example usage:
  7. # $ cd system/bt
  8. # $ ./test/run_benchmarks.sh bluetooth_benchmark_example
  9. known_benchmarks=(
  10. bluetooth_benchmark_thread_performance
  11. bluetooth_benchmark_timer_performance
  12. )
  13. usage() {
  14. binary="$(basename "$0")"
  15. echo "Usage: ${binary} --help"
  16. echo " ${binary} [-i <iterations>] [-s <specific device>] [--all] [<benchmark name>[.<filter>] ...] [--<arg> ...]"
  17. echo
  18. echo "Unknown long arguments are passed to the benchmark."
  19. echo
  20. echo "Known benchmark names:"
  21. for name in "${known_benchmarks[@]}"
  22. do
  23. echo " ${name}"
  24. done
  25. }
  26. iterations=1
  27. device=
  28. benchmarks=()
  29. benchmark_args=()
  30. while [ $# -gt 0 ]
  31. do
  32. case "$1" in
  33. -h|--help)
  34. usage
  35. exit 0
  36. ;;
  37. -i)
  38. shift
  39. if [ $# -eq 0 ]; then
  40. echo "error: number of iterations expected" 1>&2
  41. usage
  42. exit 2
  43. fi
  44. iterations=$(( $1 ))
  45. shift
  46. ;;
  47. -s)
  48. shift
  49. if [ $# -eq 0 ]; then
  50. echo "error: no device specified" 1>&2
  51. usage
  52. exit 2
  53. fi
  54. device="$1"
  55. shift
  56. ;;
  57. --all)
  58. benchmarks+=( "${known_benchmarks[@]}" )
  59. shift
  60. ;;
  61. --*)
  62. benchmark_args+=( "$1" )
  63. shift
  64. ;;
  65. *)
  66. benchmarks+=( "$1" )
  67. shift
  68. ;;
  69. esac
  70. done
  71. if [ "${#benchmarks[@]}" -eq 0 ]; then
  72. benchmarks+=( "${known_benchmarks[@]}" )
  73. fi
  74. adb=( "adb" )
  75. if [ -n "${device}" ]; then
  76. adb+=( "-s" "${device}" )
  77. fi
  78. source ${ANDROID_BUILD_TOP}/build/envsetup.sh
  79. target_arch=$(gettargetarch)
  80. failed_benchmarks=()
  81. for spec in "${benchmarks[@]}"
  82. do
  83. name="${spec%%.*}"
  84. if [[ $target_arch == *"64"* ]]; then
  85. binary="/data/benchmarktest64/${name}/${name}"
  86. else
  87. binary="/data/benchmarktest/${name}/${name}"
  88. fi
  89. push_command=( "${adb[@]}" push {"${ANDROID_PRODUCT_OUT}",}"${binary}" )
  90. benchmark_command=( "${adb[@]}" shell "${binary}" )
  91. if [ "${name}" != "${spec}" ]; then
  92. filter="${spec#*.}"
  93. benchmark_command+=( "--benchmark_filter=${filter}" )
  94. fi
  95. benchmark_command+=( "${benchmark_args[@]}" )
  96. echo "--- ${name} ---"
  97. echo "pushing..."
  98. "${push_command[@]}"
  99. echo "running..."
  100. failed_count=0
  101. for i in $(seq 1 ${iterations})
  102. do
  103. "${benchmark_command[@]}" || failed_count=$(( $failed_count + 1 ))
  104. done
  105. if [ $failed_count != 0 ]; then
  106. failed_benchmarks+=( "${name} ${failed_count}/${iterations}" )
  107. fi
  108. done
  109. if [ "${#failed_benchmarks[@]}" -ne 0 ]; then
  110. for failed_benchmark in "${failed_benchmarks[@]}"
  111. do
  112. echo "!!! FAILED TEST: ${failed_benchmark} !!!"
  113. done
  114. exit 1
  115. fi
  116. exit 0