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

Commit bf61ebd3 authored by Jing Ji's avatar Jing Ji
Browse files

Defer the Pss sampling on app processes post the boot

Now we're not going to collect the Pss for the first N(default=20) mins
after the boot. Given the system is most likely very busy, sampling
the Pss makes the system load even worse.

Bug: 304484667
Test: Manual - check logcat.
Change-Id: I2f7fb78e003fa3b426643f2a7067afb77b5b9b63
parent 7be165fb
Loading
Loading
Loading
Loading
+13 −4
Original line number Original line Diff line number Diff line
@@ -1531,6 +1531,11 @@ public class ActivityManagerService extends IActivityManager.Stub
     */
     */
    int mBootPhase;
    int mBootPhase;
    /**
     * The time stamp that all apps have received BOOT_COMPLETED.
     */
    volatile long mBootCompletedTimestamp;
    @GuardedBy("this")
    @GuardedBy("this")
    boolean mDeterministicUidIdle = false;
    boolean mDeterministicUidIdle = false;
@@ -5126,10 +5131,14 @@ public class ActivityManagerService extends IActivityManager.Stub
                        public void performReceive(Intent intent, int resultCode,
                        public void performReceive(Intent intent, int resultCode,
                                String data, Bundle extras, boolean ordered,
                                String data, Bundle extras, boolean ordered,
                                boolean sticky, int sendingUser) {
                                boolean sticky, int sendingUser) {
                            mBootCompletedTimestamp = SystemClock.uptimeMillis();
                            // Defer the full Pss collection as the system is really busy now.
                            mHandler.postDelayed(() -> {
                                synchronized (mProcLock) {
                                synchronized (mProcLock) {
                                    mAppProfiler.requestPssAllProcsLPr(
                                    mAppProfiler.requestPssAllProcsLPr(
                                            SystemClock.uptimeMillis(), true, false);
                                            SystemClock.uptimeMillis(), true, false);
                                }
                                }
                            }, mConstants.FULL_PSS_MIN_INTERVAL);
                        }
                        }
                    });
                    });
            maybeLogUserspaceRebootEvent();
            maybeLogUserspaceRebootEvent();
+2 −2
Original line number Original line Diff line number Diff line
@@ -1439,7 +1439,7 @@ public final class ProcessList {
    }
    }


    public static long computeNextPssTime(int procState, ProcStateMemTracker tracker, boolean test,
    public static long computeNextPssTime(int procState, ProcStateMemTracker tracker, boolean test,
            boolean sleeping, long now) {
            boolean sleeping, long now, long earliest) {
        boolean first;
        boolean first;
        float scalingFactor;
        float scalingFactor;
        final int memState = sProcStateToProcMem[procState];
        final int memState = sProcStateToProcMem[procState];
@@ -1470,7 +1470,7 @@ public final class ProcessList {
        if (delay > PSS_MAX_INTERVAL) {
        if (delay > PSS_MAX_INTERVAL) {
            delay = PSS_MAX_INTERVAL;
            delay = PSS_MAX_INTERVAL;
        }
        }
        return now + delay;
        return Math.max(now + delay, earliest);
    }
    }


    long getMemLevel(int adjustment) {
    long getMemLevel(int adjustment) {
+5 −1
Original line number Original line Diff line number Diff line
@@ -570,7 +570,11 @@ final class ProcessProfileRecord {


    @GuardedBy("mProfilerLock")
    @GuardedBy("mProfilerLock")
    long computeNextPssTime(int procState, boolean test, boolean sleeping, long now) {
    long computeNextPssTime(int procState, boolean test, boolean sleeping, long now) {
        return ProcessList.computeNextPssTime(procState, mProcStateMemTracker, test, sleeping, now);
        return ProcessList.computeNextPssTime(procState, mProcStateMemTracker, test, sleeping, now,
                // Cap the Pss time to make sure no Pss is collected during the very few
                // minutes after the system is boot, given the system is already busy.
                Math.max(mService.mBootCompletedTimestamp, mService.mLastIdleTime)
                + mService.mConstants.FULL_PSS_MIN_INTERVAL);
    }
    }


    private static void commitNextPssTime(ProcStateMemTracker tracker) {
    private static void commitNextPssTime(ProcStateMemTracker tracker) {