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

Commit 49fee9a9 authored by Kevin Jeon's avatar Kevin Jeon Committed by Android (Google) Code Review
Browse files

Merge "Add Debug.getRss()" into main

parents 60b37c28 7aa6d657
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -32285,6 +32285,7 @@ package android.os {
    method public static long getNativeHeapFreeSize();
    method public static long getNativeHeapSize();
    method public static long getPss();
    method @FlaggedApi(Flags.FLAG_REMOVE_APP_PROFILER_PSS_COLLECTION) public static long getRss();
    method public static String getRuntimeStat(String);
    method public static java.util.Map<java.lang.String,java.lang.String> getRuntimeStats();
    method @Deprecated public static int getThreadAllocCount();
+18 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package android.os;

import android.annotation.FlaggedApi;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.app.AppGlobals;
@@ -1953,6 +1954,23 @@ public final class Debug
     */
    public static native long getPss(int pid, long[] outUssSwapPssRss, long[] outMemtrack);

    /**
     * Retrieves the RSS memory used by the process as given by the status file.
     */
    @FlaggedApi(Flags.FLAG_REMOVE_APP_PROFILER_PSS_COLLECTION)
    public static native long getRss();

    /**
     * Retrieves the RSS memory used by the process as given by the status file. Optionally supply a
     * long array of up to 4 entries to retrieve the total memtrack reported size, memtrack
     * graphics, memtrack gl, and memtrack other.
     *
     * @return The RSS memory usage, or 0 if retrieval failed (i.e. the PID is gone).
     * @hide
     */
    @FlaggedApi(Flags.FLAG_REMOVE_APP_PROFILER_PSS_COLLECTION)
    public static native long getRss(int pid, long[] outMemtrack);

    /** @hide */
    public static final int MEMINFO_TOTAL = 0;
    /** @hide */
+82 −56
Original line number Diff line number Diff line
@@ -565,6 +565,51 @@ static jlong android_os_Debug_getPss(JNIEnv *env, jobject clazz)
    return android_os_Debug_getPssPid(env, clazz, getpid(), NULL, NULL);
}

static jlong android_os_Debug_getRssPid(JNIEnv* env, jobject clazz, jint pid,
                                        jlongArray outMemtrack) {
    jlong rss = 0;
    jlong memtrack = 0;

    struct graphics_memory_pss graphics_mem;
    if (read_memtrack_memory(pid, &graphics_mem) == 0) {
        rss = memtrack = graphics_mem.graphics + graphics_mem.gl + graphics_mem.other;
    }

    ::android::meminfo::ProcMemInfo proc_mem(pid);
    uint64_t status_rss;
    if (proc_mem.StatusVmRSS(&status_rss)) {
        rss += status_rss;
    } else {
        return 0;
    }

    if (outMemtrack != NULL) {
        int outLen = env->GetArrayLength(outMemtrack);
        if (outLen >= 1) {
            jlong* outMemtrackArray = env->GetLongArrayElements(outMemtrack, 0);
            if (outMemtrackArray != NULL) {
                outMemtrackArray[0] = memtrack;
                if (outLen >= 2) {
                    outMemtrackArray[1] = graphics_mem.graphics;
                }
                if (outLen >= 3) {
                    outMemtrackArray[2] = graphics_mem.gl;
                }
                if (outLen >= 4) {
                    outMemtrackArray[3] = graphics_mem.other;
                }
            }
            env->ReleaseLongArrayElements(outMemtrack, outMemtrackArray, 0);
        }
    }

    return rss;
}

static jlong android_os_Debug_getRss(JNIEnv* env, jobject clazz) {
    return android_os_Debug_getRssPid(env, clazz, getpid(), NULL);
}

