1 #!/bin/bash 2 # 3 # android_perf: utility for running perf on an android device 4 # 5 # The basic usage sequence is to run... 6 # 1) perf record [gm/tests/bench] # runs profiler on specified app 7 # 2) perf report # prints profiler results 8 # 3) perf clean # cleans the temporary directory used to store results 9 # 10 11 SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 12 source $SCRIPT_DIR/android_setup.sh 13 source $SCRIPT_DIR/utils/setup_adb.sh 14 15 if [ $(uname) == "Linux" ]; then 16 PERFHOST=$SCRIPT_DIR/linux/perfhost 17 elif [ $(uname) == "Darwin" ]; then 18 PERFHOST=$SCRIPT_DIR/mac/perfhost 19 else 20 echo "Could not automatically determine OS!" 21 exit 1; 22 fi 23 24 # grab and remove the perf command from the input args 25 PERF_CMD=${APP_ARGS[0]} 26 unset APP_ARGS[0] 27 runVars=("${APP_ARGS[@]}") # shift array indices 28 29 # We need the debug symbols from these files 30 PERF_TMP_DIR=$(pwd)/android_perf_tmp 31 32 TMP_SYS_BIN=$PERF_TMP_DIR/system/bin 33 TMP_SYS_LIB=$PERF_TMP_DIR/system/lib 34 TMP_APP_LOC=$PERF_TMP_DIR/data/local/tmp 35 36 perf_setup() { 37 38 mkdir -p $TMP_SYS_BIN 39 mkdir -p $TMP_SYS_LIB 40 mkdir -p $TMP_APP_LOC 41 42 echo "Copying symbol files" 43 adb_pull_if_needed /system/lib/libc.so $TMP_SYS_LIB 44 adb_pull_if_needed /system/lib/libstdc++.so $TMP_SYS_LIB 45 adb_pull_if_needed /system/lib/libstlport.so $TMP_SYS_LIB 46 adb_pull_if_needed /system/lib/libGLESv2.so $TMP_SYS_LIB 47 adb_pull_if_needed /system/lib/libandroid.so $TMP_SYS_LIB 48 adb_pull_if_needed /system/lib/libm.so $TMP_SYS_LIB 49 adb_pull_if_needed /system/lib/libz.so $TMP_SYS_LIB 50 51 # BUILDTYPE variable is set by android_setup.sh 52 BUILDDIR="${SKIA_OUT}/${BUILDTYPE}" 53 if [ ! -f "${BUILDDIR}/lib/lib${runVars[0]}.so" ]; 54 then 55 echo "Unable to find the ${runVars[0]} library in ${BUILDDIR}/lib." 56 exit 1 57 fi 58 59 echo "Pushing app..." 60 for lib_file in \ 61 "${BUILDDIR}/skia_launcher" \ 62 "${BUILDDIR}/lib/libskia_android.so" \ 63 "${BUILDDIR}/lib/lib${runVars[0]}.so" \ 64 ; do 65 adb_push_if_needed "$lib_file" /data/local/tmp 66 cp "$lib_file" $TMP_APP_LOC 67 done 68 } 69 70 perf_record() { 71 72 echo "Killing any running Skia processes." 73 $ADB shell ps | grep skia_launcher | awk '{print $2}' | xargs $ADB shell kill 74 75 echo "Starting application" 76 $ADB shell /data/local/tmp/skia_launcher ${runVars[@]} & 77 78 # WE REALLY REALLY WANT TO BE ABLE TO PASS THE SKIA_LAUNCHER APP DIRECTLY TO 79 # PERF, BUT AT THIS POINT THE DATA FILE WE GET WHEN GOING THAT ROUTE IS UNABLE 80 # TO BE READ BY THE REPORTING TOOL 81 echo "Starting profiler" 82 APP_PID=$($ADB shell ps | grep skia_launcher | awk '{print $2}') 83 $ADB shell perf record -p ${APP_PID} sleep 70 84 85 $ADB pull /data/perf.data $PERF_TMP_DIR/perf.data 86 87 exit 0; 88 } 89 90 perf_report() { 91 adb_pull_if_needed /data/perf.data $PERF_TMP_DIR/perf.data 92 $PERFHOST report -i $PERF_TMP_DIR/perf.data --symfs=$PERF_TMP_DIR ${runVars[@]} 93 } 94 95 # Clean up 96 perf_clean() { 97 rm -rf $PERF_TMP_DIR 98 } 99 100 case $PERF_CMD in 101 setup) 102 perf_setup ${runVars[@]} 103 ;; 104 record) 105 perf_setup ${runVars[@]} 106 perf_record ${runVars[@]} 107 ;; 108 report) 109 perf_report 110 ;; 111 clean) 112 perf_clean 113 ;; 114 *) 115 echo -n "ERROR: unknown perf command ($PERF_CMD), valid values: " 116 echo "setup, record, report, clean" 117 exit 1; 118 ;; 119 esac 120 121 exit 0; 122