Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9269d67c authored by Christopher Ferris's avatar Christopher Ferris Committed by Android (Google) Code Review
Browse files

Merge "Allow logging internal allocator stats." into main

parents 988b1898 8d1938ef
Loading
Loading
Loading
Loading
+8 −3
Original line number Diff line number Diff line
@@ -1544,11 +1544,12 @@ public final class ActivityThread extends ClientTransactionHandler
        @Override
        public void dumpMemInfo(ParcelFileDescriptor pfd, Debug.MemoryInfo mem, boolean checkin,
                boolean dumpFullInfo, boolean dumpDalvik, boolean dumpSummaryOnly,
                boolean dumpUnreachable, String[] args) {
                boolean dumpUnreachable, boolean dumpAllocatorStats, String[] args) {
            FileOutputStream fout = new FileOutputStream(pfd.getFileDescriptor());
            PrintWriter pw = new FastPrintWriter(fout);
            try {
                dumpMemInfo(pw, mem, checkin, dumpFullInfo, dumpDalvik, dumpSummaryOnly, dumpUnreachable);
                dumpMemInfo(pw, mem, checkin, dumpFullInfo, dumpDalvik, dumpSummaryOnly,
                            dumpUnreachable, dumpAllocatorStats);
            } finally {
                pw.flush();
                IoUtils.closeQuietly(pfd);
@@ -1557,7 +1558,8 @@ public final class ActivityThread extends ClientTransactionHandler

        @NeverCompile
        private void dumpMemInfo(PrintWriter pw, Debug.MemoryInfo memInfo, boolean checkin,
                boolean dumpFullInfo, boolean dumpDalvik, boolean dumpSummaryOnly, boolean dumpUnreachable) {
                boolean dumpFullInfo, boolean dumpDalvik, boolean dumpSummaryOnly,
                boolean dumpUnreachable, boolean dumpAllocatorStats) {
            long nativeMax = Debug.getNativeHeapSize() / 1024;
            long nativeAllocated = Debug.getNativeHeapAllocatedSize() / 1024;
            long nativeFree = Debug.getNativeHeapFreeSize() / 1024;
@@ -1710,6 +1712,9 @@ public final class ActivityThread extends ClientTransactionHandler
                pw.println(" Unreachable memory");
                pw.print(Debug.getUnreachableMemory(100, showContents));
            }
            if (dumpAllocatorStats) {
                Debug.logAllocatorStats();
            }
        }

        @NeverCompile
+1 −1
Original line number Diff line number Diff line
@@ -129,7 +129,7 @@ oneway interface IApplicationThread {
    void scheduleTrimMemory(int level);
    void dumpMemInfo(in ParcelFileDescriptor fd, in Debug.MemoryInfo mem, boolean checkin,
            boolean dumpInfo, boolean dumpDalvik, boolean dumpSummaryOnly, boolean dumpUnreachable,
            in String[] args);
            boolean dumpAllocatorLogs, in String[] args);
    void dumpMemInfoProto(in ParcelFileDescriptor fd, in Debug.MemoryInfo mem,
            boolean dumpInfo, boolean dumpDalvik, boolean dumpSummaryOnly, boolean dumpUnreachable,
            in String[] args);
+9 −0
Original line number Diff line number Diff line
@@ -2702,4 +2702,13 @@ public final class Debug
     * @hide
     */
    public static native boolean isVmapStack();

    /**
     * Log internal statistics about the allocator.
     * @return true if the statistics were logged properly, false if not.
     *
     * @hide
     */
    public static native boolean logAllocatorStats();

}
+5 −0
Original line number Diff line number Diff line
@@ -1014,6 +1014,10 @@ static jboolean android_os_Debug_isVmapStack(JNIEnv *env, jobject clazz)
    return cfg_state == CONFIG_SET;
}

static jboolean android_os_Debug_logAllocatorStats(JNIEnv*, jobject) {
    return mallopt(M_LOG_STATS, 0) == 1 ? JNI_TRUE : JNI_FALSE;
}

/*
 * JNI registration.
 */
@@ -1056,6 +1060,7 @@ static const JNINativeMethod gMethods[] = {
        {"getDmabufHeapPoolsSizeKb", "()J", (void*)android_os_Debug_getDmabufHeapPoolsSizeKb},
        {"getGpuTotalUsageKb", "()J", (void*)android_os_Debug_getGpuTotalUsageKb},
        {"isVmapStack", "()Z", (void*)android_os_Debug_isVmapStack},
        {"logAllocatorStats", "()Z", (void*)android_os_Debug_logAllocatorStats},
};

int register_android_os_Debug(JNIEnv *env)
+6 −2
Original line number Diff line number Diff line
@@ -11972,6 +11972,7 @@ public class ActivityManagerService extends IActivityManager.Stub
        boolean dumpSwapPss;
        boolean dumpProto;
        boolean mDumpPrivateDirty;
        boolean mDumpAllocatorStats;
    }
    @NeverCompile // Avoid size overhead of debugging code.
@@ -11991,6 +11992,7 @@ public class ActivityManagerService extends IActivityManager.Stub
        opts.dumpSwapPss = false;
        opts.dumpProto = asProto;
        opts.mDumpPrivateDirty = false;
        opts.mDumpAllocatorStats = false;
        int opti = 0;
        while (opti < args.length) {
@@ -12027,7 +12029,8 @@ public class ActivityManagerService extends IActivityManager.Stub
                opts.isCheckinRequest = true;
            } else if ("--proto".equals(opt)) {
                opts.dumpProto = true;
            } else if ("--logstats".equals(opt)) {
                opts.mDumpAllocatorStats = true;
            } else if ("-h".equals(opt)) {
                pw.println("meminfo dump options: [-a] [-d] [-c] [-s] [--oom] [process]");
                pw.println("  -a: include all available information for each process.");
@@ -12238,7 +12241,8 @@ public class ActivityManagerService extends IActivityManager.Stub
                            try {
                                thread.dumpMemInfo(tp.getWriteFd(),
                                        mi, opts.isCheckinRequest, opts.dumpFullDetails,
                                        opts.dumpDalvik, opts.dumpSummaryOnly, opts.dumpUnreachable, innerArgs);
                                        opts.dumpDalvik, opts.dumpSummaryOnly, opts.dumpUnreachable,
                                        opts.mDumpAllocatorStats, innerArgs);
                                tp.go(fd, opts.dumpUnreachable ? 30000 : 5000);
                            } finally {
                                tp.kill();