Loading startop/iorap/src/com/google/android/startop/iorap/EventSequenceValidator.java +25 −16 Original line number Diff line number Diff line Loading @@ -23,6 +23,9 @@ import android.util.Log; import com.android.server.wm.ActivityMetricsLaunchObserver; import java.io.StringWriter; import java.io.PrintWriter; /** * A validator to check the correctness of event sequence during app startup. * Loading Loading @@ -100,7 +103,7 @@ public class EventSequenceValidator implements ActivityMetricsLaunchObserver { @Override public void onIntentStarted(@NonNull Intent intent, long timestampNs) { if (state == State.UNKNOWN) { Log.wtf(TAG, "IntentStarted during UNKNOWN." + intent); logWarningWithStackTrace("IntentStarted during UNKNOWN. " + intent); incAccIntentStartedEvents(); return; } Loading @@ -110,7 +113,7 @@ public class EventSequenceValidator implements ActivityMetricsLaunchObserver { state != State.ACTIVITY_CANCELLED && state != State.ACTIVITY_FINISHED && state != State.REPORT_FULLY_DRAWN) { Log.wtf(TAG, logWarningWithStackTrace( String.format("Cannot transition from %s to %s", state, State.INTENT_STARTED)); incAccIntentStartedEvents(); incAccIntentStartedEvents(); Loading @@ -124,12 +127,12 @@ public class EventSequenceValidator implements ActivityMetricsLaunchObserver { @Override public void onIntentFailed() { if (state == State.UNKNOWN) { Log.wtf(TAG, "IntentFailed during UNKNOWN."); logWarningWithStackTrace("onIntentFailed during UNKNOWN."); decAccIntentStartedEvents(); return; } if (state != State.INTENT_STARTED) { Log.wtf(TAG, logWarningWithStackTrace( String.format("Cannot transition from %s to %s", state, State.INTENT_FAILED)); incAccIntentStartedEvents(); return; Loading @@ -143,11 +146,11 @@ public class EventSequenceValidator implements ActivityMetricsLaunchObserver { public void onActivityLaunched(@NonNull @ActivityRecordProto byte[] activity, @Temperature int temperature) { if (state == State.UNKNOWN) { Log.wtf(TAG, "onActivityLaunched during UNKNOWN."); logWarningWithStackTrace("onActivityLaunched during UNKNOWN."); return; } if (state != State.INTENT_STARTED) { Log.wtf(TAG, logWarningWithStackTrace( String.format("Cannot transition from %s to %s", state, State.ACTIVITY_LAUNCHED)); incAccIntentStartedEvents(); return; Loading @@ -160,12 +163,12 @@ public class EventSequenceValidator implements ActivityMetricsLaunchObserver { @Override public void onActivityLaunchCancelled(@Nullable @ActivityRecordProto byte[] activity) { if (state == State.UNKNOWN) { Log.wtf(TAG, "onActivityLaunchCancelled during UNKNOWN."); logWarningWithStackTrace("onActivityLaunchCancelled during UNKNOWN."); decAccIntentStartedEvents(); return; } if (state != State.ACTIVITY_LAUNCHED) { Log.wtf(TAG, logWarningWithStackTrace( String.format("Cannot transition from %s to %s", state, State.ACTIVITY_CANCELLED)); incAccIntentStartedEvents(); return; Loading @@ -179,13 +182,13 @@ public class EventSequenceValidator implements ActivityMetricsLaunchObserver { public void onActivityLaunchFinished(@NonNull @ActivityRecordProto byte[] activity, long timestampNs) { if (state == State.UNKNOWN) { Log.wtf(TAG, "onActivityLaunchFinished during UNKNOWN."); logWarningWithStackTrace("onActivityLaunchFinished during UNKNOWN."); decAccIntentStartedEvents(); return; } if (state != State.ACTIVITY_LAUNCHED) { Log.wtf(TAG, logWarningWithStackTrace( String.format("Cannot transition from %s to %s", state, State.ACTIVITY_FINISHED)); incAccIntentStartedEvents(); return; Loading @@ -199,7 +202,7 @@ public class EventSequenceValidator implements ActivityMetricsLaunchObserver { public void onReportFullyDrawn(@NonNull @ActivityRecordProto byte[] activity, long timestampNs) { if (state == State.UNKNOWN) { Log.wtf(TAG, "onReportFullyDrawn during UNKNOWN."); logWarningWithStackTrace("onReportFullyDrawn during UNKNOWN."); return; } if (state == State.INIT) { Loading @@ -207,7 +210,7 @@ public class EventSequenceValidator implements ActivityMetricsLaunchObserver { } if (state != State.ACTIVITY_FINISHED) { Log.wtf(TAG, logWarningWithStackTrace( String.format("Cannot transition from %s to %s", state, State.REPORT_FULLY_DRAWN)); return; } Loading @@ -229,8 +232,7 @@ public class EventSequenceValidator implements ActivityMetricsLaunchObserver { private void incAccIntentStartedEvents() { if (accIntentStartedEvents < 0) { throw new AssertionError( String.format("The number of unknowns cannot be negative")); throw new AssertionError("The number of unknowns cannot be negative"); } if (accIntentStartedEvents == 0) { state = State.UNKNOWN; Loading @@ -242,8 +244,7 @@ public class EventSequenceValidator implements ActivityMetricsLaunchObserver { private void decAccIntentStartedEvents() { if (accIntentStartedEvents <= 0) { throw new AssertionError( String.format("The number of unknowns cannot be negative")); throw new AssertionError("The number of unknowns cannot be negative"); } if(accIntentStartedEvents == 1) { state = State.INIT; Loading @@ -252,4 +253,12 @@ public class EventSequenceValidator implements ActivityMetricsLaunchObserver { Log.i(TAG, String.format("dec AccIntentStartedEvents to %d", accIntentStartedEvents)); } private void logWarningWithStackTrace(String log) { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); new Throwable("EventSequenceValidator#getStackTrace").printStackTrace(pw); Log.wtf(TAG, String.format("%s\n%s", log, sw)); } } Loading
startop/iorap/src/com/google/android/startop/iorap/EventSequenceValidator.java +25 −16 Original line number Diff line number Diff line Loading @@ -23,6 +23,9 @@ import android.util.Log; import com.android.server.wm.ActivityMetricsLaunchObserver; import java.io.StringWriter; import java.io.PrintWriter; /** * A validator to check the correctness of event sequence during app startup. * Loading Loading @@ -100,7 +103,7 @@ public class EventSequenceValidator implements ActivityMetricsLaunchObserver { @Override public void onIntentStarted(@NonNull Intent intent, long timestampNs) { if (state == State.UNKNOWN) { Log.wtf(TAG, "IntentStarted during UNKNOWN." + intent); logWarningWithStackTrace("IntentStarted during UNKNOWN. " + intent); incAccIntentStartedEvents(); return; } Loading @@ -110,7 +113,7 @@ public class EventSequenceValidator implements ActivityMetricsLaunchObserver { state != State.ACTIVITY_CANCELLED && state != State.ACTIVITY_FINISHED && state != State.REPORT_FULLY_DRAWN) { Log.wtf(TAG, logWarningWithStackTrace( String.format("Cannot transition from %s to %s", state, State.INTENT_STARTED)); incAccIntentStartedEvents(); incAccIntentStartedEvents(); Loading @@ -124,12 +127,12 @@ public class EventSequenceValidator implements ActivityMetricsLaunchObserver { @Override public void onIntentFailed() { if (state == State.UNKNOWN) { Log.wtf(TAG, "IntentFailed during UNKNOWN."); logWarningWithStackTrace("onIntentFailed during UNKNOWN."); decAccIntentStartedEvents(); return; } if (state != State.INTENT_STARTED) { Log.wtf(TAG, logWarningWithStackTrace( String.format("Cannot transition from %s to %s", state, State.INTENT_FAILED)); incAccIntentStartedEvents(); return; Loading @@ -143,11 +146,11 @@ public class EventSequenceValidator implements ActivityMetricsLaunchObserver { public void onActivityLaunched(@NonNull @ActivityRecordProto byte[] activity, @Temperature int temperature) { if (state == State.UNKNOWN) { Log.wtf(TAG, "onActivityLaunched during UNKNOWN."); logWarningWithStackTrace("onActivityLaunched during UNKNOWN."); return; } if (state != State.INTENT_STARTED) { Log.wtf(TAG, logWarningWithStackTrace( String.format("Cannot transition from %s to %s", state, State.ACTIVITY_LAUNCHED)); incAccIntentStartedEvents(); return; Loading @@ -160,12 +163,12 @@ public class EventSequenceValidator implements ActivityMetricsLaunchObserver { @Override public void onActivityLaunchCancelled(@Nullable @ActivityRecordProto byte[] activity) { if (state == State.UNKNOWN) { Log.wtf(TAG, "onActivityLaunchCancelled during UNKNOWN."); logWarningWithStackTrace("onActivityLaunchCancelled during UNKNOWN."); decAccIntentStartedEvents(); return; } if (state != State.ACTIVITY_LAUNCHED) { Log.wtf(TAG, logWarningWithStackTrace( String.format("Cannot transition from %s to %s", state, State.ACTIVITY_CANCELLED)); incAccIntentStartedEvents(); return; Loading @@ -179,13 +182,13 @@ public class EventSequenceValidator implements ActivityMetricsLaunchObserver { public void onActivityLaunchFinished(@NonNull @ActivityRecordProto byte[] activity, long timestampNs) { if (state == State.UNKNOWN) { Log.wtf(TAG, "onActivityLaunchFinished during UNKNOWN."); logWarningWithStackTrace("onActivityLaunchFinished during UNKNOWN."); decAccIntentStartedEvents(); return; } if (state != State.ACTIVITY_LAUNCHED) { Log.wtf(TAG, logWarningWithStackTrace( String.format("Cannot transition from %s to %s", state, State.ACTIVITY_FINISHED)); incAccIntentStartedEvents(); return; Loading @@ -199,7 +202,7 @@ public class EventSequenceValidator implements ActivityMetricsLaunchObserver { public void onReportFullyDrawn(@NonNull @ActivityRecordProto byte[] activity, long timestampNs) { if (state == State.UNKNOWN) { Log.wtf(TAG, "onReportFullyDrawn during UNKNOWN."); logWarningWithStackTrace("onReportFullyDrawn during UNKNOWN."); return; } if (state == State.INIT) { Loading @@ -207,7 +210,7 @@ public class EventSequenceValidator implements ActivityMetricsLaunchObserver { } if (state != State.ACTIVITY_FINISHED) { Log.wtf(TAG, logWarningWithStackTrace( String.format("Cannot transition from %s to %s", state, State.REPORT_FULLY_DRAWN)); return; } Loading @@ -229,8 +232,7 @@ public class EventSequenceValidator implements ActivityMetricsLaunchObserver { private void incAccIntentStartedEvents() { if (accIntentStartedEvents < 0) { throw new AssertionError( String.format("The number of unknowns cannot be negative")); throw new AssertionError("The number of unknowns cannot be negative"); } if (accIntentStartedEvents == 0) { state = State.UNKNOWN; Loading @@ -242,8 +244,7 @@ public class EventSequenceValidator implements ActivityMetricsLaunchObserver { private void decAccIntentStartedEvents() { if (accIntentStartedEvents <= 0) { throw new AssertionError( String.format("The number of unknowns cannot be negative")); throw new AssertionError("The number of unknowns cannot be negative"); } if(accIntentStartedEvents == 1) { state = State.INIT; Loading @@ -252,4 +253,12 @@ public class EventSequenceValidator implements ActivityMetricsLaunchObserver { Log.i(TAG, String.format("dec AccIntentStartedEvents to %d", accIntentStartedEvents)); } private void logWarningWithStackTrace(String log) { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); new Throwable("EventSequenceValidator#getStackTrace").printStackTrace(pw); Log.wtf(TAG, String.format("%s\n%s", log, sw)); } }