Is it possible to trigger an Android heap dump from the command line?

In Android pre 3.0 you can use so called

kill -10 <pid> (more)

In Android 3.0 a new command-line tool has been added:

adb shell am dumpheap <pid> <output-file-name>; (more)

Detailed description

To get HPROF you need also change the format of it using hprof-conv


The easy way:

adb shell am dumpheap your.package.name /sdcard/dumpheap.hprof

The hard way (don't remember why I've added it originally):

adb shell am dumpheap $(ps | grep your.package.name | awk '{print $2}') /sdcard/dumpheap.hprof

If your device doesn't have awk try to use busybox awk.

After that pull the created file, convert it with hprof-conv and open it in Android Studio.