Created
December 20, 2017 04:09
-
-
Save LanderlYoung/9cd0f49e49e42746622cc8e7b4bbcc8a to your computer and use it in GitHub Desktop.
script to dump android java heap and convert use hprof-conv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ADB=${ANDROID_HOME}/platform-tools/adb | |
HPROF_CONV=${ANDROID_HOME}/platform-tools/hprof-conv | |
# customized functions | |
# dump droid heap | |
function droid_hd() { | |
PACKAGE_NAME=$1 | |
TIME=$(date +"%Y%m%d_%H%M%S") | |
FILE_NAME="${PACKAGE_NAME}-${TIME}-heap.hprof" | |
PATH_IN_PHONE="/data/local/tmp/${FILE_NAME}" | |
${ADB} shell rm ${PATH_IN_PHONE} 2> /dev/null | |
echo "cause GC for ${PACKAGE_NAME}" | |
${ADB} shell pkill -l 10 ${PACKAGE_NAME} | |
echo "> dump heap for ${PACKAGE_NAME}" | |
${ADB} shell "am dumpheap ${PACKAGE_NAME} ${PATH_IN_PHONE}" | |
if [[ $? != 0 ]]; then | |
echo | |
${ADB} devices | |
echo "run command:" | |
echo "\e[38;5;82mexport ANDROID_SERIAL=" | |
return | |
fi | |
# I don't want to... But it smees adb shell can't block untils it's done! | |
sleep 3 | |
echo "> list heap for ${PATH_IN_PHONE}" | |
${ADB} shell ls -lh ${PATH_IN_PHONE} | |
echo "> pull to computer" | |
${ADB} pull ${PATH_IN_PHONE} ./ | |
echo "> delete device copy" | |
${ADB} shell rm ${PATH_IN_PHONE} | |
echo "> hprof-conv it" | |
${HPROF_CONV} -z ${FILE_NAME} droid-${FILE_NAME} | |
echo "> remove tmp hprof" | |
mv -f droid-${FILE_NAME} ${FILE_NAME} | |
ls -lh ${FILE_NAME} | |
echo "done! file: \e[38;5;82m ${FILE_NAME}" | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
这里调用方式能方便提示一下吗?