// The 1:1 mapping of MEMINFO_* enums here must match with the constants from
// Debug.java.
enum {
@@ -974,62 +1019,43 @@ static jboolean android_os_Debug_isVmapStack(JNIEnv *env, jobject clazz)
 */

static const JNINativeMethod gMethods[] = {
    { "getNativeHeapSize",      "()J",
            (void*) android_os_Debug_getNativeHeapSize },
    { "getNativeHeapAllocatedSize", "()J",
            (void*) android_os_Debug_getNativeHeapAllocatedSize },
    { "getNativeHeapFreeSize",  "()J",
            (void*) android_os_Debug_getNativeHeapFreeSize },
        {"getNativeHeapSize", "()J", (void*)android_os_Debug_getNativeHeapSize},
        {"getNativeHeapAllocatedSize", "()J", (void*)android_os_Debug_getNativeHeapAllocatedSize},
        {"getNativeHeapFreeSize", "()J", (void*)android_os_Debug_getNativeHeapFreeSize},
        {"getMemoryInfo", "(Landroid/os/Debug$MemoryInfo;)V",
         (void*)android_os_Debug_getDirtyPages},
        {"getMemoryInfo", "(ILandroid/os/Debug$MemoryInfo;)Z",
         (void*)android_os_Debug_getDirtyPagesPid},
    { "getPss",                 "()J",
            (void*) android_os_Debug_getPss },
    { "getPss",                 "(I[J[J)J",
            (void*) android_os_Debug_getPssPid },
    { "getMemInfo",             "([J)V",
            (void*) android_os_Debug_getMemInfo },
    { "dumpNativeHeap",         "(Ljava/io/FileDescriptor;)V",
            (void*) android_os_Debug_dumpNativeHeap },
        {"getPss", "()J", (void*)android_os_Debug_getPss},
        {"getPss", "(I[J[J)J", (void*)android_os_Debug_getPssPid},
        {"getRss", "()J", (void*)android_os_Debug_getRss},
        {"getRss", "(I[J)J", (void*)android_os_Debug_getRssPid},
        {"getMemInfo", "([J)V", (void*)android_os_Debug_getMemInfo},
        {"dumpNativeHeap", "(Ljava/io/FileDescriptor;)V", (void*)android_os_Debug_dumpNativeHeap},
        {"dumpNativeMallocInfo", "(Ljava/io/FileDescriptor;)V",
         (void*)android_os_Debug_dumpNativeMallocInfo},
    { "getBinderSentTransactions", "()I",
            (void*) android_os_Debug_getBinderSentTransactions },
    { "getBinderReceivedTransactions", "()I",
            (void*) android_os_getBinderReceivedTransactions },
    { "getBinderLocalObjectCount", "()I",
            (void*)android_os_Debug_getLocalObjectCount },
    { "getBinderProxyObjectCount", "()I",
            (void*)android_os_Debug_getProxyObjectCount },
    { "getBinderDeathObjectCount", "()I",
            (void*)android_os_Debug_getDeathObjectCount },
        {"getBinderSentTransactions", "()I", (void*)android_os_Debug_getBinderSentTransactions},
        {"getBinderReceivedTransactions", "()I", (void*)android_os_getBinderReceivedTransactions},
        {"getBinderLocalObjectCount", "()I", (void*)android_os_Debug_getLocalObjectCount},
        {"getBinderProxyObjectCount", "()I", (void*)android_os_Debug_getProxyObjectCount},
        {"getBinderDeathObjectCount", "()I", (void*)android_os_Debug_getDeathObjectCount},
        {"dumpJavaBacktraceToFileTimeout", "(ILjava/lang/String;I)Z",
         (void*)android_os_Debug_dumpJavaBacktraceToFileTimeout},
        {"dumpNativeBacktraceToFileTimeout", "(ILjava/lang/String;I)Z",
         (void*)android_os_Debug_dumpNativeBacktraceToFileTimeout},
        {"getUnreachableMemory", "(IZ)Ljava/lang/String;",
         (void*)android_os_Debug_getUnreachableMemory},
    { "getZramFreeKb", "()J",
            (void*)android_os_Debug_getFreeZramKb },
    { "getIonHeapsSizeKb", "()J",
            (void*)android_os_Debug_getIonHeapsSizeKb },
    { "getDmabufTotalExportedKb", "()J",
            (void*)android_os_Debug_getDmabufTotalExportedKb },
    { "getGpuPrivateMemoryKb", "()J",
            (void*)android_os_Debug_getGpuPrivateMemoryKb },
        {"getZramFreeKb", "()J", (void*)android_os_Debug_getFreeZramKb},
        {"getIonHeapsSizeKb", "()J", (void*)android_os_Debug_getIonHeapsSizeKb},
        {"getDmabufTotalExportedKb", "()J", (void*)android_os_Debug_getDmabufTotalExportedKb},
        {"getGpuPrivateMemoryKb", "()J", (void*)android_os_Debug_getGpuPrivateMemoryKb},
        {"getDmabufHeapTotalExportedKb", "()J",
         (void*)android_os_Debug_getDmabufHeapTotalExportedKb},
    { "getIonPoolsSizeKb", "()J",
            (void*)android_os_Debug_getIonPoolsSizeKb },
    { "getDmabufMappedSizeKb", "()J",
            (void*)android_os_Debug_getDmabufMappedSizeKb },
    { "getDmabufHeapPoolsSizeKb", "()J",
            (void*)android_os_Debug_getDmabufHeapPoolsSizeKb },
    { "getGpuTotalUsageKb", "()J",
            (void*)android_os_Debug_getGpuTotalUsageKb },
    { "isVmapStack", "()Z",
            (void*)android_os_Debug_isVmapStack },
        {"getIonPoolsSizeKb", "()J", (void*)android_os_Debug_getIonPoolsSizeKb},
        {"getDmabufMappedSizeKb", "()J", (void*)android_os_Debug_getDmabufMappedSizeKb},
        {"getDmabufHeapPoolsSizeKb", "()J", (void*)android_os_Debug_getDmabufHeapPoolsSizeKb},
        {"getGpuTotalUsageKb", "()J", (void*)android_os_Debug_getGpuTotalUsageKb},
        {"isVmapStack", "()Z", (void*)android_os_Debug_isVmapStack},
};

int register_android_os_Debug(JNIEnv *env)