Loading core/java/com/android/internal/os/anr/AnrLatencyTracker.java +17 −1 Original line number Diff line number Diff line Loading @@ -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(); Loading Loading @@ -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"); Loading @@ -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 = */ Loading Loading @@ -464,6 +478,8 @@ public class AnrLatencyTracker implements AutoCloseable { + "," + mEarlyDumpStatus /* copying_first_pid_succeeded = */ + "," + (mCopyingFirstPidSucceeded ? 1 : 0) /* preDumpIfLockTooSlow_duration = */ + "," + mPreDumpIfLockTooSlowDuration + "\n\n"; } Loading services/core/java/com/android/server/wm/AnrController.java +25 −12 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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; Loading Loading @@ -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); } } Loading Loading @@ -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; Loading @@ -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); Loading @@ -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 Loading Loading @@ -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) { Loading Loading
core/java/com/android/internal/os/anr/AnrLatencyTracker.java +17 −1 Original line number Diff line number Diff line Loading @@ -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(); Loading Loading @@ -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"); Loading @@ -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 = */ Loading Loading @@ -464,6 +478,8 @@ public class AnrLatencyTracker implements AutoCloseable { + "," + mEarlyDumpStatus /* copying_first_pid_succeeded = */ + "," + (mCopyingFirstPidSucceeded ? 1 : 0) /* preDumpIfLockTooSlow_duration = */ + "," + mPreDumpIfLockTooSlowDuration + "\n\n"; } Loading
services/core/java/com/android/server/wm/AnrController.java +25 −12 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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; Loading Loading @@ -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); } } Loading Loading @@ -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; Loading @@ -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); Loading @@ -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 Loading Loading @@ -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) { Loading