From 824c510752fd6a30cdba5ed7324cb80a5043ce26 Mon Sep 17 00:00:00 2001 From: Andy McFadden Date: Fri, 9 Jul 2010 16:26:57 -0700 Subject: 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 --- core/java/android/app/ApplicationThreadNative.java | 28 ++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'core/java/android/app/ApplicationThreadNative.java') diff --git a/core/java/android/app/ApplicationThreadNative.java b/core/java/android/app/ApplicationThreadNative.java index 1c20062f3f84..dc2145fb4c2c 100644 --- a/core/java/android/app/ApplicationThreadNative.java +++ b/core/java/android/app/ApplicationThreadNative.java @@ -403,6 +403,17 @@ public abstract class ApplicationThreadNative extends Binder scheduleCrash(msg); return true; } + + case DUMP_HEAP_TRANSACTION: + { + data.enforceInterface(IApplicationThread.descriptor); + boolean managed = data.readInt() != 0; + String path = data.readString(); + ParcelFileDescriptor fd = data.readInt() != 0 + ? data.readFileDescriptor() : null; + dumpHeap(managed, path, fd); + return true; + } } return super.onTransact(code, data, reply, flags); @@ -829,5 +840,22 @@ class ApplicationThreadProxy implements IApplicationThread { data.recycle(); } + + public void dumpHeap(boolean managed, String path, + ParcelFileDescriptor fd) throws RemoteException { + Parcel data = Parcel.obtain(); + data.writeInterfaceToken(IApplicationThread.descriptor); + data.writeInt(managed ? 1 : 0); + data.writeString(path); + if (fd != null) { + data.writeInt(1); + fd.writeToParcel(data, Parcelable.PARCELABLE_WRITE_RETURN_VALUE); + } else { + data.writeInt(0); + } + mRemote.transact(DUMP_HEAP_TRANSACTION, data, null, + IBinder.FLAG_ONEWAY); + data.recycle(); + } } -- cgit v1.2.3