Add VmStat atom and read the count of OOM kills

We want to understand how frequently the OOM killer is invoked in our
droidfood / prod fleets. To do so, introduce a /proc/vmstat reading atom
which we can subsequently use as a ValueMetric to count number of OOM
kills per session.

Bug: 154233512
Test: atest VmStatTests
Change-Id: I58ad126aa691c4ee1c61468e4c5ff5331649791c
This commit is contained in:
Ioannis Ilkos
2021-06-08 14:01:10 +01:00
parent 7dfe7b74a7
commit a20c33866a
2 changed files with 45 additions and 0 deletions

View File

@@ -30,6 +30,9 @@ public final class ProcfsMemoryUtil {
"RssAnon:",
"VmSwap:"
};
private static final String[] VMSTAT_KEYS = new String[] {
"oom_kill"
};
private ProcfsMemoryUtil() {}
@@ -99,4 +102,22 @@ public final class ProcfsMemoryUtil {
public int anonRssInKilobytes;
public int swapInKilobytes;
}
/** Reads and parses selected entries of /proc/vmstat. */
@Nullable
static VmStat readVmStat() {
long[] vmstat = new long[VMSTAT_KEYS.length];
vmstat[0] = -1;
Process.readProcLines("/proc/vmstat", VMSTAT_KEYS, vmstat);
if (vmstat[0] == -1) {
return null;
}
VmStat result = new VmStat();
result.oomKillCount = (int) vmstat[0];
return result;
}
static final class VmStat {
public int oomKillCount;
}
}

View File

@@ -544,6 +544,8 @@ public class StatsPullAtomService extends SystemService {
return pullProcessDmabufMemory(atomTag, data);
case FrameworkStatsLog.SYSTEM_MEMORY:
return pullSystemMemory(atomTag, data);
case FrameworkStatsLog.VMSTAT:
return pullVmStat(atomTag, data);
case FrameworkStatsLog.TEMPERATURE:
synchronized (mTemperatureLock) {
return pullTemperatureLocked(atomTag, data);
@@ -842,6 +844,7 @@ public class StatsPullAtomService extends SystemService {
registerProcessSystemIonHeapSize();
registerSystemMemory();
registerProcessDmabufMemory();
registerVmStat();
registerTemperature();
registerCoolingDevice();
registerBinderCallsStats();
@@ -2273,6 +2276,27 @@ public class StatsPullAtomService extends SystemService {
return StatsManager.PULL_SUCCESS;
}
private void registerVmStat() {
int tagId = FrameworkStatsLog.VMSTAT;
mStatsManager.setPullAtomCallback(
tagId,
null, // use default PullAtomMetadata values
DIRECT_EXECUTOR,
mStatsCallbackImpl
);
}
int pullVmStat(int atomTag, List<StatsEvent> pulledData) {
ProcfsMemoryUtil.VmStat vmStat = ProcfsMemoryUtil.readVmStat();
if (vmStat != null) {
pulledData.add(
FrameworkStatsLog.buildStatsEvent(
atomTag,
vmStat.oomKillCount));
}
return StatsManager.PULL_SUCCESS;
}
private void registerTemperature() {
int tagId = FrameworkStatsLog.TEMPERATURE;
mStatsManager.setPullAtomCallback(