LifecycleEventDataSeries implements DataSeries<EventAction<LifecycleEvent>> { @Override public List<SeriesData<EventAction<LifecycleEvent>>> getDataForRange(@NotNull Range timeCurrentRangeUs) { if (myProfilers.getIdeServices().getFeatureConfig().isUnifiedPipelineEnabled()) { return getTransportData(timeCurrentRangeUs); } else { return getLegacyData(timeCurrentRangeUs); } } LifecycleEventDataSeries(@NotNull StudioProfilers profilers, boolean fragmentOnly); @Override List<SeriesData<EventAction<LifecycleEvent>>> getDataForRange(@NotNull Range timeCurrentRangeUs);  }
@Test public void testActivityStarted() { buildActivityEvent(ACTIVITY_NAME, new ActivityStateData[]{ new ActivityStateData(Interaction.ViewData.State.CREATED, TEST_START_TIME_NS), new ActivityStateData(Interaction.ViewData.State.RESUMED, TEST_START_TIME_NS), }, 0); Range range = new Range(TimeUnit.NANOSECONDS.toMicros(TEST_START_TIME_NS), TimeUnit.NANOSECONDS.toMicros(TEST_END_TIME_NS)); List<SeriesData<EventAction<LifecycleEvent>>> dataList = myActivitySeries.getDataForRange(range); assertThat(dataList).hasSize(1); SeriesData<EventAction<LifecycleEvent>> event = dataList.get(0); verifyActivity(event, 0); assertThat(event.value.getType()).isEqualTo(LifecycleEvent.STARTED); assertThat(((LifecycleAction)event.value).getName()).isEqualTo(ACTIVITY_NAME); }
@Test public void testActivityCompleted() { buildActivityEvent(ACTIVITY_NAME, new ActivityStateData[]{ new ActivityStateData(Interaction.ViewData.State.CREATED, TEST_START_TIME_NS), new ActivityStateData(Interaction.ViewData.State.RESUMED, TEST_START_TIME_NS), new ActivityStateData(Interaction.ViewData.State.PAUSED, TEST_END_TIME_NS), new ActivityStateData(Interaction.ViewData.State.DESTROYED, TEST_END_TIME_NS), }, 0); Range range = new Range(TimeUnit.NANOSECONDS.toMicros(TEST_START_TIME_NS), TimeUnit.NANOSECONDS.toMicros(TEST_END_TIME_NS)); List<SeriesData<EventAction<LifecycleEvent>>> dataList = myActivitySeries.getDataForRange(range); assertThat(dataList).hasSize(1); SeriesData<EventAction<LifecycleEvent>> event = dataList.get(0); verifyActivity(event, TEST_END_TIME_NS); assertThat(event.value.getType()).isEqualTo(LifecycleEvent.COMPLETED); assertThat(((LifecycleAction)event.value).getName()).isEqualTo( String.format("%s - %s", ACTIVITY_NAME, Interaction.ViewData.State.DESTROYED.toString().toLowerCase())); }
@Test public void testActivityDied() { buildActivityEvent(ACTIVITY_NAME, new ActivityStateData[]{ new ActivityStateData(Interaction.ViewData.State.CREATED, TEST_START_TIME_NS), new ActivityStateData(Interaction.ViewData.State.RESUMED, TEST_START_TIME_NS), new ActivityStateData(Interaction.ViewData.State.PAUSED, TEST_END_TIME_NS), new ActivityStateData(Interaction.ViewData.State.STOPPED, TEST_END_TIME_NS), new ActivityStateData(Interaction.ViewData.State.DESTROYED, TEST_END_TIME_NS), }, 0); Range range = new Range(TimeUnit.NANOSECONDS.toMicros(TEST_START_TIME_NS), TimeUnit.NANOSECONDS.toMicros(TEST_END_TIME_NS)); List<SeriesData<EventAction<LifecycleEvent>>> dataList = myActivitySeries.getDataForRange(range); assertThat(dataList).hasSize(1); SeriesData<EventAction<LifecycleEvent>> event = dataList.get(0); verifyActivity(event, TEST_END_TIME_NS); assertThat(event.value.getType()).isEqualTo(LifecycleEvent.COMPLETED); assertThat(((LifecycleAction)event.value).getName()).isEqualTo( String.format("%s - %s - %s", ACTIVITY_NAME, Interaction.ViewData.State.STOPPED.toString().toLowerCase(), Interaction.ViewData.State.DESTROYED.toString().toLowerCase())); }
@Test public void testActivityDiedThenResumed() { buildActivityEvent(ACTIVITY_NAME, new ActivityStateData[]{ new ActivityStateData(Interaction.ViewData.State.CREATED, TEST_START_TIME_NS), new ActivityStateData(Interaction.ViewData.State.RESUMED, TEST_START_TIME_NS), new ActivityStateData(Interaction.ViewData.State.PAUSED, TEST_START_TIME_NS), new ActivityStateData(Interaction.ViewData.State.DESTROYED, TEST_START_TIME_NS), new ActivityStateData(Interaction.ViewData.State.REMOVED, TEST_START_TIME_NS), new ActivityStateData(Interaction.ViewData.State.CREATED, TEST_START_TIME_NS), new ActivityStateData(Interaction.ViewData.State.RESUMED, TEST_START_TIME_NS), new ActivityStateData(Interaction.ViewData.State.PAUSED, TEST_END_TIME_NS), new ActivityStateData(Interaction.ViewData.State.DESTROYED, TEST_END_TIME_NS), }, 0); Range range = new Range(TimeUnit.NANOSECONDS.toMicros(TEST_START_TIME_NS), TimeUnit.NANOSECONDS.toMicros(TEST_END_TIME_NS)); List<SeriesData<EventAction<LifecycleEvent>>> dataList = myActivitySeries.getDataForRange(range); assertThat(dataList).hasSize(2); SeriesData<EventAction<LifecycleEvent>> event = dataList.get(0); verifyActivity(event, TEST_START_TIME_NS); assertThat(event.value.getType()).isEqualTo(LifecycleEvent.COMPLETED); assertThat(((LifecycleAction)event.value).getName()).isEqualTo( String.format("%s - %s - %s", ACTIVITY_NAME, Interaction.ViewData.State.DESTROYED.toString().toLowerCase(), Interaction.ViewData.State.REMOVED.toString().toLowerCase())); event = dataList.get(1); verifyActivity(event, TEST_END_TIME_NS); assertThat(event.value.getType()).isEqualTo(LifecycleEvent.COMPLETED); assertThat(((LifecycleAction)event.value).getName()).isEqualTo( String.format("%s - %s", ACTIVITY_NAME, Interaction.ViewData.State.DESTROYED.toString().toLowerCase())); }
@Test public void testActivityDestroyedDisplayString() { buildActivityEvent(ACTIVITY_NAME, new ActivityStateData[]{ new ActivityStateData(Interaction.ViewData.State.CREATED, TEST_START_TIME_NS), new ActivityStateData(Interaction.ViewData.State.DESTROYED, TEST_START_TIME_NS), }, 0); Range range = new Range(TimeUnit.NANOSECONDS.toMicros(TEST_START_TIME_NS), TimeUnit.NANOSECONDS.toMicros(TEST_END_TIME_NS)); List<SeriesData<EventAction<LifecycleEvent>>> dataList = myActivitySeries.getDataForRange(range); assertThat(dataList).hasSize(1); SeriesData<EventAction<LifecycleEvent>> event = dataList.get(0); assertThat(event.value.getType()).isEqualTo(LifecycleEvent.COMPLETED); assertThat(((LifecycleAction)event.value).getName()).isEqualTo( String.format("%s - %s", ACTIVITY_NAME, Interaction.ViewData.State.DESTROYED.toString().toLowerCase())); }
@Test public void testDestroyedEventOutOfOrder() { buildActivityEvent(ACTIVITY_NAME, new ActivityStateData[]{ new ActivityStateData(Interaction.ViewData.State.CREATED, TEST_START_TIME_NS), new ActivityStateData(Interaction.ViewData.State.DESTROYED, TEST_START_TIME_NS), new ActivityStateData(Interaction.ViewData.State.PAUSED, TEST_START_TIME_NS), }, 0); Range range = new Range(TimeUnit.NANOSECONDS.toMicros(TEST_START_TIME_NS), TimeUnit.NANOSECONDS.toMicros(TEST_END_TIME_NS)); List<SeriesData<EventAction<LifecycleEvent>>> dataList = myActivitySeries.getDataForRange(range); assertThat(dataList).hasSize(1); SeriesData<EventAction<LifecycleEvent>> event = dataList.get(0); assertThat(event.value.getType()).isEqualTo(LifecycleEvent.COMPLETED); assertThat(((LifecycleAction)event.value).getName()).isEqualTo(ACTIVITY_NAME); }
@Test public void testMultipleActivity() { buildActivityEvent(ACTIVITY_NAME, new ActivityStateData[]{ new ActivityStateData(Interaction.ViewData.State.CREATED, TEST_START_TIME_NS), new ActivityStateData(Interaction.ViewData.State.RESUMED, TEST_START_TIME_NS), }, 0); buildActivityEvent(ACTIVITY_NAME_2, new ActivityStateData[]{ new ActivityStateData(Interaction.ViewData.State.CREATED, TEST_START_TIME_NS), new ActivityStateData(Interaction.ViewData.State.RESUMED, TEST_START_TIME_NS), new ActivityStateData(Interaction.ViewData.State.PAUSED, TEST_END_TIME_NS), new ActivityStateData(Interaction.ViewData.State.DESTROYED, TEST_END_TIME_NS), }, 0); Range range = new Range(TimeUnit.NANOSECONDS.toMicros(TEST_START_TIME_NS), TimeUnit.NANOSECONDS.toMicros(TEST_END_TIME_NS)); List<SeriesData<EventAction<LifecycleEvent>>> dataList = myActivitySeries.getDataForRange(range); assertThat(dataList).hasSize(2); SeriesData<EventAction<LifecycleEvent>> event = dataList.get(0); verifyActivity(event, 0); assertThat(event.value.getType()).isEqualTo(LifecycleEvent.STARTED); assertThat(((LifecycleAction)event.value).getName()).isEqualTo(ACTIVITY_NAME); event = dataList.get(1); verifyActivity(event, TEST_END_TIME_NS); assertThat(event.value.getType()).isEqualTo(LifecycleEvent.COMPLETED); assertThat(((LifecycleAction)event.value).getName()).isEqualTo( String.format("%s - %s", ACTIVITY_NAME_2, Interaction.ViewData.State.DESTROYED.toString().toLowerCase())); }
@Test public void testOnlyFragmentReceived() { buildActivityEvent(FRAGMENT_NAME, new ActivityStateData[]{ new ActivityStateData(Interaction.ViewData.State.RESUMED, TEST_START_TIME_NS), new ActivityStateData(Interaction.ViewData.State.PAUSED, TEST_END_TIME_NS), }, 1234 ); buildActivityEvent(ACTIVITY_NAME, new ActivityStateData[]{ new ActivityStateData(Interaction.ViewData.State.RESUMED, TEST_START_TIME_NS), new ActivityStateData(Interaction.ViewData.State.PAUSED, TEST_END_TIME_NS), }, 0 ); Range range = new Range(TimeUnit.NANOSECONDS.toMicros(TEST_START_TIME_NS), TimeUnit.NANOSECONDS.toMicros(TEST_END_TIME_NS)); List<SeriesData<EventAction<LifecycleEvent>>> dataList = myFragmentSeries.getDataForRange(range); assertThat(dataList).hasSize(1); SeriesData<EventAction<LifecycleEvent>> event = dataList.get(0); verifyActivity(event, TEST_END_TIME_NS); assertThat(event.value.getType()).isEqualTo(LifecycleEvent.COMPLETED); assertThat(((LifecycleAction)event.value).getName()).isEqualTo(FRAGMENT_NAME); }