Search in sources :

Example 26 with TraceMetric

use of com.google.firebase.perf.v1.TraceMetric in project firebase-android-sdk by firebase.

the class AppStateMonitorTest method testAppStateCallbackWithTrace.

@Test
public void testAppStateCallbackWithTrace() {
    AppStateMonitor monitor = new AppStateMonitor(transportManager, clock);
    Trace trace = new Trace("TRACE_1", transportManager, clock, monitor);
    // Trace is not started yet, default state is APPLICATION_PROCESS_STATE_UNKNOWN
    Assert.assertEquals(ApplicationProcessState.APPLICATION_PROCESS_STATE_UNKNOWN, trace.getAppState());
    // activity1 comes to foreground.
    currentTime = 1;
    // registerForAppState() is called by Trace.start().
    trace.start();
    // Trace started, get state from AppStateMonitor.
    Assert.assertEquals(ApplicationProcessState.BACKGROUND, trace.getAppState());
    monitor.onActivityResumed(activity1);
    Assert.assertTrue(monitor.isForeground());
    Assert.assertEquals(FOREGROUND_BACKGROUND, trace.getAppState());
    verify(transportManager, times(0)).log(argTraceMetric.capture(), nullable(ApplicationProcessState.class));
    // activity1 goes to background.
    currentTime = 2;
    monitor.onActivityStopped(activity1);
    Assert.assertFalse(monitor.isForeground());
    // Foreground session trace.
    verify(transportManager, times(1)).log(argTraceMetric.capture(), eq(FOREGROUND_BACKGROUND));
    // Trace is updated through AppStatCallback.
    Assert.assertEquals(FOREGROUND_BACKGROUND, trace.getAppState());
    // unregisterForAppState() is called by Trace.stop()
    trace.stop();
    // trace has been through FOREGROUND_BACKGROUND
    Assert.assertEquals(FOREGROUND_BACKGROUND, trace.getAppState());
    // a TraceMetric is sent for this trace object.
    verify(transportManager, times(2)).log(argTraceMetric.capture(), eq(FOREGROUND_BACKGROUND));
    TraceMetric metric = argTraceMetric.getValue();
    Assert.assertEquals("TRACE_1", metric.getName());
}
Also used : Trace(com.google.firebase.perf.metrics.Trace) ApplicationProcessState(com.google.firebase.perf.v1.ApplicationProcessState) TraceMetric(com.google.firebase.perf.v1.TraceMetric) Test(org.junit.Test)

Example 27 with TraceMetric

use of com.google.firebase.perf.v1.TraceMetric in project firebase-android-sdk by firebase.

the class FragmentStateMonitorTest method fragmentTraceCreation_noParentFragment_addsSpecialAttributeValue.

@Test
public void fragmentTraceCreation_noParentFragment_addsSpecialAttributeValue() {
    FragmentStateMonitor monitor = new FragmentStateMonitor(clock, mockTransportManager, appStateMonitor, recorder);
    when(recorder.stopFragment(any())).thenReturn(Optional.of(frameCounts1));
    monitor.onFragmentResumed(mockFragmentManager, mockFragment);
    monitor.onFragmentPaused(mockFragmentManager, mockFragment);
    verify(mockTransportManager, times(1)).log(argTraceMetric.capture(), any());
    TraceMetric metric = argTraceMetric.getValue();
    assertThat(metric.getCustomAttributesMap().get(Constants.PARENT_FRAGMENT_ATTRIBUTE_KEY)).isEqualTo(Constants.PARENT_FRAGMENT_ATTRIBUTE_VALUE_NONE);
}
Also used : TraceMetric(com.google.firebase.perf.v1.TraceMetric) Test(org.junit.Test)

Example 28 with TraceMetric

use of com.google.firebase.perf.v1.TraceMetric in project firebase-android-sdk by firebase.

the class FragmentStateMonitorTest method lifecycleCallbacks_differentFrameMetricsCapturedByFrameRecorder_logFragmentScreenTraceWithCorrectFrames.

