androidheap-dump

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


I would like to be able to trigger an Android heap dump from the command line. Is there a command for that?

Specifically, from the command line, not via Montior or DDMS GUIs

Maybe something like using ddms or adb, e.g. ddms -head-dump or adb shell heapdump? AFAICT monitor and ddms always start in GUI mode, and adb doesn't have a heap dump command.

Update: I tried this, it looked promising, but it doesn't work:

  1. adb jdwp
  2. adb forward tcp:8000 jdwp:1234 (substitute output of 1 for 1234)
  3. jmap -dump:format=b,file=heapdump.hprof localhost:8000

But even the heap summary fails:

jmap -heap localhost:8000
Attaching to remote server localhost:8000, please wait...
Error attaching to remote server: java.rmi.ConnectIOException: error during JRMP connection establishment; nested exception is: 
        java.net.SocketTimeoutException: Read timed out

Solution

  • 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