use of com.google.firebase.perf.metrics.FrameMetricsCalculator.PerfFrameMetrics in project firebase-android-sdk by firebase.
the class FragmentStateMonitorTest method setUp.
@Before
public void setUp() {
currentTime = 0;
initMocks(this);
doAnswer((Answer<Timer>) invocationOnMock -> new Timer(currentTime)).when(clock).getTime();
DeviceCacheManager.clearInstance();
when(configResolver.isPerformanceMonitoringEnabled()).thenReturn(true);
doNothing().when(recorder).start();
doNothing().when(recorder).startFragment(any());
activity = createFakeActivity(true);
// Sample frame counts.
frameCounts1 = new PerfFrameMetrics(9, 5, 3);
frameCounts2 = new PerfFrameMetrics(14, 9, 4);
savedInstanceState = mock(Bundle.class);
appStateMonitor = mock(AppStateMonitor.class);
mockFragment1 = mock(Fragment.class);
mockFragment2 = mock(Fragment.class);
}
use of com.google.firebase.perf.metrics.FrameMetricsCalculator.PerfFrameMetrics in project firebase-android-sdk by firebase.
the class FrameMetricsRecorderTest method startAndStopSubTrace_activityRecordingHasEnded_returnsEmptyResult.
@Test
public void startAndStopSubTrace_activityRecordingHasEnded_returnsEmptyResult() {
Fragment fragment = new Fragment();
recorder.start();
recorder.stop();
stubFrameMetricsAggregatorData(fma, frameTimes1);
recorder.startFragment(fragment);
stubFrameMetricsAggregatorData(fma, frameTimes2);
Optional<PerfFrameMetrics> result = recorder.stopFragment(fragment);
assertThat(result.isAvailable()).isFalse();
}
use of com.google.firebase.perf.metrics.FrameMetricsCalculator.PerfFrameMetrics in project firebase-android-sdk by firebase.
the class FrameMetricsRecorderTest method startAndStopSubTrace_whenTwoSubTracesOverlap_returnsCorrectResults.
@Test
public void startAndStopSubTrace_whenTwoSubTracesOverlap_returnsCorrectResults() {
Fragment fragment1 = new Fragment();
Fragment fragment2 = new Fragment();
recorder.start();
// comments are in this format: total frames, slow frames, frozen frames
// 3, 2, 1
stubFrameMetricsAggregatorData(fma, new int[][] { { 1, 1 }, { 17, 1 }, { 800, 1 } });
recorder.startFragment(fragment1);
// 7, 5, 2
stubFrameMetricsAggregatorData(fma, new int[][] { { 1, 2 }, { 17, 3 }, { 800, 2 } });
recorder.startFragment(fragment2);
// 14, 9, 5
stubFrameMetricsAggregatorData(fma, new int[][] { { 1, 5 }, { 17, 4 }, { 800, 5 } });
Optional<PerfFrameMetrics> subTrace1 = recorder.stopFragment(fragment1);
// 16, 10, 5
stubFrameMetricsAggregatorData(fma, new int[][] { { 1, 6 }, { 17, 5 }, { 800, 5 } });
Optional<PerfFrameMetrics> subTrace2 = recorder.stopFragment(fragment2);
// 3rd snapshot - 1st snapshot
assertThat(subTrace1.get().getTotalFrames()).isEqualTo(14 - 3);
assertThat(subTrace1.get().getSlowFrames()).isEqualTo(9 - 2);
assertThat(subTrace1.get().getFrozenFrames()).isEqualTo(5 - 1);
// 4th snapshot - 2nd snapshot
assertThat(subTrace2.get().getTotalFrames()).isEqualTo(16 - 7);
assertThat(subTrace2.get().getSlowFrames()).isEqualTo(10 - 5);
assertThat(subTrace2.get().getFrozenFrames()).isEqualTo(5 - 2);
}
use of com.google.firebase.perf.metrics.FrameMetricsCalculator.PerfFrameMetrics in project firebase-android-sdk by firebase.
the class FrameMetricsRecorderTest method startAndStopSubTrace_duringActivityRecording_returnsValidResult.
@Test
public void startAndStopSubTrace_duringActivityRecording_returnsValidResult() {
Fragment fragment = new Fragment();
recorder.start();
stubFrameMetricsAggregatorData(fma, frameTimes1);
recorder.startFragment(fragment);
stubFrameMetricsAggregatorData(fma, frameTimes2);
Optional<PerfFrameMetrics> result = recorder.stopFragment(fragment);
assertThat(result.isAvailable()).isTrue();
// frameTimes2 - frameTimes1
assertThat(result.get().getTotalFrames()).isEqualTo(9);
assertThat(result.get().getSlowFrames()).isEqualTo(5);
assertThat(result.get().getFrozenFrames()).isEqualTo(3);
}
use of com.google.firebase.perf.metrics.FrameMetricsCalculator.PerfFrameMetrics in project firebase-android-sdk by firebase.
the class FrameMetricsRecorderTest method stopAndStopSubTrace_whenNoSubTraceWithGivenKeyExists_returnsEmptyResult.
@Test
public void stopAndStopSubTrace_whenNoSubTraceWithGivenKeyExists_returnsEmptyResult() {
Fragment fragment1 = new Fragment();
Fragment fragment2 = new Fragment();
recorder.start();
recorder.startFragment(fragment1);
Optional<PerfFrameMetrics> result = recorder.stopFragment(fragment2);
assertThat(result.isAvailable()).isFalse();
}
Aggregations