Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 84aa7299 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Add RSS high-water mark in kilobytes"

parents b4323c69 239b680a
Loading
Loading
Loading
Loading
+5 −1
Original line number Original line Diff line number Diff line
@@ -4094,9 +4094,13 @@ message ProcessMemoryHighWaterMark {
    // Provided by ActivityManagerService or read from /proc/PID/cmdline.
    // Provided by ActivityManagerService or read from /proc/PID/cmdline.
    optional string process_name = 2;
    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
    // RSS high-water mark. Peak RSS usage of the process. Read from the VmHWM field in
    // /proc/PID/status.
    // /proc/PID/status.
    optional int64 rss_high_water_mark_in_bytes = 3;
    optional int32 rss_high_water_mark_in_kilobytes = 4;
}
}


/*
/*
+6 −8
Original line number Original line Diff line number Diff line
@@ -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
     * 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);
        final String statusPath = String.format(Locale.US, PROC_STATUS_FILE_FMT, pid);
        return parseVmHWMFromProcfs(readFileContents(statusPath));
        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
     * Parses RSS high-water mark out from the contents of the /proc/pid/status file in procfs. The
     * returned value is in bytes.
     * returned value is in kilobytes.
     */
     */
    @VisibleForTesting
    @VisibleForTesting
    static long parseVmHWMFromProcfs(String procStatusContents) {
    static int parseVmHWMFromProcfs(String procStatusContents) {
        if (procStatusContents == null || procStatusContents.isEmpty()) {
        if (procStatusContents == null || procStatusContents.isEmpty()) {
            return 0;
            return 0;
        }
        }
        // Convert value read from /proc/pid/status from kilobytes to bytes.
        return (int) tryParseLong(RSS_HIGH_WATERMARK_IN_KILOBYTES, procStatusContents);
        return tryParseLong(RSS_HIGH_WATERMARK_IN_KILOBYTES, procStatusContents)
                * BYTES_IN_KILOBYTE;
    }
    }




+12 −5
Original line number Original line Diff line number Diff line
@@ -1237,15 +1237,17 @@ public class StatsCompanionService extends IStatsCompanionService.Stub {
                LocalServices.getService(
                LocalServices.getService(
                        ActivityManagerInternal.class).getMemoryStateForProcesses();
                        ActivityManagerInternal.class).getMemoryStateForProcesses();
        for (ProcessMemoryState managedProcess : managedProcessList) {
        for (ProcessMemoryState managedProcess : managedProcessList) {
            final long rssHighWaterMarkInBytes =
            final int rssHighWaterMarkInKilobytes =
                    readRssHighWaterMarkFromProcfs(managedProcess.pid);
                    readRssHighWaterMarkFromProcfs(managedProcess.pid);
            if (rssHighWaterMarkInBytes == 0) {
            if (rssHighWaterMarkInKilobytes == 0) {
                continue;
                continue;
            }
            }
            StatsLogEventWrapper e = new StatsLogEventWrapper(tagId, elapsedNanos, wallClockNanos);
            StatsLogEventWrapper e = new StatsLogEventWrapper(tagId, elapsedNanos, wallClockNanos);
            e.writeInt(managedProcess.uid);
            e.writeInt(managedProcess.uid);
            e.writeString(managedProcess.processName);
            e.writeString(managedProcess.processName);
            e.writeLong(rssHighWaterMarkInBytes);
            // RSS high-water mark in bytes.
            e.writeLong((long) rssHighWaterMarkInKilobytes * 1024L);
            e.writeInt(rssHighWaterMarkInKilobytes);
            pulledData.add(e);
            pulledData.add(e);
        }
        }
        int[] pids = getPidsForCommands(MEMORY_INTERESTING_NATIVE_PROCESSES);
        int[] pids = getPidsForCommands(MEMORY_INTERESTING_NATIVE_PROCESSES);
@@ -1253,11 +1255,16 @@ public class StatsCompanionService extends IStatsCompanionService.Stub {
            final int pid = pids[i];
            final int pid = pids[i];
            final int uid = getUidForPid(pid);
            final int uid = getUidForPid(pid);
            final String processName = readCmdlineFromProcfs(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);
            StatsLogEventWrapper e = new StatsLogEventWrapper(tagId, elapsedNanos, wallClockNanos);
            e.writeInt(uid);
            e.writeInt(uid);
            e.writeString(processName);
            e.writeString(processName);
            e.writeLong(rssHighWaterMarkInBytes);
            // RSS high-water mark in bytes.
            e.writeLong((long) rssHighWaterMarkInKilobytes * 1024L);
            e.writeInt(rssHighWaterMarkInKilobytes);
            pulledData.add(e);
            pulledData.add(e);
        }
        }
        // Invoke rss_hwm_reset binary to reset RSS HWM counters for all processes.
        // Invoke rss_hwm_reset binary to reset RSS HWM counters for all processes.
+1 −1
Original line number Original line Diff line number Diff line
@@ -302,7 +302,7 @@ public class MemoryStatUtilTest {


    @Test
    @Test
    public void testParseVmHWMFromProcfs_parsesCorrectValue() {
    public void testParseVmHWMFromProcfs_parsesCorrectValue() {
        assertEquals(137668, parseVmHWMFromProcfs(PROC_STATUS_CONTENTS) / BYTES_IN_KILOBYTE);
        assertEquals(137668, parseVmHWMFromProcfs(PROC_STATUS_CONTENTS));
    }
    }


    @Test
    @Test