Is it possible to initiate an Android heap reset from the command line?
I would like to be able to run an Android heap dump from the command line. Is there a command for this?
Specifically from the command line and not through the Montior GUI or DDMS
Maybe something like using ddms or adb for example. ddms -head-dump
or adb shell heapdump
? AFAICT monitor and ddms always start in GUI mode and there is no heap reset command in adb.
Update: I tried this, it looked promising, but it doesn't work:
-
adb jdwp
-
adb forward tcp:8000 jdwp:1234
(replace pin 1 with 1234) -
jmap -dump:format=b,file=heapdump.hprof localhost:8000
But even pivot pivot 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
source to share
In Android pre 3.0, you can use the so called
kill -10 <pid>
( more )
Android 3.0 adds a new command line tool:
adb shell am dumpheap <pid> <output-file-name>;
( more )
To get HPROF you also need to change its format using hprof-conv
source to share
Simple way:
adb shell am dumpheap your.package.name /sdcard/dumpheap.hprof
Hard way:
adb shell am dumpheap $(ps | grep your.package.name | awk '{print $2}') /sdcard/dumpheap.hprof
If your device doesn't have one awk
, try using busybox awk
.
After that, pull out the generated file, convert it with hprof-conv and open it in Android Studio.
source to share