title: Is it possible to trigger an Android heap dump from the command line?
body: <p>I would like to be able to trigger an Android heap dump from the command line. Is there a command for that?</p>
  
  <p><strong>Specifically, from the command line, not via Montior or DDMS GUIs</strong></p>
  
  <p>Maybe something like using ddms or adb, e.g. <code>ddms -head-dump</code> or <code>adb shell heapdump</code>? AFAICT monitor and ddms always start in GUI mode, and adb doesn't have a heap dump command.</p>
  
  <p>Update: I tried this, it looked promising, but it doesn't work:</p>
  
  <ol>
  <li><code>adb jdwp</code></li>
  <li><code>adb forward tcp:8000 jdwp:1234</code> (substitute output of 1 for 1234)</li>
  <li><code>jmap -dump:format=b,file=heapdump.hprof localhost:8000</code></li>
  </ol>
  
  <p>But even the heap summary fails: </p>
  
  <pre><code>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
  </code></pre>