Merge "Add dumpsys meminfo --unreachable"
This commit is contained in:
@@ -941,18 +941,19 @@ public final class ActivityThread {
|
||||
|
||||
@Override
|
||||
public void dumpMemInfo(FileDescriptor fd, Debug.MemoryInfo mem, boolean checkin,
|
||||
boolean dumpFullInfo, boolean dumpDalvik, boolean dumpSummaryOnly, String[] args) {
|
||||
boolean dumpFullInfo, boolean dumpDalvik, boolean dumpSummaryOnly,
|
||||
boolean dumpUnreachable, String[] args) {
|
||||
FileOutputStream fout = new FileOutputStream(fd);
|
||||
PrintWriter pw = new FastPrintWriter(fout);
|
||||
try {
|
||||
dumpMemInfo(pw, mem, checkin, dumpFullInfo, dumpDalvik, dumpSummaryOnly);
|
||||
dumpMemInfo(pw, mem, checkin, dumpFullInfo, dumpDalvik, dumpSummaryOnly, dumpUnreachable);
|
||||
} finally {
|
||||
pw.flush();
|
||||
}
|
||||
}
|
||||
|
||||
private void dumpMemInfo(PrintWriter pw, Debug.MemoryInfo memInfo, boolean checkin,
|
||||
boolean dumpFullInfo, boolean dumpDalvik, boolean dumpSummaryOnly) {
|
||||
boolean dumpFullInfo, boolean dumpDalvik, boolean dumpSummaryOnly, boolean dumpUnreachable) {
|
||||
long nativeMax = Debug.getNativeHeapSize() / 1024;
|
||||
long nativeAllocated = Debug.getNativeHeapAllocatedSize() / 1024;
|
||||
long nativeFree = Debug.getNativeHeapFreeSize() / 1024;
|
||||
@@ -1066,6 +1067,16 @@ public final class ActivityThread {
|
||||
pw.println(" Asset Allocations");
|
||||
pw.print(assetAlloc);
|
||||
}
|
||||
|
||||
// Unreachable native memory
|
||||
if (dumpUnreachable) {
|
||||
boolean showContents = ((mBoundApplication != null)
|
||||
&& ((mBoundApplication.appInfo.flags&ApplicationInfo.FLAG_DEBUGGABLE) != 0))
|
||||
|| android.os.Build.IS_DEBUGGABLE;
|
||||
pw.println(" ");
|
||||
pw.println(" Unreachable memory");
|
||||
pw.print(Debug.getUnreachableMemory(100, showContents));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -534,11 +534,12 @@ public abstract class ApplicationThreadNative extends Binder
|
||||
boolean dumpInfo = data.readInt() != 0;
|
||||
boolean dumpDalvik = data.readInt() != 0;
|
||||
boolean dumpSummaryOnly = data.readInt() != 0;
|
||||
boolean dumpUnreachable = data.readInt() != 0;
|
||||
String[] args = data.readStringArray();
|
||||
if (fd != null) {
|
||||
try {
|
||||
dumpMemInfo(fd.getFileDescriptor(), mi, checkin, dumpInfo,
|
||||
dumpDalvik, dumpSummaryOnly, args);
|
||||
dumpDalvik, dumpSummaryOnly, dumpUnreachable, args);
|
||||
} finally {
|
||||
try {
|
||||
fd.close();
|
||||
@@ -1261,7 +1262,8 @@ class ApplicationThreadProxy implements IApplicationThread {
|
||||
}
|
||||
|
||||
public void dumpMemInfo(FileDescriptor fd, Debug.MemoryInfo mem, boolean checkin,
|
||||
boolean dumpInfo, boolean dumpDalvik, boolean dumpSummaryOnly, String[] args) throws RemoteException {
|
||||
boolean dumpInfo, boolean dumpDalvik, boolean dumpSummaryOnly,
|
||||
boolean dumpUnreachable, String[] args) throws RemoteException {
|
||||
Parcel data = Parcel.obtain();
|
||||
Parcel reply = Parcel.obtain();
|
||||
data.writeInterfaceToken(IApplicationThread.descriptor);
|
||||
@@ -1271,6 +1273,7 @@ class ApplicationThreadProxy implements IApplicationThread {
|
||||
data.writeInt(dumpInfo ? 1 : 0);
|
||||
data.writeInt(dumpDalvik ? 1 : 0);
|
||||
data.writeInt(dumpSummaryOnly ? 1 : 0);
|
||||
data.writeInt(dumpUnreachable ? 1 : 0);
|
||||
data.writeStringArray(args);
|
||||
mRemote.transact(DUMP_MEM_INFO_TRANSACTION, data, reply, 0);
|
||||
reply.readException();
|
||||
|
||||
@@ -132,7 +132,8 @@ public interface IApplicationThread extends IInterface {
|
||||
void updatePackageCompatibilityInfo(String pkg, CompatibilityInfo info) throws RemoteException;
|
||||
void scheduleTrimMemory(int level) throws RemoteException;
|
||||
void dumpMemInfo(FileDescriptor fd, Debug.MemoryInfo mem, boolean checkin, boolean dumpInfo,
|
||||
boolean dumpDalvik, boolean dumpSummaryOnly, String[] args) throws RemoteException;
|
||||
boolean dumpDalvik, boolean dumpSummaryOnly, boolean dumpUnreachable,
|
||||
String[] args) throws RemoteException;
|
||||
void dumpGfxInfo(FileDescriptor fd, String[] args) throws RemoteException;
|
||||
void dumpDbInfo(FileDescriptor fd, String[] args) throws RemoteException;
|
||||
void unstableProviderDied(IBinder provider) throws RemoteException;
|
||||
|
||||
@@ -2111,6 +2111,14 @@ href="{@docRoot}guide/developing/tools/traceview.html">Traceview: A Graphical Lo
|
||||
*/
|
||||
public static native void dumpNativeBacktraceToFile(int pid, String file);
|
||||
|
||||
/**
|
||||
* Get description of unreachable native memory.
|
||||
* @param limit the number of leaks to provide info on, 0 to only get a summary.
|
||||
* @param contents true to include a hex dump of the contents of unreachable memory.
|
||||
* @return the String containing a description of unreachable memory.
|
||||
* @hide */
|
||||
public static native String getUnreachableMemory(int limit, boolean contents);
|
||||
|
||||
/**
|
||||
* Return a String describing the calling method and location at a particular stack depth.
|
||||
* @param callStack the Thread stack
|
||||
|
||||
@@ -253,7 +253,8 @@ LOCAL_SHARED_LIBRARIES := \
|
||||
libprocessgroup \
|
||||
libnativebridge \
|
||||
libradio_metadata \
|
||||
libnativeloader
|
||||
libnativeloader \
|
||||
libmemunreachable \
|
||||
|
||||
LOCAL_SHARED_LIBRARIES += \
|
||||
libhwui \
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include "utils/misc.h"
|
||||
#include "cutils/debugger.h"
|
||||
#include <memtrack/memtrack.h>
|
||||
#include <memunreachable/memunreachable.h>
|
||||
|
||||
#include <cutils/log.h>
|
||||
#include <fcntl.h>
|
||||
@@ -36,6 +37,9 @@
|
||||
#include <ctype.h>
|
||||
#include <malloc.h>
|
||||
|
||||
#include <iomanip>
|
||||
#include <string>
|
||||
|
||||
namespace android
|
||||
{
|
||||
|
||||
@@ -971,6 +975,13 @@ static void android_os_Debug_dumpNativeBacktraceToFile(JNIEnv* env, jobject claz
|
||||
close(fd);
|
||||
}
|
||||
|
||||
static jstring android_os_Debug_getUnreachableMemory(JNIEnv* env, jobject clazz,
|
||||
jint limit, jboolean contents)
|
||||
{
|
||||
std::string s = GetUnreachableMemoryString(contents, limit);
|
||||
return env->NewStringUTF(s.c_str());
|
||||
}
|
||||
|
||||
/*
|
||||
* JNI registration.
|
||||
*/
|
||||
@@ -1006,6 +1017,8 @@ static const JNINativeMethod gMethods[] = {
|
||||
(void*)android_os_Debug_getDeathObjectCount },
|
||||
{ "dumpNativeBacktraceToFile", "(ILjava/lang/String;)V",
|
||||
(void*)android_os_Debug_dumpNativeBacktraceToFile },
|
||||
{ "getUnreachableMemory", "(IZ)Ljava/lang/String;",
|
||||
(void*)android_os_Debug_getUnreachableMemory },
|
||||
};
|
||||
|
||||
int register_android_os_Debug(JNIEnv *env)
|
||||
|
||||
@@ -14693,6 +14693,7 @@ public final class ActivityManagerService extends ActivityManagerNative
|
||||
boolean dumpFullDetails = false;
|
||||
boolean dumpDalvik = false;
|
||||
boolean dumpSummaryOnly = false;
|
||||
boolean dumpUnreachable = false;
|
||||
boolean oomOnly = false;
|
||||
boolean isCompact = false;
|
||||
boolean localOnly = false;
|
||||
@@ -14716,6 +14717,8 @@ public final class ActivityManagerService extends ActivityManagerNative
|
||||
} else if ("-s".equals(opt)) {
|
||||
dumpDetails = true;
|
||||
dumpSummaryOnly = true;
|
||||
} else if ("--unreachable".equals(opt)) {
|
||||
dumpUnreachable = true;
|
||||
} else if ("--oom".equals(opt)) {
|
||||
oomOnly = true;
|
||||
} else if ("--local".equals(opt)) {
|
||||
@@ -14862,7 +14865,7 @@ public final class ActivityManagerService extends ActivityManagerNative
|
||||
try {
|
||||
pw.flush();
|
||||
thread.dumpMemInfo(fd, mi, isCheckinRequest, dumpFullDetails,
|
||||
dumpDalvik, dumpSummaryOnly, innerArgs);
|
||||
dumpDalvik, dumpSummaryOnly, dumpUnreachable, innerArgs);
|
||||
} catch (RemoteException e) {
|
||||
if (!isCheckinRequest) {
|
||||
pw.println("Got RemoteException!");
|
||||
|
||||
Reference in New Issue
Block a user