From 8ac40038582992b73a2e60c0a9a46f2680e78639 Mon Sep 17 00:00:00 2001 From: Rafal Slawik Date: Wed, 15 Apr 2020 16:07:00 +0100 Subject: [PATCH] Check if RssAnon and swap were read Keep memory snapshots even if anon RSS and swap are both 0 as long as the values were read correctly. These should happen rarely and statsd can be configured to ignore atoms with zeros. Bug: 145755384 Test: atest UidAtomTests#testProcessMemorySnapshot Change-Id: I0ab13be008c48113f80269af4f815d807096b938 --- .../com/android/server/stats/pull/ProcfsMemoryUtil.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/services/core/java/com/android/server/stats/pull/ProcfsMemoryUtil.java b/services/core/java/com/android/server/stats/pull/ProcfsMemoryUtil.java index 67677c6cf17e2..e1e6195ad2602 100644 --- a/services/core/java/com/android/server/stats/pull/ProcfsMemoryUtil.java +++ b/services/core/java/com/android/server/stats/pull/ProcfsMemoryUtil.java @@ -41,10 +41,11 @@ public final class ProcfsMemoryUtil { public static MemorySnapshot readMemorySnapshotFromProcfs(int pid) { long[] output = new long[STATUS_KEYS.length]; output[0] = -1; + output[3] = -1; + output[4] = -1; Process.readProcLines("/proc/" + pid + "/status", STATUS_KEYS, output); - if (output[0] == -1 || (output[3] == 0 && output[4] == 0)) { - // Could not open file or anon rss / swap are 0 indicating the process is in a zombie - // state. + if (output[0] == -1 || output[3] == -1 || output[4] == -1) { + // Could not open or parse file. return null; } final MemorySnapshot snapshot = new MemorySnapshot();