Loading core/java/android/os/Debug.java +7 −0 Original line number Diff line number Diff line Loading @@ -2589,6 +2589,13 @@ public final class Debug */ public static native long getIonPoolsSizeKb(); /** * Return GPU DMA buffer usage in kB or -1 on error. * * @hide */ public static native long getGpuDmaBufUsageKb(); /** * Return DMA-BUF memory mapped by processes in kB. * Notes: Loading core/jni/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -207,6 +207,7 @@ cc_library_shared { ], shared_libs: [ "android.hardware.memtrack-unstable-ndk_platform", "audioclient-types-aidl-cpp", "audioflinger-aidl-cpp", "av-types-aidl-cpp", Loading core/jni/android_os_Debug.cpp +29 −0 Original line number Diff line number Diff line Loading @@ -33,6 +33,7 @@ #include <string> #include <vector> #include <aidl/android/hardware/memtrack/DeviceInfo.h> #include <android-base/logging.h> #include <bionic/malloc.h> #include <debuggerd/client.h> Loading @@ -45,6 +46,7 @@ #include "jni.h" #include <dmabufinfo/dmabuf_sysfs_stats.h> #include <dmabufinfo/dmabufinfo.h> #include <dmabufinfo/dmabuf_sysfs_stats.h> #include <meminfo/procmeminfo.h> #include <meminfo/sysmeminfo.h> #include <memtrack/memtrack.h> Loading Loading @@ -849,6 +851,31 @@ static jlong android_os_Debug_getDmabufHeapPoolsSizeKb(JNIEnv* env, jobject claz return poolsSizeKb; } static jlong android_os_Debug_getGpuDmaBufUsageKb(JNIEnv* env, jobject clazz) { std::vector<aidl::android::hardware::memtrack::DeviceInfo> gpu_device_info; if (!memtrack_gpu_device_info(&gpu_device_info)) { return -1; } dmabufinfo::DmabufSysfsStats stats; if (!GetDmabufSysfsStats(&stats)) { return -1; } jlong sizeKb = 0; const auto& importer_stats = stats.importer_info(); for (const auto& dev_info : gpu_device_info) { const auto& importer_info = importer_stats.find(dev_info.name); if (importer_info == importer_stats.end()) { continue; } sizeKb += importer_info->second.size; } return sizeKb; } static jlong android_os_Debug_getDmabufMappedSizeKb(JNIEnv* env, jobject clazz) { jlong dmabufPss = 0; std::vector<dmabufinfo::DmaBuffer> dmabufs; Loading Loading @@ -957,6 +984,8 @@ static const JNINativeMethod gMethods[] = { (void*)android_os_Debug_getIonHeapsSizeKb }, { "getDmabufTotalExportedKb", "()J", (void*)android_os_Debug_getDmabufTotalExportedKb }, { "getGpuDmaBufUsageKb", "()J", (void*)android_os_Debug_getGpuDmaBufUsageKb }, { "getIonPoolsSizeKb", "()J", (void*)android_os_Debug_getIonPoolsSizeKb }, { "getDmabufMappedSizeKb", "()J", Loading services/core/java/com/android/server/am/ActivityManagerService.java +42 −9 Original line number Diff line number Diff line Loading @@ -1490,7 +1490,9 @@ public class ActivityManagerService extends IActivityManager.Stub private static final int INDEX_TOTAL_SWAP_PSS = 10; private static final int INDEX_TOTAL_RSS = 11; private static final int INDEX_TOTAL_NATIVE_PSS = 12; private static final int INDEX_LAST = 13; private static final int INDEX_TOTAL_MEMTRACK_GRAPHICS = 13; private static final int INDEX_TOTAL_MEMTRACK_GL = 14; private static final int INDEX_LAST = 15; final class UiHandler extends Handler { public UiHandler() { Loading Loading @@ -10316,6 +10318,7 @@ public class ActivityManagerService extends IActivityManager.Stub long[] miscPss = new long[Debug.MemoryInfo.NUM_OTHER_STATS]; long[] miscSwapPss = new long[Debug.MemoryInfo.NUM_OTHER_STATS]; long[] miscRss = new long[Debug.MemoryInfo.NUM_OTHER_STATS]; long[] memtrackTmp = new long[4]; long oomPss[] = new long[DUMP_MEM_OOM_LABEL.length]; long oomSwapPss[] = new long[DUMP_MEM_OOM_LABEL.length]; Loading Loading @@ -10349,6 +10352,8 @@ public class ActivityManagerService extends IActivityManager.Stub final int reportType; final long startTime; final long endTime; long memtrackGraphics = 0; long memtrackGl = 0; if (opts.dumpDetails || (!brief && !opts.oomOnly)) { reportType = ProcessStats.ADD_PSS_EXTERNAL_SLOW; startTime = SystemClock.currentThreadTimeMillis(); Loading @@ -10360,7 +10365,7 @@ public class ActivityManagerService extends IActivityManager.Stub } else { reportType = ProcessStats.ADD_PSS_EXTERNAL; startTime = SystemClock.currentThreadTimeMillis(); long pss = Debug.getPss(pid, tmpLong, null); long pss = Debug.getPss(pid, tmpLong, memtrackTmp); if (pss == 0) { continue; } Loading @@ -10368,6 +10373,8 @@ public class ActivityManagerService extends IActivityManager.Stub endTime = SystemClock.currentThreadTimeMillis(); mi.dalvikPrivateDirty = (int) tmpLong[0]; mi.dalvikRss = (int) tmpLong[2]; memtrackGraphics = memtrackTmp[1]; memtrackGl = memtrackTmp[2]; } if (!opts.isCheckinRequest && opts.dumpDetails) { pw.println("\n** MEMINFO in pid " + pid + " [" + r.processName + "] **"); Loading Loading @@ -10431,6 +10438,8 @@ public class ActivityManagerService extends IActivityManager.Stub ss[INDEX_TOTAL_PSS] += myTotalPss; ss[INDEX_TOTAL_SWAP_PSS] += myTotalSwapPss; ss[INDEX_TOTAL_RSS] += myTotalRss; ss[INDEX_TOTAL_MEMTRACK_GRAPHICS] += memtrackGraphics; ss[INDEX_TOTAL_MEMTRACK_GL] += memtrackGl; MemItem pssItem = new MemItem(r.processName + " (pid " + pid + (hasActivities ? " / activities)" : ")"), r.processName, myTotalPss, myTotalSwapPss, myTotalRss, pid, hasActivities); Loading Loading @@ -10494,6 +10503,8 @@ public class ActivityManagerService extends IActivityManager.Stub final Debug.MemoryInfo[] memInfos = new Debug.MemoryInfo[1]; mAppProfiler.forAllCpuStats((st) -> { if (st.vsize > 0 && procMemsMap.indexOfKey(st.pid) < 0) { long memtrackGraphics = 0; long memtrackGl = 0; if (memInfos[0] == null) { memInfos[0] = new Debug.MemoryInfo(); } Loading @@ -10503,13 +10514,15 @@ public class ActivityManagerService extends IActivityManager.Stub return; } } else { long pss = Debug.getPss(st.pid, tmpLong, null); long pss = Debug.getPss(st.pid, tmpLong, memtrackTmp); if (pss == 0) { return; } info.nativePss = (int) pss; info.nativePrivateDirty = (int) tmpLong[0]; info.nativeRss = (int) tmpLong[2]; memtrackGraphics = memtrackTmp[1]; memtrackGl = memtrackTmp[2]; } final long myTotalPss = info.getTotalPss(); Loading @@ -10519,6 +10532,8 @@ public class ActivityManagerService extends IActivityManager.Stub ss[INDEX_TOTAL_SWAP_PSS] += myTotalSwapPss; ss[INDEX_TOTAL_RSS] += myTotalRss; ss[INDEX_TOTAL_NATIVE_PSS] += myTotalPss; ss[INDEX_TOTAL_MEMTRACK_GRAPHICS] += memtrackGraphics; ss[INDEX_TOTAL_MEMTRACK_GL] += memtrackGl; MemItem pssItem = new MemItem(st.name + " (pid " + st.pid + ")", st.name, myTotalPss, info.getSummaryTotalSwapPss(), myTotalRss, Loading Loading @@ -10726,7 +10741,11 @@ public class ActivityManagerService extends IActivityManager.Stub pw.print(" mapped + "); pw.print(stringifyKBSize(dmabufUnmapped)); pw.println(" unmapped)"); kernelUsed += totalExportedDmabuf; // Account unmapped dmabufs as part of kernel memory allocations kernelUsed += dmabufUnmapped; // Replace memtrack HAL reported Graphics category with mapped dmabufs ss[INDEX_TOTAL_PSS] -= ss[INDEX_TOTAL_MEMTRACK_GRAPHICS]; ss[INDEX_TOTAL_PSS] += dmabufMapped; } final long totalDmabufHeapPool = Debug.getDmabufHeapPoolsSizeKb(); if (totalDmabufHeapPool >= 0) { Loading @@ -10736,13 +10755,27 @@ public class ActivityManagerService extends IActivityManager.Stub } final long gpuUsage = Debug.getGpuTotalUsageKb(); if (gpuUsage >= 0) { final long gpuDmaBufUsage = Debug.getGpuDmaBufUsageKb(); if (gpuDmaBufUsage >= 0) { final long gpuPrivateUsage = gpuUsage - gpuDmaBufUsage; pw.print(" GPU: "); pw.print(stringifyKBSize(gpuUsage)); pw.print(" ("); pw.print(stringifyKBSize(gpuDmaBufUsage)); pw.print(" dmabuf + "); pw.print(stringifyKBSize(gpuPrivateUsage)); pw.println(" private)"); // Replace memtrack HAL reported GL category with private GPU allocations and // account it as part of kernel memory allocations ss[INDEX_TOTAL_PSS] -= ss[INDEX_TOTAL_MEMTRACK_GL]; kernelUsed += gpuPrivateUsage; } else { pw.print(" GPU: "); pw.println(stringifyKBSize(gpuUsage)); } } /* * Note: ION/DMA-BUF heap pools are reclaimable and hence, they are included as part of * memInfo.getCachedSizeKb(). */ // Note: ION/DMA-BUF heap pools are reclaimable and hence, they are included as part of // memInfo.getCachedSizeKb(). final long lostRAM = memInfo.getTotalSizeKb() - (ss[INDEX_TOTAL_PSS] - ss[INDEX_TOTAL_SWAP_PSS]) - memInfo.getFreeSizeKb() - memInfo.getCachedSizeKb() Loading services/core/java/com/android/server/am/AppProfiler.java +34 −9 Original line number Diff line number Diff line Loading @@ -1322,7 +1322,7 @@ public class AppProfiler { infoMap.put(mi.pid, mi); } updateCpuStatsNow(); long[] memtrackTmp = new long[1]; long[] memtrackTmp = new long[4]; long[] swaptrackTmp = new long[2]; // Get a list of Stats that have vsize > 0 final List<ProcessCpuTracker.Stats> stats = getCpuStats(st -> st.vsize > 0); Loading @@ -1345,6 +1345,8 @@ public class AppProfiler { long totalPss = 0; long totalSwapPss = 0; long totalMemtrack = 0; long totalMemtrackGraphics = 0; long totalMemtrackGl = 0; for (int i = 0, size = memInfos.size(); i < size; i++) { ProcessMemInfo mi = memInfos.get(i); if (mi.pss == 0) { Loading @@ -1355,6 +1357,8 @@ public class AppProfiler { totalPss += mi.pss; totalSwapPss += mi.swapPss; totalMemtrack += mi.memtrack; totalMemtrackGraphics += memtrackTmp[1]; totalMemtrackGl += memtrackTmp[2]; } Collections.sort(memInfos, new Comparator<ProcessMemInfo>() { @Override public int compare(ProcessMemInfo lhs, ProcessMemInfo rhs) { Loading Loading @@ -1521,10 +1525,16 @@ public class AppProfiler { } else { final long totalExportedDmabuf = Debug.getDmabufTotalExportedKb(); if (totalExportedDmabuf >= 0) { final long dmabufMapped = Debug.getDmabufMappedSizeKb(); final long dmabufUnmapped = totalExportedDmabuf - dmabufMapped; memInfoBuilder.append("DMA-BUF: "); memInfoBuilder.append(stringifyKBSize(totalExportedDmabuf)); memInfoBuilder.append("\n"); kernelUsed += totalExportedDmabuf; // Account unmapped dmabufs as part of kernel memory allocations kernelUsed += dmabufUnmapped; // Replace memtrack HAL reported Graphics category with mapped dmabufs totalPss -= totalMemtrackGraphics; totalPss += dmabufMapped; } final long totalDmabufHeapPool = Debug.getDmabufHeapPoolsSizeKb(); Loading @@ -1537,19 +1547,34 @@ public class AppProfiler { final long gpuUsage = Debug.getGpuTotalUsageKb(); if (gpuUsage >= 0) { final long gpuDmaBufUsage = Debug.getGpuDmaBufUsageKb(); if (gpuDmaBufUsage >= 0) { final long gpuPrivateUsage = gpuUsage - gpuDmaBufUsage; memInfoBuilder.append(" GPU: "); memInfoBuilder.append(stringifyKBSize(gpuUsage)); memInfoBuilder.append(" ("); memInfoBuilder.append(stringifyKBSize(gpuDmaBufUsage)); memInfoBuilder.append(" dmabuf + "); memInfoBuilder.append(stringifyKBSize(gpuPrivateUsage)); memInfoBuilder.append(" private)\n"); // Replace memtrack HAL reported GL category with private GPU allocations and // account it as part of kernel memory allocations totalPss -= totalMemtrackGl; kernelUsed += gpuPrivateUsage; } else { memInfoBuilder.append(" GPU: "); memInfoBuilder.append(stringifyKBSize(gpuUsage)); memInfoBuilder.append("\n"); } } memInfoBuilder.append(" Used RAM: "); memInfoBuilder.append(stringifyKBSize( totalPss - cachedPss + kernelUsed)); memInfoBuilder.append("\n"); /* * Note: ION/DMA-BUF heap pools are reclaimable and hence, they are included as part of * memInfo.getCachedSizeKb(). */ // Note: ION/DMA-BUF heap pools are reclaimable and hence, they are included as part of // memInfo.getCachedSizeKb(). memInfoBuilder.append(" Lost RAM: "); memInfoBuilder.append(stringifyKBSize(memInfo.getTotalSizeKb() - (totalPss - totalSwapPss) - memInfo.getFreeSizeKb() - memInfo.getCachedSizeKb() Loading Loading
core/java/android/os/Debug.java +7 −0 Original line number Diff line number Diff line Loading @@ -2589,6 +2589,13 @@ public final class Debug */ public static native long getIonPoolsSizeKb(); /** * Return GPU DMA buffer usage in kB or -1 on error. * * @hide */ public static native long getGpuDmaBufUsageKb(); /** * Return DMA-BUF memory mapped by processes in kB. * Notes: Loading
core/jni/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -207,6 +207,7 @@ cc_library_shared { ], shared_libs: [ "android.hardware.memtrack-unstable-ndk_platform", "audioclient-types-aidl-cpp", "audioflinger-aidl-cpp", "av-types-aidl-cpp", Loading
core/jni/android_os_Debug.cpp +29 −0 Original line number Diff line number Diff line Loading @@ -33,6 +33,7 @@ #include <string> #include <vector> #include <aidl/android/hardware/memtrack/DeviceInfo.h> #include <android-base/logging.h> #include <bionic/malloc.h> #include <debuggerd/client.h> Loading @@ -45,6 +46,7 @@ #include "jni.h" #include <dmabufinfo/dmabuf_sysfs_stats.h> #include <dmabufinfo/dmabufinfo.h> #include <dmabufinfo/dmabuf_sysfs_stats.h> #include <meminfo/procmeminfo.h> #include <meminfo/sysmeminfo.h> #include <memtrack/memtrack.h> Loading Loading @@ -849,6 +851,31 @@ static jlong android_os_Debug_getDmabufHeapPoolsSizeKb(JNIEnv* env, jobject claz return poolsSizeKb; } static jlong android_os_Debug_getGpuDmaBufUsageKb(JNIEnv* env, jobject clazz) { std::vector<aidl::android::hardware::memtrack::DeviceInfo> gpu_device_info; if (!memtrack_gpu_device_info(&gpu_device_info)) { return -1; } dmabufinfo::DmabufSysfsStats stats; if (!GetDmabufSysfsStats(&stats)) { return -1; } jlong sizeKb = 0; const auto& importer_stats = stats.importer_info(); for (const auto& dev_info : gpu_device_info) { const auto& importer_info = importer_stats.find(dev_info.name); if (importer_info == importer_stats.end()) { continue; } sizeKb += importer_info->second.size; } return sizeKb; } static jlong android_os_Debug_getDmabufMappedSizeKb(JNIEnv* env, jobject clazz) { jlong dmabufPss = 0; std::vector<dmabufinfo::DmaBuffer> dmabufs; Loading Loading @@ -957,6 +984,8 @@ static const JNINativeMethod gMethods[] = { (void*)android_os_Debug_getIonHeapsSizeKb }, { "getDmabufTotalExportedKb", "()J", (void*)android_os_Debug_getDmabufTotalExportedKb }, { "getGpuDmaBufUsageKb", "()J", (void*)android_os_Debug_getGpuDmaBufUsageKb }, { "getIonPoolsSizeKb", "()J", (void*)android_os_Debug_getIonPoolsSizeKb }, { "getDmabufMappedSizeKb", "()J", Loading
services/core/java/com/android/server/am/ActivityManagerService.java +42 −9 Original line number Diff line number Diff line Loading @@ -1490,7 +1490,9 @@ public class ActivityManagerService extends IActivityManager.Stub private static final int INDEX_TOTAL_SWAP_PSS = 10; private static final int INDEX_TOTAL_RSS = 11; private static final int INDEX_TOTAL_NATIVE_PSS = 12; private static final int INDEX_LAST = 13; private static final int INDEX_TOTAL_MEMTRACK_GRAPHICS = 13; private static final int INDEX_TOTAL_MEMTRACK_GL = 14; private static final int INDEX_LAST = 15; final class UiHandler extends Handler { public UiHandler() { Loading Loading @@ -10316,6 +10318,7 @@ public class ActivityManagerService extends IActivityManager.Stub long[] miscPss = new long[Debug.MemoryInfo.NUM_OTHER_STATS]; long[] miscSwapPss = new long[Debug.MemoryInfo.NUM_OTHER_STATS]; long[] miscRss = new long[Debug.MemoryInfo.NUM_OTHER_STATS]; long[] memtrackTmp = new long[4]; long oomPss[] = new long[DUMP_MEM_OOM_LABEL.length]; long oomSwapPss[] = new long[DUMP_MEM_OOM_LABEL.length]; Loading Loading @@ -10349,6 +10352,8 @@ public class ActivityManagerService extends IActivityManager.Stub final int reportType; final long startTime; final long endTime; long memtrackGraphics = 0; long memtrackGl = 0; if (opts.dumpDetails || (!brief && !opts.oomOnly)) { reportType = ProcessStats.ADD_PSS_EXTERNAL_SLOW; startTime = SystemClock.currentThreadTimeMillis(); Loading @@ -10360,7 +10365,7 @@ public class ActivityManagerService extends IActivityManager.Stub } else { reportType = ProcessStats.ADD_PSS_EXTERNAL; startTime = SystemClock.currentThreadTimeMillis(); long pss = Debug.getPss(pid, tmpLong, null); long pss = Debug.getPss(pid, tmpLong, memtrackTmp); if (pss == 0) { continue; } Loading @@ -10368,6 +10373,8 @@ public class ActivityManagerService extends IActivityManager.Stub endTime = SystemClock.currentThreadTimeMillis(); mi.dalvikPrivateDirty = (int) tmpLong[0]; mi.dalvikRss = (int) tmpLong[2]; memtrackGraphics = memtrackTmp[1]; memtrackGl = memtrackTmp[2]; } if (!opts.isCheckinRequest && opts.dumpDetails) { pw.println("\n** MEMINFO in pid " + pid + " [" + r.processName + "] **"); Loading Loading @@ -10431,6 +10438,8 @@ public class ActivityManagerService extends IActivityManager.Stub ss[INDEX_TOTAL_PSS] += myTotalPss; ss[INDEX_TOTAL_SWAP_PSS] += myTotalSwapPss; ss[INDEX_TOTAL_RSS] += myTotalRss; ss[INDEX_TOTAL_MEMTRACK_GRAPHICS] += memtrackGraphics; ss[INDEX_TOTAL_MEMTRACK_GL] += memtrackGl; MemItem pssItem = new MemItem(r.processName + " (pid " + pid + (hasActivities ? " / activities)" : ")"), r.processName, myTotalPss, myTotalSwapPss, myTotalRss, pid, hasActivities); Loading Loading @@ -10494,6 +10503,8 @@ public class ActivityManagerService extends IActivityManager.Stub final Debug.MemoryInfo[] memInfos = new Debug.MemoryInfo[1]; mAppProfiler.forAllCpuStats((st) -> { if (st.vsize > 0 && procMemsMap.indexOfKey(st.pid) < 0) { long memtrackGraphics = 0; long memtrackGl = 0; if (memInfos[0] == null) { memInfos[0] = new Debug.MemoryInfo(); } Loading @@ -10503,13 +10514,15 @@ public class ActivityManagerService extends IActivityManager.Stub return; } } else { long pss = Debug.getPss(st.pid, tmpLong, null); long pss = Debug.getPss(st.pid, tmpLong, memtrackTmp); if (pss == 0) { return; } info.nativePss = (int) pss; info.nativePrivateDirty = (int) tmpLong[0]; info.nativeRss = (int) tmpLong[2]; memtrackGraphics = memtrackTmp[1]; memtrackGl = memtrackTmp[2]; } final long myTotalPss = info.getTotalPss(); Loading @@ -10519,6 +10532,8 @@ public class ActivityManagerService extends IActivityManager.Stub ss[INDEX_TOTAL_SWAP_PSS] += myTotalSwapPss; ss[INDEX_TOTAL_RSS] += myTotalRss; ss[INDEX_TOTAL_NATIVE_PSS] += myTotalPss; ss[INDEX_TOTAL_MEMTRACK_GRAPHICS] += memtrackGraphics; ss[INDEX_TOTAL_MEMTRACK_GL] += memtrackGl; MemItem pssItem = new MemItem(st.name + " (pid " + st.pid + ")", st.name, myTotalPss, info.getSummaryTotalSwapPss(), myTotalRss, Loading Loading @@ -10726,7 +10741,11 @@ public class ActivityManagerService extends IActivityManager.Stub pw.print(" mapped + "); pw.print(stringifyKBSize(dmabufUnmapped)); pw.println(" unmapped)"); kernelUsed += totalExportedDmabuf; // Account unmapped dmabufs as part of kernel memory allocations kernelUsed += dmabufUnmapped; // Replace memtrack HAL reported Graphics category with mapped dmabufs ss[INDEX_TOTAL_PSS] -= ss[INDEX_TOTAL_MEMTRACK_GRAPHICS]; ss[INDEX_TOTAL_PSS] += dmabufMapped; } final long totalDmabufHeapPool = Debug.getDmabufHeapPoolsSizeKb(); if (totalDmabufHeapPool >= 0) { Loading @@ -10736,13 +10755,27 @@ public class ActivityManagerService extends IActivityManager.Stub } final long gpuUsage = Debug.getGpuTotalUsageKb(); if (gpuUsage >= 0) { final long gpuDmaBufUsage = Debug.getGpuDmaBufUsageKb(); if (gpuDmaBufUsage >= 0) { final long gpuPrivateUsage = gpuUsage - gpuDmaBufUsage; pw.print(" GPU: "); pw.print(stringifyKBSize(gpuUsage)); pw.print(" ("); pw.print(stringifyKBSize(gpuDmaBufUsage)); pw.print(" dmabuf + "); pw.print(stringifyKBSize(gpuPrivateUsage)); pw.println(" private)"); // Replace memtrack HAL reported GL category with private GPU allocations and // account it as part of kernel memory allocations ss[INDEX_TOTAL_PSS] -= ss[INDEX_TOTAL_MEMTRACK_GL]; kernelUsed += gpuPrivateUsage; } else { pw.print(" GPU: "); pw.println(stringifyKBSize(gpuUsage)); } } /* * Note: ION/DMA-BUF heap pools are reclaimable and hence, they are included as part of * memInfo.getCachedSizeKb(). */ // Note: ION/DMA-BUF heap pools are reclaimable and hence, they are included as part of // memInfo.getCachedSizeKb(). final long lostRAM = memInfo.getTotalSizeKb() - (ss[INDEX_TOTAL_PSS] - ss[INDEX_TOTAL_SWAP_PSS]) - memInfo.getFreeSizeKb() - memInfo.getCachedSizeKb() Loading
services/core/java/com/android/server/am/AppProfiler.java +34 −9 Original line number Diff line number Diff line Loading @@ -1322,7 +1322,7 @@ public class AppProfiler { infoMap.put(mi.pid, mi); } updateCpuStatsNow(); long[] memtrackTmp = new long[1]; long[] memtrackTmp = new long[4]; long[] swaptrackTmp = new long[2]; // Get a list of Stats that have vsize > 0 final List<ProcessCpuTracker.Stats> stats = getCpuStats(st -> st.vsize > 0); Loading @@ -1345,6 +1345,8 @@ public class AppProfiler { long totalPss = 0; long totalSwapPss = 0; long totalMemtrack = 0; long totalMemtrackGraphics = 0; long totalMemtrackGl = 0; for (int i = 0, size = memInfos.size(); i < size; i++) { ProcessMemInfo mi = memInfos.get(i); if (mi.pss == 0) { Loading @@ -1355,6 +1357,8 @@ public class AppProfiler { totalPss += mi.pss; totalSwapPss += mi.swapPss; totalMemtrack += mi.memtrack; totalMemtrackGraphics += memtrackTmp[1]; totalMemtrackGl += memtrackTmp[2]; } Collections.sort(memInfos, new Comparator<ProcessMemInfo>() { @Override public int compare(ProcessMemInfo lhs, ProcessMemInfo rhs) { Loading Loading @@ -1521,10 +1525,16 @@ public class AppProfiler { } else { final long totalExportedDmabuf = Debug.getDmabufTotalExportedKb(); if (totalExportedDmabuf >= 0) { final long dmabufMapped = Debug.getDmabufMappedSizeKb(); final long dmabufUnmapped = totalExportedDmabuf - dmabufMapped; memInfoBuilder.append("DMA-BUF: "); memInfoBuilder.append(stringifyKBSize(totalExportedDmabuf)); memInfoBuilder.append("\n"); kernelUsed += totalExportedDmabuf; // Account unmapped dmabufs as part of kernel memory allocations kernelUsed += dmabufUnmapped; // Replace memtrack HAL reported Graphics category with mapped dmabufs totalPss -= totalMemtrackGraphics; totalPss += dmabufMapped; } final long totalDmabufHeapPool = Debug.getDmabufHeapPoolsSizeKb(); Loading @@ -1537,19 +1547,34 @@ public class AppProfiler { final long gpuUsage = Debug.getGpuTotalUsageKb(); if (gpuUsage >= 0) { final long gpuDmaBufUsage = Debug.getGpuDmaBufUsageKb(); if (gpuDmaBufUsage >= 0) { final long gpuPrivateUsage = gpuUsage - gpuDmaBufUsage; memInfoBuilder.append(" GPU: "); memInfoBuilder.append(stringifyKBSize(gpuUsage)); memInfoBuilder.append(" ("); memInfoBuilder.append(stringifyKBSize(gpuDmaBufUsage)); memInfoBuilder.append(" dmabuf + "); memInfoBuilder.append(stringifyKBSize(gpuPrivateUsage)); memInfoBuilder.append(" private)\n"); // Replace memtrack HAL reported GL category with private GPU allocations and // account it as part of kernel memory allocations totalPss -= totalMemtrackGl; kernelUsed += gpuPrivateUsage; } else { memInfoBuilder.append(" GPU: "); memInfoBuilder.append(stringifyKBSize(gpuUsage)); memInfoBuilder.append("\n"); } } memInfoBuilder.append(" Used RAM: "); memInfoBuilder.append(stringifyKBSize( totalPss - cachedPss + kernelUsed)); memInfoBuilder.append("\n"); /* * Note: ION/DMA-BUF heap pools are reclaimable and hence, they are included as part of * memInfo.getCachedSizeKb(). */ // Note: ION/DMA-BUF heap pools are reclaimable and hence, they are included as part of // memInfo.getCachedSizeKb(). memInfoBuilder.append(" Lost RAM: "); memInfoBuilder.append(stringifyKBSize(memInfo.getTotalSizeKb() - (totalPss - totalSwapPss) - memInfo.getFreeSizeKb() - memInfo.getCachedSizeKb() Loading