Merge changes I631488d9,Ie72f46c8 into sc-dev
* changes: Eliminate memtrack variability from the lost RAM calculation Provide an interface to query dmabuf GPU allocations
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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>
|
||||
@@ -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>
|
||||
@@ -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;
|
||||
@@ -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",
|
||||
|
||||
@@ -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() {
|
||||
@@ -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];
|
||||
@@ -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();
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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 + "] **");
|
||||
@@ -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);
|
||||
@@ -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();
|
||||
}
|
||||
@@ -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();
|
||||
@@ -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,
|
||||
@@ -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) {
|
||||
@@ -10736,13 +10755,27 @@ public class ActivityManagerService extends IActivityManager.Stub
|
||||
}
|
||||
final long gpuUsage = Debug.getGpuTotalUsageKb();
|
||||
if (gpuUsage >= 0) {
|
||||
pw.print(" GPU: "); pw.println(stringifyKBSize(gpuUsage));
|
||||
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()
|
||||
|
||||
@@ -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);
|
||||
@@ -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) {
|
||||
@@ -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) {
|
||||
@@ -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();
|
||||
@@ -1537,19 +1547,34 @@ public class AppProfiler {
|
||||
|
||||
final long gpuUsage = Debug.getGpuTotalUsageKb();
|
||||
if (gpuUsage >= 0) {
|
||||
memInfoBuilder.append(" GPU: ");
|
||||
memInfoBuilder.append(stringifyKBSize(gpuUsage));
|
||||
memInfoBuilder.append("\n");
|
||||
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()
|
||||
|
||||
Reference in New Issue
Block a user