使用Android Studio自带的Profile工具
必看的两篇官方文档:
选看的一篇官方文档:
Use MAT for profiling Android memory
First, you have install MAT ( download )
In Android Studio open Android Device Monitor or DDMS.
Select your process “com.example.etc..”
Click Update Heap above the process list.
In the right-side panel, select the Heap tab.
Click in Cause GC.
Click Dump HPROF file above the process list.
When we downloaded the file HPROF, we have to open the Terminal and run this command to generate the file to open it with MAT.
Open terminal and run this command “./hprof-conv path/file.hprof exitPath/1. heap-converted.hprof”. The command “hprof-conv” is in the platform-tools 1. folder of the sdk.
And ready and MAT can open and open the converted file ( heap-converted.hprof ) .
如何在Android Studio 3.0里面打开DDMS?
自从Android Studio进入3.0,DDMS就被偷偷的隐藏起来了。参考下面的文章看如何打开DDMS。
在Android Studio中保存hprof文档
在Android Studio将DDMS偷偷隐藏起来的同时,DDMS的一些工具已经集成到Android Studio里面了。比如这个获取hprof文件的方法。
该方法不需要打开DDMS,直接用Android Studio的Profile工具即可。
Mat启动报错
下载的Mat在打开的时候会报错。错误信息如下:
java.lang.IllegalStateException: The platform metadata area could not be written: /private/var/folders/7b/3wj5jwnd1yg98w2yzmn36qwr0000gq/T/AppTranslocation/C98006F4-54ED-44FB-9F3E-AC7C1EB9519B/d/mat.app/Contents/MacOS/workspace/.metadata. By default the platform writes its content under the current working directory when the platform is launched. Use the -data parameter to specify a different content area for the platform.
注意:右键打开Mat package,可以找到上面说的MemoryAnalyzer.ini文件