Skip to content

Instantly share code, notes, and snippets.

@cattaka
Last active October 28, 2017 04:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cattaka/7465f31bff94653fc06505bd7fe780a4 to your computer and use it in GitHub Desktop.
Save cattaka/7465f31bff94653fc06505bd7fe780a4 to your computer and use it in GitHub Desktop.
Dump Android hprof and convert to hprof for Memory Analyzer
#!/bin/sh
if [ -z "$1" ]; then
echo "USAGE: dumphprof <package_name> [<out_file>]"
exit 1
fi
date=`date '+%Y%m%d%H%M%S'`
temp_file="$1_${date}_orig.hprof"
output_file="$1_${date}.hprof"
if [ -n "$2" ]; then
output_file=$2
fi
echo "dumpheap to /data/local/tmp/${temp_file}"
adb shell am dumpheap $1 /data/local/tmp/${temp_file}
while [ `adb shell run-as $1 lsof -- /data/local/tmp/${temp_file} 2>/dev/null| wc -l` -gt 0 ]; do
sleep 1
done
echo "pull /data/local/tmp/${temp_file}"
adb pull /data/local/tmp/${temp_file}
adb shell rm /data/local/tmp/${temp_file}
echo "hprof-conv to ${output_file}"
hprof-conv ${temp_file} ${output_file}
rm ${temp_file}
echo "hprof file is pulled : ${output_file}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment