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());
}
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);
}
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());
}
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");
}
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();
}
Aggregations