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

Commit acce1ce2 authored by Mohamad Mahmoud's avatar Mohamad Mahmoud Committed by Automerger Merge Worker
Browse files

Merge "Move dumpAnrStateLocked off the critical ANR path" into udc-dev am:...

Merge "Move dumpAnrStateLocked off the critical ANR path" into udc-dev am: bc6fc2c4 am: 74cd564c

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/23130580



Change-Id: I30d99f73e8e0b7cc6a5a93e968e90dd282cf712b
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 3cc8ecd6 74cd564c
Loading
Loading
Loading
Loading
+17 −1
Original line number Diff line number Diff line
@@ -118,6 +118,9 @@ public class AnrLatencyTracker implements AutoCloseable {
    private boolean mIsSkipped = false;
    private boolean mCopyingFirstPidSucceeded = false;

    private long mPreDumpIfLockTooSlowStartUptime;
    private long mPreDumpIfLockTooSlowDuration = 0;

    private final int mAnrRecordPlacedOnQueueCookie =
            sNextAnrRecordPlacedOnQueueCookieGenerator.incrementAndGet();

@@ -401,6 +404,17 @@ public class AnrLatencyTracker implements AutoCloseable {
        Trace.traceCounter(TRACE_TAG_ACTIVITY_MANAGER, "anrRecordsQueueSize", queueSize);
    }

    /** Records the start of AnrController#preDumpIfLockTooSlow. */
    public void preDumpIfLockTooSlowStarted() {
        mPreDumpIfLockTooSlowStartUptime = getUptimeMillis();
    }

    /** Records the end of AnrController#preDumpIfLockTooSlow. */
    public void preDumpIfLockTooSlowEnded() {
        mPreDumpIfLockTooSlowDuration +=
                getUptimeMillis() - mPreDumpIfLockTooSlowStartUptime;
    }

    /** Records a skipped ANR in ProcessErrorStateRecord#appNotResponding. */
    public void anrSkippedProcessErrorStateRecordAppNotResponding() {
        anrSkipped("appNotResponding");
@@ -415,7 +429,7 @@ public class AnrLatencyTracker implements AutoCloseable {
     * Returns latency data as a comma separated value string for inclusion in ANR report.
     */
    public String dumpAsCommaSeparatedArrayWithHeader() {
        return "DurationsV3: " + mAnrTriggerUptime
        return "DurationsV4: " + mAnrTriggerUptime
                /* triggering_to_app_not_responding_duration = */
                + "," + (mAppNotRespondingStartUptime -  mAnrTriggerUptime)
                /* app_not_responding_duration = */
@@ -464,6 +478,8 @@ public class AnrLatencyTracker implements AutoCloseable {
                + "," + mEarlyDumpStatus
                /* copying_first_pid_succeeded = */
                + "," + (mCopyingFirstPidSucceeded ? 1 : 0)
                /* preDumpIfLockTooSlow_duration = */
                + "," + mPreDumpIfLockTooSlowDuration
                + "\n\n";

    }
+25 −12
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ import android.util.SparseArray;
import android.view.InputApplicationHandle;

import com.android.internal.os.TimeoutRecord;
import com.android.server.FgThread;
import com.android.server.am.StackTracesDumpHelper;
import com.android.server.criticalevents.CriticalEventLog;

@@ -68,7 +69,9 @@ class AnrController {
            TimeoutRecord timeoutRecord) {
        try {
            Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "notifyAppUnresponsive()");
            timeoutRecord.mLatencyTracker.preDumpIfLockTooSlowStarted();
            preDumpIfLockTooSlow();
            timeoutRecord.mLatencyTracker.preDumpIfLockTooSlowEnded();
            final ActivityRecord activity;
            timeoutRecord.mLatencyTracker.waitingOnGlobalLockStarted();
            boolean blamePendingFocusRequest = false;
@@ -108,7 +111,7 @@ class AnrController {
                if (!blamePendingFocusRequest) {
                    Slog.i(TAG_WM, "ANR in " + activity.getName() + ".  Reason: "
                            + timeoutRecord.mReason);
                    dumpAnrStateLocked(activity, null /* windowState */, timeoutRecord.mReason);
                    dumpAnrStateAsync(activity, null /* windowState */, timeoutRecord.mReason);
                    mUnresponsiveAppByDisplay.put(activity.getDisplayId(), activity);
                }
            }
@@ -159,7 +162,9 @@ class AnrController {
     */
    private boolean notifyWindowUnresponsive(@NonNull IBinder inputToken,
            TimeoutRecord timeoutRecord) {
        timeoutRecord.mLatencyTracker.preDumpIfLockTooSlowStarted();
        preDumpIfLockTooSlow();
        timeoutRecord.mLatencyTracker.preDumpIfLockTooSlowEnded();
        final int pid;
        final boolean aboveSystem;
        final ActivityRecord activity;
@@ -178,7 +183,7 @@ class AnrController {
                    ? windowState.mActivityRecord : null;
            Slog.i(TAG_WM, "ANR in " + target + ". Reason:" + timeoutRecord.mReason);
            aboveSystem = isWindowAboveSystem(windowState);
            dumpAnrStateLocked(activity, windowState, timeoutRecord.mReason);
            dumpAnrStateAsync(activity, windowState, timeoutRecord.mReason);
        }
        if (activity != null) {
            activity.inputDispatchingTimedOut(timeoutRecord, pid);
@@ -197,7 +202,7 @@ class AnrController {
        timeoutRecord.mLatencyTracker.waitingOnGlobalLockStarted();
        synchronized (mService.mGlobalLock) {
            timeoutRecord.mLatencyTracker.waitingOnGlobalLockEnded();
            dumpAnrStateLocked(null /* activity */, null /* windowState */, timeoutRecord.mReason);
            dumpAnrStateAsync(null /* activity */, null /* windowState */, timeoutRecord.mReason);
        }

        // We cannot determine the z-order of the window, so place the anr dialog as high
@@ -351,15 +356,23 @@ class AnrController {

    }

    private void dumpAnrStateLocked(ActivityRecord activity, WindowState windowState,
    /**
     * Executes asynchronously on the fg thread not to block the stack dump for
     * the ANRing processes.
     */
    private void dumpAnrStateAsync(ActivityRecord activity, WindowState windowState,
            String reason) {
        FgThread.getExecutor().execute(() -> {
            try {
                Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "dumpAnrStateLocked()");
                synchronized (mService.mGlobalLock) {
                    mService.saveANRStateLocked(activity, windowState, reason);
                    mService.mAtmService.saveANRState(reason);
                }
            } finally {
                Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);
            }
        });
    }

    private boolean isWindowAboveSystem(@NonNull WindowState windowState) {