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

Commit fe5097cf authored by Mark Fasheh's avatar Mark Fasheh Committed by Android (Google) Code Review
Browse files

Merge "Only collect PSS one time after an app has been frozen."

parents a818ba89 bb7484a1
Loading
Loading
Loading
Loading
+9 −5
Original line number Diff line number Diff line
@@ -506,10 +506,14 @@ public class AppProfiler {
            }
            if (profile != null) {
                long startTime = SystemClock.currentThreadTimeMillis();
                // skip background PSS calculation of apps that are capturing
                // camera imagery
                final boolean usingCamera = mService.isCameraActiveForUid(profile.mApp.uid);
                long pss = usingCamera ? 0 : Debug.getPss(pid, tmp, null);
                // skip background PSS calculation under the following situations:
                //  - app is capturing camera imagery
                //  - app is frozen and we have already collected PSS once.
                final boolean skipPSSCollection =
                        (profile.mApp.mOptRecord != null
                         && profile.mApp.mOptRecord.skipPSSCollectionBecauseFrozen())
                        || mService.isCameraActiveForUid(profile.mApp.uid);
                long pss = skipPSSCollection ? 0 : Debug.getPss(pid, tmp, null);
                long endTime = SystemClock.currentThreadTimeMillis();
                synchronized (mProfilerLock) {
                    if (pss != 0 && profile.getThread() != null
@@ -524,7 +528,7 @@ public class AppProfiler {
                        if (DEBUG_PSS) {
                            Slog.d(TAG_PSS, "Skipped pss collection of " + pid
                                    + ": " + (profile.getThread() == null ? "NO_THREAD " : "")
                                    + (usingCamera ? "CAMERA " : "")
                                    + (skipPSSCollection ? "SKIP_PSS_COLLECTION " : "")
                                    + (profile.getPid() != pid ? "PID_CHANGED " : "")
                                    + " initState=" + procState + " curState="
                                    + profile.getSetProcState() + " "
+1 −0
Original line number Diff line number Diff line
@@ -2004,6 +2004,7 @@ public final class CachedAppOptimizer {

                    opt.setFreezeUnfreezeTime(SystemClock.uptimeMillis());
                    opt.setFrozen(true);
                    opt.setHasCollectedFrozenPSS(false);
                    mFrozenProcesses.put(pid, proc);
                } catch (Exception e) {
                    Slog.w(TAG_AM, "Unable to freeze " + pid + " " + name);
+25 −0
Original line number Diff line number Diff line
@@ -72,6 +72,12 @@ final class ProcessCachedOptimizerRecord {
    @GuardedBy("mProcLock")
    private boolean mFrozen;

    /**
     * Set to false after the process has been frozen.
     * Set to true after we have collected PSS for the frozen process.
     */
    private boolean mHasCollectedFrozenPSS;

    /**
     * An override on the freeze state is in progress.
     */
@@ -188,6 +194,25 @@ final class ProcessCachedOptimizerRecord {
        mFrozen = frozen;
    }

    boolean skipPSSCollectionBecauseFrozen() {
        boolean collected = mHasCollectedFrozenPSS;

        // This check is racy but it isn't critical to PSS collection that we have the most up to
        // date idea of whether a task is frozen.
        if (!mFrozen) {
            // not frozen == always ask to collect PSS
            return false;
        }

        // We don't want to count PSS for a frozen process more than once.
        mHasCollectedFrozenPSS = true;
        return collected;
    }

    void setHasCollectedFrozenPSS(boolean collected) {
        mHasCollectedFrozenPSS = collected;
    }

    @GuardedBy("mProcLock")
    boolean hasFreezerOverride() {
        return mFreezerOverride;