diff options
author | Andy McFadden <fadden@android.com> | 2010-07-09 16:26:57 -0700 |
---|---|---|
committer | Andy McFadden <fadden@android.com> | 2010-07-12 13:35:14 -0700 |
commit | 824c510752fd6a30cdba5ed7324cb80a5043ce26 (patch) | |
tree | 701346031a5b93e71c73f4786f1a276e1f6053db /cmds/am | |
parent | 2707d6026240bcca6f0e35e2e1138958882e90ce (diff) | |
download | frameworks_base-824c510752fd6a30cdba5ed7324cb80a5043ce26.zip frameworks_base-824c510752fd6a30cdba5ed7324cb80a5043ce26.tar.gz frameworks_base-824c510752fd6a30cdba5ed7324cb80a5043ce26.tar.bz2 |
Allow "am" to initiate heap dumps.
This was mostly cloned from the "am profile" implementation. It's
intended to replace the old "kill -10" approach used by "runhat".
We could really use a native heap dump, so I pass a "managed"
flag through that indicates whether we want to dump the native or
managed heap. We don't currently have a native heap dump-to-file
function, so it currently just logs a warning.
(android.ddm.DdmHandleNativeHeap.getLeakInfo is a good start -- it
copies /proc/maps and then calls get_malloc_leak_info to get some
goodies. Needs some formatting to make it human-readable. I didn't
want to cram all that into this change.)
It would be useful if "am" didn't exit until the heap dump operation
completed, but I'm not sure how to do that.
Bug 2759474.
Change-Id: I46bc98067738d8c72ac0fc10002ca67bb4929271
Diffstat (limited to 'cmds/am')
-rw-r--r-- | cmds/am/src/com/android/commands/am/Am.java | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/cmds/am/src/com/android/commands/am/Am.java b/cmds/am/src/com/android/commands/am/Am.java index 301883f..fb60fdf 100644 --- a/cmds/am/src/com/android/commands/am/Am.java +++ b/cmds/am/src/com/android/commands/am/Am.java @@ -98,6 +98,8 @@ public class Am { sendBroadcast(); } else if (op.equals("profile")) { runProfile(); + } else if (op.equals("dumpheap")) { + runDumpHeap(); } else { throw new IllegalArgumentException("Unknown command: " + op); } @@ -424,6 +426,28 @@ public class Am { } } + private void runDumpHeap() throws Exception { + boolean managed = !"-n".equals(nextOption()); + String process = nextArgRequired(); + String heapFile = nextArgRequired(); + ParcelFileDescriptor fd = null; + + try { + fd = ParcelFileDescriptor.open( + new File(heapFile), + ParcelFileDescriptor.MODE_CREATE | + ParcelFileDescriptor.MODE_TRUNCATE | + ParcelFileDescriptor.MODE_READ_WRITE); + } catch (FileNotFoundException e) { + System.err.println("Error: Unable to open file: " + heapFile); + return; + } + + if (!mAm.dumpHeap(process, managed, heapFile, fd)) { + throw new AndroidException("HEAP DUMP FAILED on process " + process); + } + } + private class IntentReceiver extends IIntentReceiver.Stub { private boolean mFinished = false; @@ -593,6 +617,8 @@ public class Am { "\n" + " start profiling: am profile <PROCESS> start <FILE>\n" + " stop profiling: am profile <PROCESS> stop\n" + + " dump heap: am dumpheap [flags] <PROCESS> <FILE>\n" + + " -n: dump native heap instead of managed heap\n" + "\n" + " <INTENT> specifications include these flags:\n" + " [-a <ACTION>] [-d <DATA_URI>] [-t <MIME_TYPE>]\n" + |