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