Add RSS high-water mark in kilobytes
The new field will be used to reduce the upload size of RSS HWM metric.
Single int32 instead of int64.
Keep both fields populated on device for backwards compatibility.
Bug: 139269772
Test: atest MemoryStatUtilTest
Change-Id: Iea850a0baceabe07586147955fcfd11c46f8ac30
diff --git a/cmds/statsd/src/atoms.proto b/cmds/statsd/src/atoms.proto
index ae751ce..fe3c3d5 100644
--- a/cmds/statsd/src/atoms.proto
+++ b/cmds/statsd/src/atoms.proto
@@ -4094,9 +4094,13 @@
// Provided by ActivityManagerService or read from /proc/PID/cmdline.
optional string process_name = 2;
+ // Deprecated: use rss_high_water_mark_in_kilobytes instead. This field is
+ // computed by converting kilobytes to bytes.
+ optional int64 rss_high_water_mark_in_bytes = 3 [deprecated = true];
+
// RSS high-water mark. Peak RSS usage of the process. Read from the VmHWM field in
// /proc/PID/status.
- optional int64 rss_high_water_mark_in_bytes = 3;
+ optional int32 rss_high_water_mark_in_kilobytes = 4;
}
/*
diff --git a/services/core/java/com/android/server/am/MemoryStatUtil.java b/services/core/java/com/android/server/am/MemoryStatUtil.java
index 95eb2c69..6666cf4 100644
--- a/services/core/java/com/android/server/am/MemoryStatUtil.java
+++ b/services/core/java/com/android/server/am/MemoryStatUtil.java
@@ -126,9 +126,9 @@
/**
* Reads RSS high-water mark of a process from procfs. Returns value of the VmHWM field in
- * /proc/PID/status in bytes or 0 if not available.
+ * /proc/PID/status in kilobytes or 0 if not available.
*/
- public static long readRssHighWaterMarkFromProcfs(int pid) {
+ public static int readRssHighWaterMarkFromProcfs(int pid) {
final String statusPath = String.format(Locale.US, PROC_STATUS_FILE_FMT, pid);
return parseVmHWMFromProcfs(readFileContents(statusPath));
}
@@ -236,17 +236,15 @@
}
/**
- * Parses RSS high watermark out from the contents of the /proc/pid/status file in procfs. The
- * returned value is in bytes.
+ * Parses RSS high-water mark out from the contents of the /proc/pid/status file in procfs. The
+ * returned value is in kilobytes.
*/
@VisibleForTesting
- static long parseVmHWMFromProcfs(String procStatusContents) {
+ static int parseVmHWMFromProcfs(String procStatusContents) {
if (procStatusContents == null || procStatusContents.isEmpty()) {
return 0;
}
- // Convert value read from /proc/pid/status from kilobytes to bytes.
- return tryParseLong(RSS_HIGH_WATERMARK_IN_KILOBYTES, procStatusContents)
- * BYTES_IN_KILOBYTE;
+ return (int) tryParseLong(RSS_HIGH_WATERMARK_IN_KILOBYTES, procStatusContents);
}
diff --git a/services/core/java/com/android/server/stats/StatsCompanionService.java b/services/core/java/com/android/server/stats/StatsCompanionService.java
index c76bbb0..e176480 100644
--- a/services/core/java/com/android/server/stats/StatsCompanionService.java
+++ b/services/core/java/com/android/server/stats/StatsCompanionService.java
@@ -1237,15 +1237,17 @@
LocalServices.getService(
ActivityManagerInternal.class).getMemoryStateForProcesses();
for (ProcessMemoryState managedProcess : managedProcessList) {
- final long rssHighWaterMarkInBytes =
+ final int rssHighWaterMarkInKilobytes =
readRssHighWaterMarkFromProcfs(managedProcess.pid);
- if (rssHighWaterMarkInBytes == 0) {
+ if (rssHighWaterMarkInKilobytes == 0) {
continue;
}
StatsLogEventWrapper e = new StatsLogEventWrapper(tagId, elapsedNanos, wallClockNanos);
e.writeInt(managedProcess.uid);
e.writeString(managedProcess.processName);
- e.writeLong(rssHighWaterMarkInBytes);
+ // RSS high-water mark in bytes.
+ e.writeLong((long) rssHighWaterMarkInKilobytes * 1024L);
+ e.writeInt(rssHighWaterMarkInKilobytes);
pulledData.add(e);
}
int[] pids = getPidsForCommands(MEMORY_INTERESTING_NATIVE_PROCESSES);
@@ -1253,11 +1255,16 @@
final int pid = pids[i];
final int uid = getUidForPid(pid);
final String processName = readCmdlineFromProcfs(pid);
- final long rssHighWaterMarkInBytes = readRssHighWaterMarkFromProcfs(pid);
+ final int rssHighWaterMarkInKilobytes = readRssHighWaterMarkFromProcfs(pid);
+ if (rssHighWaterMarkInKilobytes == 0) {
+ continue;
+ }
StatsLogEventWrapper e = new StatsLogEventWrapper(tagId, elapsedNanos, wallClockNanos);
e.writeInt(uid);
e.writeString(processName);
- e.writeLong(rssHighWaterMarkInBytes);
+ // RSS high-water mark in bytes.
+ e.writeLong((long) rssHighWaterMarkInKilobytes * 1024L);
+ e.writeInt(rssHighWaterMarkInKilobytes);
pulledData.add(e);
}
// Invoke rss_hwm_reset binary to reset RSS HWM counters for all processes.
diff --git a/services/tests/servicestests/src/com/android/server/am/MemoryStatUtilTest.java b/services/tests/servicestests/src/com/android/server/am/MemoryStatUtilTest.java
index 6678a78..5ab44a8 100644
--- a/services/tests/servicestests/src/com/android/server/am/MemoryStatUtilTest.java
+++ b/services/tests/servicestests/src/com/android/server/am/MemoryStatUtilTest.java
@@ -302,7 +302,7 @@
@Test
public void testParseVmHWMFromProcfs_parsesCorrectValue() {
- assertEquals(137668, parseVmHWMFromProcfs(PROC_STATUS_CONTENTS) / BYTES_IN_KILOBYTE);
+ assertEquals(137668, parseVmHWMFromProcfs(PROC_STATUS_CONTENTS));
}
@Test