You can capture heap dump of a running process with the adb command.
$ adb shell am dumpheap [--user <USER_ID> current] [-n] [-g] <PROCESS> <FILE>
Dump the heap of a process. The given <PROCESS> argument may
be either a process name or pid. Options are:
-n: dump native heap instead of managed heap
-g: force GC before dumping the heap
--user <USER_ID>
1. Capture Heap Dump with ADB
Check PID of App to extract memory dump
$ adb shell ps -ef | grep com.android.chrome
u0_a124 4779 266 5 22:29:20 ? 00:00:01 com.android.chrome
Capture Heap dump for the pid 4779(Chrome) with adb command.
the heap dump file will be saved on /data/local
.
$ adb shell am dumpheap 4779
File: /data/local/tmp/heapdump-20210623-223001.prof
Waiting for dump to finish...
Copy files to local PC
$ adb pull /data/local/tmp/heapdump-20210623-223001.prof
Now, you can analyze the extracted prof file using Android Studio, etc.
2. Open the prof file
in Eclipse MAT
You can open and analyze the prof file with Eclipse MAT.
But, you need to covert the prof to the MAT format file.
There is a tool called hprof-conv
in the SDK that can convert prof files to MAT-readable files with the following command:
$ hprof-conv heapdump-20210623-223001.prof heapdump-20210623-223001.prof.conv
Then, just open the converted file in MAT.
3. where can I find the hprof-conv
tool
hprof-conv
is also in the sdk platform-tools folder installed when you installed ADB from Android Studio.
../Sdk/platform-tools/$ ls -al
drwxrwxr-x 5 js js 4096 12월 18 2020 .
drwxrwxr-x 15 js js 4096 4월 16 20:22 ..
-rwxrwxr-x 1 js js 7262264 12월 18 2020 adb
-rwxrwxr-x 1 js js 13696 12월 18 2020 hprof-conv
...
Related Posts
- How to download and build Android 13, AOSP
- Notification permission request, pop up notification in Android 13
- Resolve `Access blocked: ComponentInfo` error on Android 13
- Fix error "android gradle plugin requires java 11 to run. you are currently using java 1.8."
- Android - Vibration, Vibrator, VibrationEffect example
- How to get phone number in Android
- How to create Bugreports and Logcat with ADB in Android
- Clear application user data with ADB in Android
- How to disable/enable apps with ADB in Android
- How to find PID of a package with adb in Android
- How to grant/revoke permissions with adb in Android
- How to install an apk(app) with adb in Android
- How to kill a process/package from ADB in Android
- How to transfer files using adb push/pull command in Android
- How to capture the screen from adb in Android
- How to uninstall/install system apps from adb in Android
- How to change Settings values from adb in Android
- How to Factory reset with ADB in Android
- How to get logcat from ADB command in Android
- How to capture Heap Dump from app with ADB in Android
- How to force stop an app with adb in Android
- How to start/stop a service from adb in Android
- How to send/broadcast an intent from adb command in Android
- How to start an activity from adb in Android
- How to generate input from adb in Android
- How to check SQLite DB table in Android Studio
- How to get memory info and thread list from adb in Android
- Android - Uri, Scheme and SSP(Scheme Specific Part)
- How to parse a xml file with XmlResourceParser in Android
- Android - Signing an apk with Platfom key
- How to fix "Cleartext HTTP ... not permitted" for Android development
- How to fix "kvm permission denied" for Android Emulator
- Using ADB over Wifi for Android development