Merge "Improve AM lifecycle event logs"

This commit is contained in:
Andrii Kulian
2018-02-22 22:54:53 +00:00
committed by Android (Google) Code Review
7 changed files with 58 additions and 35 deletions

View File

@@ -751,6 +751,14 @@ public class Activity extends ContextThemeWrapper
private static final String KEYBOARD_SHORTCUTS_RECEIVER_PKG_NAME = "com.android.systemui";
private static final int LOG_AM_ON_CREATE_CALLED = 30057;
private static final int LOG_AM_ON_START_CALLED = 30059;
private static final int LOG_AM_ON_RESUME_CALLED = 30022;
private static final int LOG_AM_ON_PAUSE_CALLED = 30021;
private static final int LOG_AM_ON_STOP_CALLED = 30049;
private static final int LOG_AM_ON_RESTART_CALLED = 30058;
private static final int LOG_AM_ON_DESTROY_CALLED = 30060;
private static class ManagedDialog {
Dialog mDialog;
Bundle mArgs;
@@ -7097,6 +7105,7 @@ public class Activity extends ContextThemeWrapper
} else {
onCreate(icicle);
}
writeEventLog(LOG_AM_ON_CREATE_CALLED, "performCreate");
mActivityTransitionState.readState(icicle);
mVisibleFromClient = !mWindow.getWindowStyle().getBoolean(
@@ -7110,12 +7119,14 @@ public class Activity extends ContextThemeWrapper
onNewIntent(intent);
}
final void performStart() {
final void performStart(String reason) {
mActivityTransitionState.setEnterActivityOptions(this, getActivityOptions());
mFragments.noteStateNotSaved();
mCalled = false;
mFragments.execPendingActions();
mInstrumentation.callActivityOnStart(this);
writeEventLog(LOG_AM_ON_START_CALLED, reason);
if (!mCalled) {
throw new SuperNotCalledException(
"Activity " + mComponent.toShortString() +
@@ -7184,7 +7195,7 @@ public class Activity extends ContextThemeWrapper
* The option to not start immediately is needed in case a transaction with
* multiple lifecycle transitions is in progress.
*/
final void performRestart(boolean start) {
final void performRestart(boolean start, String reason) {
mCanEnterPictureInPicture = true;
mFragments.noteStateNotSaved();
@@ -7217,19 +7228,20 @@ public class Activity extends ContextThemeWrapper
mCalled = false;
mInstrumentation.callActivityOnRestart(this);
writeEventLog(LOG_AM_ON_RESTART_CALLED, reason);
if (!mCalled) {
throw new SuperNotCalledException(
"Activity " + mComponent.toShortString() +
" did not call through to super.onRestart()");
}
if (start) {
performStart();
performStart(reason);
}
}
}
final void performResume(boolean followedByPause) {
performRestart(true /* start */);
final void performResume(boolean followedByPause, String reason) {
performRestart(true /* start */, reason);
mFragments.execPendingActions();
@@ -7248,6 +7260,7 @@ public class Activity extends ContextThemeWrapper
mCalled = false;
// mResumed is set by the instrumentation
mInstrumentation.callActivityOnResume(this);
writeEventLog(LOG_AM_ON_RESUME_CALLED, reason);
if (!mCalled) {
throw new SuperNotCalledException(
"Activity " + mComponent.toShortString() +
@@ -7284,6 +7297,7 @@ public class Activity extends ContextThemeWrapper
mFragments.dispatchPause();
mCalled = false;
onPause();
writeEventLog(LOG_AM_ON_PAUSE_CALLED, "performPause");
mResumed = false;
if (!mCalled && getApplicationInfo().targetSdkVersion
>= android.os.Build.VERSION_CODES.GINGERBREAD) {
@@ -7291,7 +7305,6 @@ public class Activity extends ContextThemeWrapper
"Activity " + mComponent.toShortString() +
" did not call through to super.onPause()");
}
mResumed = false;
}
final void performUserLeaving() {
@@ -7299,7 +7312,7 @@ public class Activity extends ContextThemeWrapper
onUserLeaveHint();
}
final void performStop(boolean preserveWindow) {
final void performStop(boolean preserveWindow, String reason) {
mDoReportFullyDrawn = false;
mFragments.doLoaderStop(mChangingConfigurations /*retain*/);
@@ -7322,6 +7335,7 @@ public class Activity extends ContextThemeWrapper
mCalled = false;
mInstrumentation.callActivityOnStop(this);
writeEventLog(LOG_AM_ON_STOP_CALLED, reason);
if (!mCalled) {
throw new SuperNotCalledException(
"Activity " + mComponent.toShortString() +
@@ -7349,6 +7363,7 @@ public class Activity extends ContextThemeWrapper
mWindow.destroy();
mFragments.dispatchDestroy();
onDestroy();
writeEventLog(LOG_AM_ON_DESTROY_CALLED, "performDestroy");
mFragments.doLoaderDestroy();
if (mVoiceInteractor != null) {
mVoiceInteractor.detachActivity();
@@ -7823,6 +7838,12 @@ public class Activity extends ContextThemeWrapper
}
}
/** Log a lifecycle event for current user id and component class. */
private void writeEventLog(int event, String reason) {
EventLog.writeEvent(event, UserHandle.myUserId(), getComponentName().getClassName(),
reason);
}
class HostCallbacks extends FragmentHostCallback<Activity> {
public HostCallbacks() {
super(Activity.this /*activity*/);

View File

@@ -208,9 +208,6 @@ public final class ActivityThread extends ClientTransactionHandler {
public static final boolean DEBUG_ORDER = false;
private static final long MIN_TIME_BETWEEN_GCS = 5*1000;
private static final int SQLITE_MEM_RELEASED_EVENT_LOG_TAG = 75003;
private static final int LOG_AM_ON_PAUSE_CALLED = 30021;
private static final int LOG_AM_ON_RESUME_CALLED = 30022;
private static final int LOG_AM_ON_STOP_CALLED = 30049;
/** Type for IActivityManager.serviceDoneExecuting: anonymous operation */
public static final int SERVICE_DONE_EXECUTING_ANON = 0;
@@ -2924,7 +2921,7 @@ public final class ActivityThread extends ClientTransactionHandler {
}
// Start
activity.performStart();
activity.performStart("handleStartActivity");
r.setState(ON_START);
if (pendingActions == null) {
@@ -3113,7 +3110,7 @@ public final class ActivityThread extends ClientTransactionHandler {
checkAndBlockForNetworkAccess();
deliverNewIntents(r, intents);
if (resumed) {
r.activity.performResume(false);
r.activity.performResume(false, "performNewIntents");
r.activity.mTemporaryPause = false;
}
@@ -3735,10 +3732,7 @@ public final class ActivityThread extends ClientTransactionHandler {
deliverResults(r, r.pendingResults);
r.pendingResults = null;
}
r.activity.performResume(r.startsNotResumed);
EventLog.writeEvent(LOG_AM_ON_RESUME_CALLED, UserHandle.myUserId(),
r.activity.getComponentName().getClassName(), reason);
r.activity.performResume(r.startsNotResumed, reason);
r.state = null;
r.persistentState = null;
@@ -3906,7 +3900,8 @@ public final class ActivityThread extends ClientTransactionHandler {
@Override
public void handlePauseActivity(IBinder token, boolean finished, boolean userLeaving,
int configChanges, boolean dontReport, PendingTransactionActions pendingActions) {
int configChanges, boolean dontReport, PendingTransactionActions pendingActions,
String reason) {
ActivityClientRecord r = mActivities.get(token);
if (r != null) {
if (userLeaving) {
@@ -3914,7 +3909,7 @@ public final class ActivityThread extends ClientTransactionHandler {
}
r.activity.mConfigChangeFlags |= configChanges;
performPauseActivity(r, finished, "handlePauseActivity", pendingActions);
performPauseActivity(r, finished, reason, pendingActions);
// Make sure any pending writes are now committed.
if (r.isPreHoneycomb()) {
@@ -4007,8 +4002,6 @@ public final class ActivityThread extends ClientTransactionHandler {
try {
r.activity.mCalled = false;
mInstrumentation.callActivityOnPause(r.activity);
EventLog.writeEvent(LOG_AM_ON_PAUSE_CALLED, UserHandle.myUserId(),
r.activity.getComponentName().getClassName(), reason);
if (!r.activity.mCalled) {
throw new SuperNotCalledException("Activity " + safeToComponentShortString(r.intent)
+ " did not call through to super.onPause()");
@@ -4119,7 +4112,7 @@ public final class ActivityThread extends ClientTransactionHandler {
}
try {
r.activity.performStop(false /*preserveWindow*/);
r.activity.performStop(false /*preserveWindow*/, reason);
} catch (SuperNotCalledException e) {
throw e;
} catch (Exception e) {
@@ -4131,8 +4124,6 @@ public final class ActivityThread extends ClientTransactionHandler {
}
}
r.setState(ON_STOP);
EventLog.writeEvent(LOG_AM_ON_STOP_CALLED, UserHandle.myUserId(),
r.activity.getComponentName().getClassName(), reason);
if (shouldSaveState && !isPreP) {
callActivityOnSaveInstanceState(r);
@@ -4169,12 +4160,12 @@ public final class ActivityThread extends ClientTransactionHandler {
@Override
public void handleStopActivity(IBinder token, boolean show, int configChanges,
PendingTransactionActions pendingActions) {
PendingTransactionActions pendingActions, String reason) {
final ActivityClientRecord r = mActivities.get(token);
r.activity.mConfigChangeFlags |= configChanges;
final StopInfo stopInfo = new StopInfo();
performStopActivityInner(r, stopInfo, show, true, "handleStopActivity");
performStopActivityInner(r, stopInfo, show, true, reason);
if (localLOGV) Slog.v(
TAG, "Finishing stop of " + r + ": show=" + show
@@ -4209,7 +4200,7 @@ public final class ActivityThread extends ClientTransactionHandler {
public void performRestartActivity(IBinder token, boolean start) {
ActivityClientRecord r = mActivities.get(token);
if (r.stopped) {
r.activity.performRestart(start);
r.activity.performRestart(start, "performRestartActivity");
if (start) {
r.setState(ON_START);
}
@@ -4232,7 +4223,7 @@ public final class ActivityThread extends ClientTransactionHandler {
// we are back active so skip it.
unscheduleGcIdler();
r.activity.performRestart(true /* start */);
r.activity.performRestart(true /* start */, "handleWindowVisibility");
r.setState(ON_START);
}
if (r.activity.mDecor != null) {
@@ -4272,7 +4263,7 @@ public final class ActivityThread extends ClientTransactionHandler {
}
} else {
if (r.stopped && r.activity.mVisibleFromServer) {
r.activity.performRestart(true /* start */);
r.activity.performRestart(true /* start */, "handleSleeping");
r.setState(ON_START);
}
}
@@ -4380,7 +4371,7 @@ public final class ActivityThread extends ClientTransactionHandler {
checkAndBlockForNetworkAccess();
deliverResults(r, results);
if (resumed) {
r.activity.performResume(false);
r.activity.performResume(false, "handleSendResult");
r.activity.mTemporaryPause = false;
}
}

View File

@@ -65,7 +65,8 @@ public abstract class ClientTransactionHandler {
/** Pause the activity. */
public abstract void handlePauseActivity(IBinder token, boolean finished, boolean userLeaving,
int configChanges, boolean dontReport, PendingTransactionActions pendingActions);
int configChanges, boolean dontReport, PendingTransactionActions pendingActions,
String reason);
/** Resume the activity. */
public abstract void handleResumeActivity(IBinder token, boolean clearHide, boolean isForward,
@@ -73,7 +74,7 @@ public abstract class ClientTransactionHandler {
/** Stop the activity. */
public abstract void handleStopActivity(IBinder token, boolean show, int configChanges,
PendingTransactionActions pendingActions);
PendingTransactionActions pendingActions, String reason);
/** Report that activity was stopped to server. */
public abstract void reportStop(PendingTransactionActions pendingActions);

View File

@@ -43,7 +43,7 @@ public class PauseActivityItem extends ActivityLifecycleItem {
PendingTransactionActions pendingActions) {
Trace.traceBegin(TRACE_TAG_ACTIVITY_MANAGER, "activityPause");
client.handlePauseActivity(token, mFinished, mUserLeaving, mConfigChanges, mDontReport,
pendingActions);
pendingActions, "PAUSE_ACTIVITY_ITEM");
Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER);
}

View File

@@ -38,7 +38,8 @@ public class StopActivityItem extends ActivityLifecycleItem {
public void execute(ClientTransactionHandler client, IBinder token,
PendingTransactionActions pendingActions) {
Trace.traceBegin(TRACE_TAG_ACTIVITY_MANAGER, "activityStop");
client.handleStopActivity(token, mShowWindow, mConfigChanges, pendingActions);
client.handleStopActivity(token, mShowWindow, mConfigChanges, pendingActions,
"STOP_ACTIVITY_ITEM");
Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER);
}

View File

@@ -186,11 +186,11 @@ public class TransactionExecutor {
case ON_PAUSE:
mTransactionHandler.handlePauseActivity(r.token, false /* finished */,
false /* userLeaving */, 0 /* configChanges */,
true /* dontReport */, mPendingActions);
true /* dontReport */, mPendingActions, "LIFECYCLER_PAUSE_ACTIVITY");
break;
case ON_STOP:
mTransactionHandler.handleStopActivity(r.token, false /* show */,
0 /* configChanges */, mPendingActions);
0 /* configChanges */, mPendingActions, "LIFECYCLER_STOP_ACTIVITY");
break;
case ON_DESTROY:
mTransactionHandler.handleDestroyActivity(r.token, false /* finishing */,

View File

@@ -125,3 +125,12 @@ option java_package com.android.server.am
30055 am_uid_idle (UID|1|5)
# Note when a service is being forcibly stopped because its app went idle.
30056 am_stop_idle_service (UID|1|5),(Component Name|3)
# The activity's onCreate has been called.
30057 am_on_create_called (User|1|5),(Component Name|3),(Reason|3)
# The activity's onRestart has been called.
30058 am_on_restart_called (User|1|5),(Component Name|3),(Reason|3)
# The activity's onStart has been called.
30059 am_on_start_called (User|1|5),(Component Name|3),(Reason|3)
# The activity's onDestroy has been called.
30060 am_on_destroy_called (User|1|5),(Component Name|3),(Reason|3)