Loading services/core/java/com/android/server/wm/ActivityMetricsLogger.java +16 −6 Original line number Original line Diff line number Diff line Loading @@ -194,11 +194,10 @@ class ActivityMetricsLogger { /** The sequence id for trace. It is used to map the traces before resolving intent. */ /** The sequence id for trace. It is used to map the traces before resolving intent. */ private static int sTraceSeqId; private static int sTraceSeqId; /** The trace format is "launchingActivity#$seqId:$state(:$packageName)". */ /** The trace format is "launchingActivity#$seqId:$state(:$packageName)". */ final String mTraceName; String mTraceName; LaunchingState() { LaunchingState() { if (!Trace.isTagEnabled(Trace.TRACE_TAG_ACTIVITY_MANAGER)) { if (!Trace.isTagEnabled(Trace.TRACE_TAG_ACTIVITY_MANAGER)) { mTraceName = null; return; return; } } // Use an id because the launching app is not yet known before resolving intent. // Use an id because the launching app is not yet known before resolving intent. Loading @@ -207,8 +206,14 @@ class ActivityMetricsLogger { Trace.asyncTraceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, mTraceName, 0); Trace.asyncTraceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, mTraceName, 0); } } void stopTrace(boolean abort) { void stopTrace(boolean abort, TransitionInfo endInfo) { if (mTraceName == null) return; if (mTraceName == null) return; if (!abort && endInfo != mAssociatedTransitionInfo) { // Multiple TransitionInfo can be associated with the same LaunchingState (e.g. a // launching activity launches another activity in a different windowing mode or // display). Only the original associated info can emit a "completed" trace. return; } Trace.asyncTraceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER, mTraceName, 0); Trace.asyncTraceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER, mTraceName, 0); final String launchResult; final String launchResult; if (mAssociatedTransitionInfo == null) { if (mAssociatedTransitionInfo == null) { Loading @@ -220,6 +225,7 @@ class ActivityMetricsLogger { } } // Put a supplement trace as the description of the async trace with the same id. // Put a supplement trace as the description of the async trace with the same id. Trace.instant(Trace.TRACE_TAG_ACTIVITY_MANAGER, mTraceName + launchResult); Trace.instant(Trace.TRACE_TAG_ACTIVITY_MANAGER, mTraceName + launchResult); mTraceName = null; } } @VisibleForTesting @VisibleForTesting Loading Loading @@ -323,7 +329,11 @@ class ActivityMetricsLogger { mProcessSwitch = processSwitch; mProcessSwitch = processSwitch; mTransitionDeviceUptimeMs = launchingState.mCurrentUpTimeMs; mTransitionDeviceUptimeMs = launchingState.mCurrentUpTimeMs; setLatestLaunchedActivity(r); setLatestLaunchedActivity(r); // The launching state can be reused by consecutive launch. Its original association // shouldn't be changed by a separated transition. if (launchingState.mAssociatedTransitionInfo == null) { launchingState.mAssociatedTransitionInfo = this; launchingState.mAssociatedTransitionInfo = this; } if (options != null) { if (options != null) { final SourceInfo sourceInfo = options.getSourceInfo(); final SourceInfo sourceInfo = options.getSourceInfo(); if (sourceInfo != null) { if (sourceInfo != null) { Loading Loading @@ -916,7 +926,7 @@ class ActivityMetricsLogger { return; return; } } if (DEBUG_METRICS) Slog.i(TAG, "abort launch cause=" + cause); if (DEBUG_METRICS) Slog.i(TAG, "abort launch cause=" + cause); state.stopTrace(true /* abort */); state.stopTrace(true /* abort */, null /* endInfo */); launchObserverNotifyIntentFailed(state.mCurrentTransitionStartTimeNs); launchObserverNotifyIntentFailed(state.mCurrentTransitionStartTimeNs); } } Loading @@ -932,7 +942,7 @@ class ActivityMetricsLogger { Slog.i(TAG, "done abort=" + abort + " cause=" + cause + " timestamp=" + timestampNs Slog.i(TAG, "done abort=" + abort + " cause=" + cause + " timestamp=" + timestampNs + " info=" + info); + " info=" + info); } } info.mLaunchingState.stopTrace(abort); info.mLaunchingState.stopTrace(abort, info); stopLaunchTrace(info); stopLaunchTrace(info); final Boolean isHibernating = final Boolean isHibernating = mLastHibernationStates.remove(info.mLastLaunchedActivity.packageName); mLastHibernationStates.remove(info.mLastLaunchedActivity.packageName); Loading services/tests/wmtests/src/com/android/server/wm/ActivityMetricsLaunchObserverTests.java +3 −0 Original line number Original line Diff line number Diff line Loading @@ -532,6 +532,9 @@ public class ActivityMetricsLaunchObserverTests extends WindowTestsBase { transitToDrawnAndVerifyOnLaunchFinished(mTopActivity); transitToDrawnAndVerifyOnLaunchFinished(mTopActivity); setLastExpectedStartedId(activityOnNewDisplay); setLastExpectedStartedId(activityOnNewDisplay); transitToDrawnAndVerifyOnLaunchFinished(activityOnNewDisplay); transitToDrawnAndVerifyOnLaunchFinished(activityOnNewDisplay); assertWithMessage("The launching state must not include the separated launch") .that(mLaunchingState.contains(activityOnNewDisplay)).isFalse(); } } @Test @Test Loading Loading
services/core/java/com/android/server/wm/ActivityMetricsLogger.java +16 −6 Original line number Original line Diff line number Diff line Loading @@ -194,11 +194,10 @@ class ActivityMetricsLogger { /** The sequence id for trace. It is used to map the traces before resolving intent. */ /** The sequence id for trace. It is used to map the traces before resolving intent. */ private static int sTraceSeqId; private static int sTraceSeqId; /** The trace format is "launchingActivity#$seqId:$state(:$packageName)". */ /** The trace format is "launchingActivity#$seqId:$state(:$packageName)". */ final String mTraceName; String mTraceName; LaunchingState() { LaunchingState() { if (!Trace.isTagEnabled(Trace.TRACE_TAG_ACTIVITY_MANAGER)) { if (!Trace.isTagEnabled(Trace.TRACE_TAG_ACTIVITY_MANAGER)) { mTraceName = null; return; return; } } // Use an id because the launching app is not yet known before resolving intent. // Use an id because the launching app is not yet known before resolving intent. Loading @@ -207,8 +206,14 @@ class ActivityMetricsLogger { Trace.asyncTraceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, mTraceName, 0); Trace.asyncTraceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, mTraceName, 0); } } void stopTrace(boolean abort) { void stopTrace(boolean abort, TransitionInfo endInfo) { if (mTraceName == null) return; if (mTraceName == null) return; if (!abort && endInfo != mAssociatedTransitionInfo) { // Multiple TransitionInfo can be associated with the same LaunchingState (e.g. a // launching activity launches another activity in a different windowing mode or // display). Only the original associated info can emit a "completed" trace. return; } Trace.asyncTraceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER, mTraceName, 0); Trace.asyncTraceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER, mTraceName, 0); final String launchResult; final String launchResult; if (mAssociatedTransitionInfo == null) { if (mAssociatedTransitionInfo == null) { Loading @@ -220,6 +225,7 @@ class ActivityMetricsLogger { } } // Put a supplement trace as the description of the async trace with the same id. // Put a supplement trace as the description of the async trace with the same id. Trace.instant(Trace.TRACE_TAG_ACTIVITY_MANAGER, mTraceName + launchResult); Trace.instant(Trace.TRACE_TAG_ACTIVITY_MANAGER, mTraceName + launchResult); mTraceName = null; } } @VisibleForTesting @VisibleForTesting Loading Loading @@ -323,7 +329,11 @@ class ActivityMetricsLogger { mProcessSwitch = processSwitch; mProcessSwitch = processSwitch; mTransitionDeviceUptimeMs = launchingState.mCurrentUpTimeMs; mTransitionDeviceUptimeMs = launchingState.mCurrentUpTimeMs; setLatestLaunchedActivity(r); setLatestLaunchedActivity(r); // The launching state can be reused by consecutive launch. Its original association // shouldn't be changed by a separated transition. if (launchingState.mAssociatedTransitionInfo == null) { launchingState.mAssociatedTransitionInfo = this; launchingState.mAssociatedTransitionInfo = this; } if (options != null) { if (options != null) { final SourceInfo sourceInfo = options.getSourceInfo(); final SourceInfo sourceInfo = options.getSourceInfo(); if (sourceInfo != null) { if (sourceInfo != null) { Loading Loading @@ -916,7 +926,7 @@ class ActivityMetricsLogger { return; return; } } if (DEBUG_METRICS) Slog.i(TAG, "abort launch cause=" + cause); if (DEBUG_METRICS) Slog.i(TAG, "abort launch cause=" + cause); state.stopTrace(true /* abort */); state.stopTrace(true /* abort */, null /* endInfo */); launchObserverNotifyIntentFailed(state.mCurrentTransitionStartTimeNs); launchObserverNotifyIntentFailed(state.mCurrentTransitionStartTimeNs); } } Loading @@ -932,7 +942,7 @@ class ActivityMetricsLogger { Slog.i(TAG, "done abort=" + abort + " cause=" + cause + " timestamp=" + timestampNs Slog.i(TAG, "done abort=" + abort + " cause=" + cause + " timestamp=" + timestampNs + " info=" + info); + " info=" + info); } } info.mLaunchingState.stopTrace(abort); info.mLaunchingState.stopTrace(abort, info); stopLaunchTrace(info); stopLaunchTrace(info); final Boolean isHibernating = final Boolean isHibernating = mLastHibernationStates.remove(info.mLastLaunchedActivity.packageName); mLastHibernationStates.remove(info.mLastLaunchedActivity.packageName); Loading
services/tests/wmtests/src/com/android/server/wm/ActivityMetricsLaunchObserverTests.java +3 −0 Original line number Original line Diff line number Diff line Loading @@ -532,6 +532,9 @@ public class ActivityMetricsLaunchObserverTests extends WindowTestsBase { transitToDrawnAndVerifyOnLaunchFinished(mTopActivity); transitToDrawnAndVerifyOnLaunchFinished(mTopActivity); setLastExpectedStartedId(activityOnNewDisplay); setLastExpectedStartedId(activityOnNewDisplay); transitToDrawnAndVerifyOnLaunchFinished(activityOnNewDisplay); transitToDrawnAndVerifyOnLaunchFinished(activityOnNewDisplay); assertWithMessage("The launching state must not include the separated launch") .that(mLaunchingState.contains(activityOnNewDisplay)).isFalse(); } } @Test @Test Loading