LoginSignup
3
2

More than 5 years have passed since last update.

AndroidのMemory Analyzer用のhprofファイルをサクッと取る

Last updated at Posted at 2017-10-28

メモリリークの調査のときはMemory Analyzer(MAT)がやっぱり強力なので使いたい。でもAndroid StudioのProfilerからダンプしてhprof-convを叩くのは面倒。だからスクリプトにした。

#!/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}"
3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2