2013-04-29 12:09:31 +00:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
|
|
|
# android_perf: utility for running perf on an android device
|
2014-06-03 22:38:18 +00:00
|
|
|
#
|
2013-04-29 12:09:31 +00:00
|
|
|
# The basic usage sequence is to run...
|
|
|
|
# 1) perf record [gm/tests/bench] # runs profiler on specified app
|
|
|
|
# 2) perf report # prints profiler results
|
|
|
|
# 3) perf clean # cleans the temporary directory used to store results
|
|
|
|
#
|
|
|
|
|
|
|
|
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
2013-08-12 12:30:04 +00:00
|
|
|
source $SCRIPT_DIR/android_setup.sh
|
2013-04-29 12:09:31 +00:00
|
|
|
source $SCRIPT_DIR/utils/setup_adb.sh
|
|
|
|
|
|
|
|
if [ $(uname) == "Linux" ]; then
|
|
|
|
PERFHOST=$SCRIPT_DIR/linux/perfhost
|
|
|
|
elif [ $(uname) == "Darwin" ]; then
|
|
|
|
PERFHOST=$SCRIPT_DIR/mac/perfhost
|
|
|
|
else
|
|
|
|
echo "Could not automatically determine OS!"
|
|
|
|
exit 1;
|
|
|
|
fi
|
|
|
|
|
2013-08-12 12:30:04 +00:00
|
|
|
# grab and remove the perf command from the input args
|
|
|
|
PERF_CMD=${APP_ARGS[0]}
|
|
|
|
unset APP_ARGS[0]
|
2014-05-05 18:40:15 +00:00
|
|
|
runVars=("${APP_ARGS[@]}") # shift array indices
|
2013-08-12 12:30:04 +00:00
|
|
|
|
2013-04-29 12:09:31 +00:00
|
|
|
# We need the debug symbols from these files
|
|
|
|
PERF_TMP_DIR=$(pwd)/android_perf_tmp
|
|
|
|
|
|
|
|
TMP_SYS_BIN=$PERF_TMP_DIR/system/bin
|
|
|
|
TMP_SYS_LIB=$PERF_TMP_DIR/system/lib
|
2013-08-12 12:30:04 +00:00
|
|
|
TMP_APP_LOC=$PERF_TMP_DIR/data/local/tmp
|
2013-04-29 12:09:31 +00:00
|
|
|
|
|
|
|
perf_setup() {
|
|
|
|
|
|
|
|
mkdir -p $TMP_SYS_BIN
|
|
|
|
mkdir -p $TMP_SYS_LIB
|
2013-08-12 12:30:04 +00:00
|
|
|
mkdir -p $TMP_APP_LOC
|
2013-04-29 12:09:31 +00:00
|
|
|
|
|
|
|
echo "Copying symbol files"
|
2013-08-12 12:30:04 +00:00
|
|
|
adb_pull_if_needed /system/lib/libc.so $TMP_SYS_LIB
|
2015-06-18 13:29:48 +00:00
|
|
|
adb_pull_if_needed /system/lib/libstdc++.so $TMP_SYS_LIB
|
2013-08-12 12:30:04 +00:00
|
|
|
adb_pull_if_needed /system/lib/libstlport.so $TMP_SYS_LIB
|
|
|
|
adb_pull_if_needed /system/lib/libGLESv2.so $TMP_SYS_LIB
|
|
|
|
adb_pull_if_needed /system/lib/libandroid.so $TMP_SYS_LIB
|
|
|
|
adb_pull_if_needed /system/lib/libm.so $TMP_SYS_LIB
|
|
|
|
adb_pull_if_needed /system/lib/libz.so $TMP_SYS_LIB
|
|
|
|
|
2014-05-05 18:40:15 +00:00
|
|
|
# BUILDTYPE variable is set by android_setup.sh
|
|
|
|
BUILDDIR="${SKIA_OUT}/${BUILDTYPE}"
|
|
|
|
if [ ! -f "${BUILDDIR}/lib/lib${runVars[0]}.so" ];
|
2013-04-29 12:09:31 +00:00
|
|
|
then
|
2014-05-05 18:40:15 +00:00
|
|
|
echo "Unable to find the ${runVars[0]} library in ${BUILDDIR}/lib."
|
2013-08-12 12:30:04 +00:00
|
|
|
exit 1
|
2013-04-29 12:09:31 +00:00
|
|
|
fi
|
|
|
|
|
2013-08-12 12:30:04 +00:00
|
|
|
echo "Pushing app..."
|
2014-05-05 18:40:15 +00:00
|
|
|
for lib_file in \
|
|
|
|
"${BUILDDIR}/skia_launcher" \
|
|
|
|
"${BUILDDIR}/lib/libskia_android.so" \
|
|
|
|
"${BUILDDIR}/lib/lib${runVars[0]}.so" \
|
|
|
|
; do
|
|
|
|
adb_push_if_needed "$lib_file" /data/local/tmp
|
|
|
|
cp "$lib_file" $TMP_APP_LOC
|
|
|
|
done
|
2013-04-29 12:09:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
perf_record() {
|
|
|
|
|
|
|
|
echo "Killing any running Skia processes."
|
|
|
|
$ADB shell ps | grep skia_launcher | awk '{print $2}' | xargs $ADB shell kill
|
|
|
|
|
|
|
|
echo "Starting application"
|
2013-08-12 12:30:04 +00:00
|
|
|
$ADB shell /data/local/tmp/skia_launcher ${runVars[@]} &
|
2013-04-29 12:09:31 +00:00
|
|
|
|
|
|
|
# WE REALLY REALLY WANT TO BE ABLE TO PASS THE SKIA_LAUNCHER APP DIRECTLY TO
|
|
|
|
# PERF, BUT AT THIS POINT THE DATA FILE WE GET WHEN GOING THAT ROUTE IS UNABLE
|
|
|
|
# TO BE READ BY THE REPORTING TOOL
|
|
|
|
echo "Starting profiler"
|
|
|
|
APP_PID=$($ADB shell ps | grep skia_launcher | awk '{print $2}')
|
|
|
|
$ADB shell perf record -p ${APP_PID} sleep 70
|
|
|
|
|
|
|
|
$ADB pull /data/perf.data $PERF_TMP_DIR/perf.data
|
|
|
|
|
|
|
|
exit 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
perf_report() {
|
2013-08-12 12:30:04 +00:00
|
|
|
adb_pull_if_needed /data/perf.data $PERF_TMP_DIR/perf.data
|
|
|
|
$PERFHOST report -i $PERF_TMP_DIR/perf.data --symfs=$PERF_TMP_DIR ${runVars[@]}
|
2013-04-29 12:09:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Clean up
|
|
|
|
perf_clean() {
|
|
|
|
rm -rf $PERF_TMP_DIR
|
|
|
|
}
|
|
|
|
|
|
|
|
case $PERF_CMD in
|
|
|
|
setup)
|
2013-08-12 12:30:04 +00:00
|
|
|
perf_setup ${runVars[@]}
|
2013-04-29 12:09:31 +00:00
|
|
|
;;
|
|
|
|
record)
|
2013-08-12 12:30:04 +00:00
|
|
|
perf_setup ${runVars[@]}
|
|
|
|
perf_record ${runVars[@]}
|
2013-04-29 12:09:31 +00:00
|
|
|
;;
|
|
|
|
report)
|
|
|
|
perf_report
|
|
|
|
;;
|
|
|
|
clean)
|
|
|
|
perf_clean
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo -n "ERROR: unknown perf command ($PERF_CMD), valid values: "
|
|
|
|
echo "setup, record, report, clean"
|
|
|
|
exit 1;
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
exit 0;
|