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

Commit 62be42df authored by Hui Yu's avatar Hui Yu
Browse files

Set number of foreground services in statsd atom LmkKillOccurred.

Bug: 234618899
Test: statsd_testdrive 51
Change-Id: Ie98f72c61e05bd9a0322390faecc2ee3abdcc5ee
Merged-In: Ie98f72c61e05bd9a0322390faecc2ee3abdcc5ee
parent 9d16d9da
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -50,7 +50,8 @@ public final class LmkdStatsReporter {
     * Logs the event when LMKD kills a process to reduce memory pressure.
     * Code: LMK_KILL_OCCURRED = 51
     */
    public static void logKillOccurred(DataInputStream inputData) {
    public static void logKillOccurred(DataInputStream inputData, int totalForegroundServices,
            int procsWithForegroundServices) {
        try {
            final long pgFault = inputData.readLong();
            final long pgMajFault = inputData.readLong();
@@ -67,11 +68,10 @@ public final class LmkdStatsReporter {
            final int thrashing = inputData.readInt();
            final int maxThrashing = inputData.readInt();
            final String procName = inputData.readUTF();

            FrameworkStatsLog.write(FrameworkStatsLog.LMK_KILL_OCCURRED, uid, procName, oomScore,
                    pgFault, pgMajFault, rssInBytes, cacheInBytes, swapInBytes, processStartTimeNS,
                    minOomScore, freeMemKb, freeSwapKb, mapKillReason(killReason), thrashing,
                    maxThrashing);
                    maxThrashing, totalForegroundServices, procsWithForegroundServices);
        } catch (IOException e) {
            Slog.e(TAG, "Invalid buffer data. Failed to log LMK_KILL_OCCURRED");
            return;
+26 −1
Original line number Diff line number Diff line
@@ -814,7 +814,12 @@ public final class ProcessList {
                                                < LmkdStatsReporter.KILL_OCCURRED_MSG_SIZE) {
                                            return false;
                                        }
                                        LmkdStatsReporter.logKillOccurred(inputData);
                                        Pair<Integer, Integer> temp = getNumForegroundServices();
                                        final int totalForegroundServices = temp.first;
                                        final int procsWithForegroundServices = temp.second;
                                        LmkdStatsReporter.logKillOccurred(inputData,
                                                totalForegroundServices,
                                                procsWithForegroundServices);
                                        return true;
                                    case LMK_STATE_CHANGED:
                                        if (receivedLen
@@ -5123,6 +5128,26 @@ public final class ProcessList {
        }
    }

    /**
     * Get the number of foreground services in all processes and number of processes that have
     * foreground service within.
     */
    Pair<Integer, Integer> getNumForegroundServices() {
        int numForegroundServices = 0;
        int procs = 0;
        synchronized (mService) {
            for (int i = 0, size = mLruProcesses.size(); i < size; i++) {
                ProcessRecord pr = mLruProcesses.get(i);
                int numFgs = pr.mServices.getNumForegroundServices();
                if (numFgs > 0) {
                    numForegroundServices += numFgs;
                    procs++;
                }
            }
        }
        return new Pair<>(numForegroundServices, procs);
    }

    private final class ImperceptibleKillRunner extends IUidObserver.Stub {
        private static final String EXTRA_PID = "pid";
        private static final String EXTRA_UID = "uid";
+10 −0
Original line number Diff line number Diff line
@@ -180,6 +180,16 @@ final class ProcessServiceRecord {
        mRepFgServiceTypes = foregroundServiceTypes;
    }

    int getNumForegroundServices() {
        int count = 0;
        for (int i = 0, serviceCount = mServices.size(); i < serviceCount; i++) {
            if (mServices.valueAt(i).isForeground) {
                count++;
            }
        }
        return count;
    }

    void updateHasTopStartedAlmostPerceptibleServices() {
        mHasTopStartedAlmostPerceptibleServices = false;
        mLastTopStartedAlmostPerceptibleBindRequestUptimeMs = 0;