diff options
| author | 2023-09-19 01:44:16 +0000 | |
|---|---|---|
| committer | 2023-09-19 01:44:16 +0000 | |
| commit | 49fee9a9bbb305047b1633c0ecf9723a63f3ef8b (patch) | |
| tree | 3b9eedc8c8f4a4df1da81e825db8358acd572239 | |
| parent | 60b37c28c62ee25e394e28bbb3a4cd84732e48b5 (diff) | |
| parent | 7aa6d65722f142c8d813d84855d33bc75a7e85c3 (diff) | |
Merge "Add Debug.getRss()" into main
| -rw-r--r-- | core/api/current.txt | 1 | ||||
| -rw-r--r-- | core/java/android/os/Debug.java | 18 | ||||
| -rw-r--r-- | core/jni/android_os_Debug.cpp | 138 |
3 files changed, 101 insertions, 56 deletions
diff --git a/core/api/current.txt b/core/api/current.txt index f488c82a2a60..a5784a048274 100644 --- a/core/api/current.txt +++ b/core/api/current.txt @@ -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(); diff --git a/core/java/android/os/Debug.java b/core/java/android/os/Debug.java index 62d9c69565da..c527cb5344c1 100644 --- a/core/java/android/os/Debug.java +++ b/core/java/android/os/Debug.java @@ -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 */ diff --git a/core/jni/android_os_Debug.cpp b/core/jni/android_os_Debug.cpp index fe957624cf4b..e0bcef642d82 100644 --- a/core/jni/android_os_Debug.cpp +++ b/core/jni/android_os_Debug.cpp @@ -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 }, - { "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 }, - { "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 }, - { "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 }, - { "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 }, + {"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}, + {"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}, + {"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}, + {"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}, }; int register_android_os_Debug(JNIEnv *env) |