Search in sources :

Example 1 with PerfFrameMetrics

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);
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) MockitoAnnotations.initMocks(org.mockito.MockitoAnnotations.initMocks) TraceMetric(com.google.firebase.perf.v1.TraceMetric) ActivityController(org.robolectric.android.controller.ActivityController) PerfFrameMetrics(com.google.firebase.perf.metrics.FrameMetricsCalculator.PerfFrameMetrics) Bundle(android.os.Bundle) ArgumentMatchers.nullable(org.mockito.ArgumentMatchers.nullable) Mock(org.mockito.Mock) WindowManager(android.view.WindowManager) RunWith(org.junit.runner.RunWith) Mockito.spy(org.mockito.Mockito.spy) AppCompatActivity(androidx.appcompat.app.AppCompatActivity) Captor(org.mockito.Captor) Answer(org.mockito.stubbing.Answer) DeviceCacheManager(com.google.firebase.perf.config.DeviceCacheManager) Constants(com.google.firebase.perf.util.Constants) ArgumentCaptor(org.mockito.ArgumentCaptor) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Fragment(androidx.fragment.app.Fragment) ApplicationProcessState(com.google.firebase.perf.v1.ApplicationProcessState) Mockito.doReturn(org.mockito.Mockito.doReturn) FirebasePerformanceTestBase(com.google.firebase.perf.FirebasePerformanceTestBase) WeakHashMap(java.util.WeakHashMap) ConfigResolver(com.google.firebase.perf.config.ConfigResolver) Before(org.junit.Before) FragmentManager(androidx.fragment.app.FragmentManager) Timer(com.google.firebase.perf.util.Timer) Clock(com.google.firebase.perf.util.Clock) Robolectric(org.robolectric.Robolectric) Trace(com.google.firebase.perf.metrics.Trace) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) Mockito.doNothing(org.mockito.Mockito.doNothing) Mockito.when(org.mockito.Mockito.when) Truth.assertThat(com.google.common.truth.Truth.assertThat) TransportManager(com.google.firebase.perf.transport.TransportManager) Mockito.verify(org.mockito.Mockito.verify) RobolectricTestRunner(org.robolectric.RobolectricTestRunner) CounterNames(com.google.firebase.perf.util.Constants.CounterNames) Optional(com.google.firebase.perf.util.Optional) Activity(android.app.Activity) Mockito.mock(org.mockito.Mockito.mock) Timer(com.google.firebase.perf.util.Timer) Bundle(android.os.Bundle) PerfFrameMetrics(com.google.firebase.perf.metrics.FrameMetricsCalculator.PerfFrameMetrics) Fragment(androidx.fragment.app.Fragment) Before(org.junit.Before)

Example 2 with PerfFrameMetrics

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();
}
Also used : PerfFrameMetrics(com.google.firebase.perf.metrics.FrameMetricsCalculator.PerfFrameMetrics) Fragment(androidx.fragment.app.Fragment) Test(org.junit.Test)

Example 3 with PerfFrameMetrics

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);
}
Also used : PerfFrameMetrics(com.google.firebase.perf.metrics.FrameMetricsCalculator.PerfFrameMetrics) Fragment(androidx.fragment.app.Fragment) Test(org.junit.Test)

Example 4 with PerfFrameMetrics

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);
}
Also used : PerfFrameMetrics(com.google.firebase.perf.metrics.FrameMetricsCalculator.PerfFrameMetrics) Fragment(androidx.fragment.app.Fragment) Test(org.junit.Test)

Example 5 with PerfFrameMetrics

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();
}
Also used : PerfFrameMetrics(com.google.firebase.perf.metrics.FrameMetricsCalculator.PerfFrameMetrics) Fragment(androidx.fragment.app.Fragment) Test(org.junit.Test)

Aggregations

PerfFrameMetrics (com.google.firebase.perf.metrics.FrameMetricsCalculator.PerfFrameMetrics)11 Fragment (androidx.fragment.app.Fragment)8 Test (org.junit.Test)8 Trace (com.google.firebase.perf.metrics.Trace)3 Activity (android.app.Activity)1 Bundle (android.os.Bundle)1 WindowManager (android.view.WindowManager)1 AppCompatActivity (androidx.appcompat.app.AppCompatActivity)1 FragmentManager (androidx.fragment.app.FragmentManager)1 Truth.assertThat (com.google.common.truth.Truth.assertThat)1 FirebasePerformanceTestBase (com.google.firebase.perf.FirebasePerformanceTestBase)1 ConfigResolver (com.google.firebase.perf.config.ConfigResolver)1 DeviceCacheManager (com.google.firebase.perf.config.DeviceCacheManager)1 TransportManager (com.google.firebase.perf.transport.TransportManager)1 Clock (com.google.firebase.perf.util.Clock)1 Constants (com.google.firebase.perf.util.Constants)1 CounterNames (com.google.firebase.perf.util.Constants.CounterNames)1 Optional (com.google.firebase.perf.util.Optional)1 Timer (com.google.firebase.perf.util.Timer)1 ApplicationProcessState (com.google.firebase.perf.v1.ApplicationProcessState)1