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

Commit 9a7a0569 authored by Jing Ji's avatar Jing Ji Committed by Android (Google) Code Review
Browse files

Merge "Add the process oom adj score prior to the activity start" into tm-qpr-dev

parents ee949491 4a685b21
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -497,6 +497,7 @@ final class ProcessStateRecord {
    @GuardedBy({"mService", "mProcLock"})
    void setCurAdj(int curAdj) {
        mCurAdj = curAdj;
        mApp.getWindowProcessController().setCurrentAdj(curAdj);
    }

    @GuardedBy(anyOf = {"mService", "mProcLock"})
+25 −11
Original line number Diff line number Diff line
@@ -70,6 +70,7 @@ import static com.android.internal.util.FrameworkStatsLog.CAMERA_COMPAT_CONTROL_
import static com.android.internal.util.FrameworkStatsLog.CAMERA_COMPAT_CONTROL_EVENT_REPORTED__EVENT__CLICKED_REVERT_TREATMENT;
import static com.android.server.am.MemoryStatUtil.MemoryStat;
import static com.android.server.am.MemoryStatUtil.readMemoryStatFromFilesystem;
import static com.android.server.am.ProcessList.INVALID_ADJ;
import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_METRICS;
import static com.android.server.wm.ActivityTaskManagerDebugConfig.TAG_ATM;
import static com.android.server.wm.ActivityTaskManagerDebugConfig.TAG_WITH_CLASS_NAME;
@@ -277,6 +278,8 @@ class ActivityMetricsLogger {
        final boolean mProcessSwitch;
        /** The process state of the launching activity prior to the launch */
        final int mProcessState;
        /** The oom adj score of the launching activity prior to the launch */
        final int mProcessOomAdj;
        /** Whether the last launched activity has reported drawn. */
        boolean mIsDrawn;
        /** The latest activity to have been launched. */
@@ -312,7 +315,7 @@ class ActivityMetricsLogger {
        @Nullable
        static TransitionInfo create(@NonNull ActivityRecord r,
                @NonNull LaunchingState launchingState, @Nullable ActivityOptions options,
                boolean processRunning, boolean processSwitch, int processState,
                boolean processRunning, boolean processSwitch, int processState, int processOomAdj,
                boolean newActivityCreated, int startResult) {
            if (startResult != START_SUCCESS && startResult != START_TASK_TO_FRONT) {
                return null;
@@ -328,19 +331,20 @@ class ActivityMetricsLogger {
                transitionType = TYPE_TRANSITION_COLD_LAUNCH;
            }
            return new TransitionInfo(r, launchingState, options, transitionType, processRunning,
                    processSwitch, processState);
                    processSwitch, processState, processOomAdj);
        }

        /** Use {@link TransitionInfo#create} instead to ensure the transition type is valid. */
        private TransitionInfo(ActivityRecord r, LaunchingState launchingState,
                ActivityOptions options, int transitionType, boolean processRunning,
                boolean processSwitch, int processState) {
                boolean processSwitch, int processState, int processOomAdj) {
            mLaunchingState = launchingState;
            mTransitionStartTimeNs = launchingState.mCurrentTransitionStartTimeNs;
            mTransitionType = transitionType;
            mProcessRunning = processRunning;
            mProcessSwitch = processSwitch;
            mProcessState = processState;
            mProcessOomAdj = processOomAdj;
            mTransitionDeviceUptimeMs = launchingState.mCurrentUpTimeMs;
            setLatestLaunchedActivity(r);
            // The launching state can be reused by consecutive launch. Its original association
@@ -644,9 +648,15 @@ class ActivityMetricsLogger {
        // interesting.
        final boolean processSwitch = !processRunning
                || !processRecord.hasStartedActivity(launchedActivity);
        final int processState = processRunning
                ? processRecord.getCurrentProcState()
                : PROCESS_STATE_NONEXISTENT;
        final int processState;
        final int processOomAdj;
        if (processRunning) {
            processState = processRecord.getCurrentProcState();
            processOomAdj = processRecord.getCurrentAdj();
        } else {
            processState = PROCESS_STATE_NONEXISTENT;
            processOomAdj = INVALID_ADJ;
        }

        final TransitionInfo info = launchingState.mAssociatedTransitionInfo;
        if (DEBUG_METRICS) {
@@ -654,6 +664,7 @@ class ActivityMetricsLogger {
                    + " launchedActivity=" + launchedActivity + " processRunning=" + processRunning
                    + " processSwitch=" + processSwitch
                    + " processState=" + processState
                    + " processOomAdj=" + processOomAdj
                    + " newActivityCreated=" + newActivityCreated + " info=" + info);
        }

@@ -689,8 +700,8 @@ class ActivityMetricsLogger {
        }

        final TransitionInfo newInfo = TransitionInfo.create(launchedActivity, launchingState,
                options, processRunning, processSwitch, processState, newActivityCreated,
                resultCode);
                options, processRunning, processSwitch, processState, processOomAdj,
                newActivityCreated, resultCode);
        if (newInfo == null) {
            abort(launchingState, "unrecognized launch");
            return;
@@ -1005,8 +1016,10 @@ class ActivityMetricsLogger {
            final long uptime = info.mTransitionDeviceUptimeMs;
            final int transitionDelay = info.mCurrentTransitionDelayMs;
            final int processState = info.mProcessState;
            final int processOomAdj = info.mProcessOomAdj;
            mLoggerHandler.post(() -> logAppTransition(
                    timestamp, uptime, transitionDelay, infoSnapshot, isHibernating, processState));
                    timestamp, uptime, transitionDelay, infoSnapshot, isHibernating,
                    processState, processOomAdj));
        }
        mLoggerHandler.post(() -> logAppDisplayed(infoSnapshot));
        if (info.mPendingFullyDrawn != null) {
@@ -1019,7 +1032,7 @@ class ActivityMetricsLogger {
    // This gets called on another thread without holding the activity manager lock.
    private void logAppTransition(long transitionStartTimeNs, long transitionDeviceUptimeMs,
            int currentTransitionDelayMs, TransitionInfoSnapshot info, boolean isHibernating,
            int processState) {
            int processState, int processOomAdj) {
        final LogMaker builder = new LogMaker(APP_TRANSITION);
        builder.setPackageName(info.packageName);
        builder.setType(info.type);
@@ -1086,7 +1099,8 @@ class ActivityMetricsLogger {
                isLoading,
                info.launchedActivityName.hashCode(),
                TimeUnit.NANOSECONDS.toMillis(transitionStartTimeNs),
                processState);
                processState,
                processOomAdj);

        if (DEBUG_METRICS) {
            Slog.i(TAG, String.format("APP_START_OCCURRED(%s, %s, %s, %s, %s)",
+11 −0
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import static android.os.InputConstants.DEFAULT_DISPATCHING_TIMEOUT_MILLIS;

import static com.android.internal.protolog.ProtoLogGroup.WM_DEBUG_CONFIGURATION;
import static com.android.internal.util.Preconditions.checkArgument;
import static com.android.server.am.ProcessList.INVALID_ADJ;
import static com.android.server.wm.ActivityRecord.State.DESTROYED;
import static com.android.server.wm.ActivityRecord.State.DESTROYING;
import static com.android.server.wm.ActivityRecord.State.PAUSED;
@@ -123,6 +124,8 @@ public class WindowProcessController extends ConfigurationContainer<Configuratio
    private volatile int mCurProcState = PROCESS_STATE_NONEXISTENT;
    // Last reported process state;
    private volatile int mRepProcState = PROCESS_STATE_NONEXISTENT;
    // Currently computed oom adj score
    private volatile int mCurAdj = INVALID_ADJ;
    // are we in the process of crashing?
    private volatile boolean mCrashing;
    // does the app have a not responding dialog?
@@ -317,6 +320,14 @@ public class WindowProcessController extends ConfigurationContainer<Configuratio
        return mCurProcState;
    }

    public void setCurrentAdj(int curAdj) {
        mCurAdj = curAdj;
    }

    int getCurrentAdj() {
        return mCurAdj;
    }

    /**
     * Sets the computed process state from the oom adjustment calculation. This is frequently
     * called in activity manager's lock, so don't use window manager lock here.