1) 安裝
Help->SoftWare Updates and Add-ons->Available software-> Add Site :
http://download.eclipse.org/mat/1.0/update-site/
2) 產生.hprof檔案
adb shell
chmod 777 /data/misc (預設的HProf (Heap Profile) 放在/data/misc,需要改寫入權限為777)
exit
adb shell ps (查看你的進程號)
adb shell kill -10 pid (你準備分析的進程號)
這個時候你可能在logCat中看到一些如下資訊:
adb shell logcat
I/dalvikvm( ): threadid=7: reacting to signal 10 I/dalvikvm( ): SIGUSR1 forcing GC and HPROF dump I/dalvikvm( ): hprof: dumping VM heap to "/data/misc/heap-dump-tm- pid.hprof-hptemp". I/dalvikvm( ): hprof: dumping heap strings to "/data/misc/heap-dump-tm124026 3144-pid.hprof". I/dalvikvm( ): hprof: heap dump completed, temp file removed D/dalvikvm( ): GC freed 1292 objects / 92440 bytes in 11 sec D/dalvikvm( ): GC freed 215 objects / 9400 bytes in 963m
現在你可以將heap dump 資訊拷貝到某個地方,以便我們一會用eclispse的 MAT來分析:
adb pull /data/misc/heap-dump-tm-pid.hprof ××××目錄
3) 使用
使用sdk安裝目錄下面的hprof-conv工具將heap-dump-tm-pid.hprof轉換一下,eclipse->windows->open perspective->other->memory analyzer 匯入你剛剛產生的.hprof檔案
4) 分析
詳解: http://www.eclipse.org/mat/about/screenshots.php
摘自:androidzhaoxiaogang的專欄