Merge "Add RSS high-water mark in kilobytes"

This commit is contained in:
TreeHugger Robot
2019-09-11 12:32:01 +00:00
committed by Android (Google) Code Review
4 changed files with 24 additions and 15 deletions

View File

@@ -4094,9 +4094,13 @@ message ProcessMemoryHighWaterMark {
// 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;
}
/*

View File

@@ -126,9 +126,9 @@ public final class MemoryStatUtil {
/**
* 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 @@ public final class MemoryStatUtil {
}
/**
* 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);
}

View File

@@ -1237,15 +1237,17 @@ public class StatsCompanionService extends IStatsCompanionService.Stub {
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 @@ public class StatsCompanionService extends IStatsCompanionService.Stub {
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.

View File

@@ -302,7 +302,7 @@ public class MemoryStatUtilTest {
@Test
public void testParseVmHWMFromProcfs_parsesCorrectValue() {
assertEquals(137668, parseVmHWMFromProcfs(PROC_STATUS_CONTENTS) / BYTES_IN_KILOBYTE);
assertEquals(137668, parseVmHWMFromProcfs(PROC_STATUS_CONTENTS));
}
@Test