@Test
public void lifecycleCallbacks_differentFrameMetricsCapturedByFrameRecorder_logFragmentScreenTraceWithCorrectFrames() {
    FragmentStateMonitor monitor = new FragmentStateMonitor(clock, mockTransportManager, appStateMonitor, recorder);
    when(recorder.stopFragment(any())).thenReturn(Optional.of(frameCounts1));
    monitor.onFragmentResumed(mockFragmentManager, mockFragment);
    verify(mockTransportManager, times(0)).log(any(TraceMetric.class), any());
    monitor.onFragmentPaused(mockFragmentManager, mockFragment);
    verify(mockTransportManager, times(1)).log(argTraceMetric.capture(), nullable(ApplicationProcessState.class));
    TraceMetric metric = argTraceMetric.getValue();
    assertThat((long) metric.getCountersMap().get(CounterNames.FRAMES_TOTAL.toString())).isEqualTo(frameCounts1.getTotalFrames());
    assertThat((long) metric.getCountersMap().get(CounterNames.FRAMES_SLOW.toString())).isEqualTo(frameCounts1.getSlowFrames());
    assertThat((long) metric.getCountersMap().get(CounterNames.FRAMES_FROZEN.toString())).isEqualTo(frameCounts1.getFrozenFrames());
}
Also used : TraceMetric(com.google.firebase.perf.v1.TraceMetric) ApplicationProcessState(com.google.firebase.perf.v1.ApplicationProcessState) Test(org.junit.Test)

Example 29 with TraceMetric

use of com.google.firebase.perf.v1.TraceMetric in project firebase-android-sdk by firebase.

the class FragmentStateMonitorTest method fragmentTraceCreation_hasParentFragment_addsParentFragmentAttribute.

@Test
public void fragmentTraceCreation_hasParentFragment_addsParentFragmentAttribute() {
    FragmentStateMonitor monitor = new FragmentStateMonitor(clock, mockTransportManager, appStateMonitor, recorder);
    when(recorder.stopFragment(any())).thenReturn(Optional.of(frameCounts1));
    Fragment mockParent = mock(Fragment.class);
    when(mockFragment.getParentFragment()).thenReturn(mockParent);
    monitor.onFragmentResumed(mockFragmentManager, mockFragment);
    monitor.onFragmentPaused(mockFragmentManager, mockFragment);
    verify(mockTransportManager, times(1)).log(argTraceMetric.capture(), any());
    TraceMetric metric = argTraceMetric.getValue();
    assertThat(metric.getCustomAttributesMap().get(Constants.PARENT_FRAGMENT_ATTRIBUTE_KEY)).isEqualTo("Fragment");
}
Also used : TraceMetric(com.google.firebase.perf.v1.TraceMetric) Fragment(androidx.fragment.app.Fragment) Test(org.junit.Test)

Example 30 with TraceMetric

use of com.google.firebase.perf.v1.TraceMetric in project firebase-android-sdk by firebase.

the class FirebasePerfTraceValidatorTest method testEmptyTraceId.

@Test
public void testEmptyTraceId() {
    TraceMetric trace = createValidTraceMetric().setName("").build();
    assertThat(new FirebasePerfTraceValidator(trace).isValidPerfMetric()).isFalse();
}
Also used : TraceMetric(com.google.firebase.perf.v1.TraceMetric) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)44 TraceMetric (com.google.firebase.perf.v1.TraceMetric)43 PerfMetric (com.google.firebase.perf.v1.PerfMetric)11 ApplicationProcessState (com.google.firebase.perf.v1.ApplicationProcessState)7 Trace (com.google.firebase.perf.metrics.Trace)2 GaugeMetric (com.google.firebase.perf.v1.GaugeMetric)2 NetworkRequestMetric (com.google.firebase.perf.v1.NetworkRequestMetric)2 PerfSession (com.google.firebase.perf.v1.PerfSession)2 Fragment (androidx.fragment.app.Fragment)1 AppStateMonitor (com.google.firebase.perf.application.AppStateMonitor)1 TransportManager (com.google.firebase.perf.transport.TransportManager)1