Search in sources :

Example 36 with TraceMetric

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

the class FirebasePerfTraceValidatorTest method createValidTraceMetric.

private TraceMetric.Builder createValidTraceMetric() {
    String traceName = "trace_1";
    long expectedClientStartTime = 1;
    long expectedTraceDuration = 50;
    TransportManager transportManager = mock(TransportManager.class);
    AppStateMonitor appStateMonitor = mock(AppStateMonitor.class);
    ArgumentCaptor<TraceMetric> argMetric = ArgumentCaptor.forClass(TraceMetric.class);
    Trace trace = new Trace(traceName, transportManager, clock, appStateMonitor);
    currentTime = expectedClientStartTime;
    trace.start();
    currentTime += expectedTraceDuration;
    trace.stop();
    verify(transportManager).log(argMetric.capture(), ArgumentMatchers.nullable(ApplicationProcessState.class));
    TraceMetric traceMetric = argMetric.getValue();
    assertThat(traceMetric.getName()).isEqualTo(traceName);
    assertThat(traceMetric.getClientStartTimeUs()).isEqualTo(expectedClientStartTime);
    assertThat(traceMetric.getDurationUs()).isEqualTo(expectedTraceDuration);
    return traceMetric.toBuilder();
}
Also used : Trace(com.google.firebase.perf.metrics.Trace) TraceMetric(com.google.firebase.perf.v1.TraceMetric) ApplicationProcessState(com.google.firebase.perf.v1.ApplicationProcessState) AppStateMonitor(com.google.firebase.perf.application.AppStateMonitor) TransportManager(com.google.firebase.perf.transport.TransportManager)

Example 37 with TraceMetric

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

the class TraceMetricBuilderTest method testUpdatingCustomAttributes.

@Test
public void testUpdatingCustomAttributes() {
    Trace trace = new Trace(TRACE_1, transportManager, clock, appStateMonitor);
    currentTime = 1;
    trace.start();
    currentTime = 2;
    trace.startStage(TRACE_2);
    trace.putAttribute(TRACE_ATTRIBUTE_KEY, TRACE_ATTRIBUTE_VALUE);
    currentTime = 3;
    trace.putAttribute(TRACE_ATTRIBUTE_KEY, TRACE_ATTRIBUTE_VALUE + "New");
    trace.stop();
    TraceMetric traceMetric = new TraceMetricBuilder(trace).build();
    Assert.assertEquals(TRACE_ATTRIBUTE_VALUE + "New", trace.getAttribute(TRACE_ATTRIBUTE_KEY));
    Assert.assertEquals(TRACE_1, traceMetric.getName());
    Assert.assertEquals(1, traceMetric.getCustomAttributesCount());
}
Also used : TraceMetric(com.google.firebase.perf.v1.TraceMetric) Test(org.junit.Test)

Example 38 with TraceMetric

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

the class TraceMetricBuilderTest method testAddingMoreThanMaxLocalAttributes.

@Test
public void testAddingMoreThanMaxLocalAttributes() {
    Trace trace = new Trace(TRACE_1, transportManager, clock, appStateMonitor);
    currentTime = 1;
    trace.start();
    currentTime = 2;
    for (int i = 0; i <= Constants.MAX_TRACE_CUSTOM_ATTRIBUTES; i++) {
        trace.putAttribute(TRACE_ATTRIBUTE_KEY + i, TRACE_ATTRIBUTE_VALUE + i);
    }
    trace.stop();
    TraceMetric traceMetric = new TraceMetricBuilder(trace).build();
    Assert.assertEquals(TRACE_1, traceMetric.getName());
    Assert.assertEquals(Constants.MAX_TRACE_CUSTOM_ATTRIBUTES, traceMetric.getCustomAttributesCount());
    for (int i = 0; i < Constants.MAX_TRACE_CUSTOM_ATTRIBUTES; i++) {
        String attributeValue = TRACE_ATTRIBUTE_VALUE + i;
        String attributeKey = TRACE_ATTRIBUTE_KEY + i;
        Assert.assertEquals(attributeValue, trace.getAttribute(attributeKey));
    }
}
Also used : TraceMetric(com.google.firebase.perf.v1.TraceMetric) Test(org.junit.Test)

Example 39 with TraceMetric

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

the class TraceMetricBuilderTest method testJustStartAndStopWithoutCheckpointsAndCounters.

@Test
public void testJustStartAndStopWithoutCheckpointsAndCounters() {
    Trace trace = new Trace(TRACE_1, transportManager, clock, appStateMonitor);
    currentTime = 1;
    trace.start();
    currentTime = 2;
    trace.stop();
    TraceMetric traceMetric = new TraceMetricBuilder(trace).build();
    Assert.assertEquals(TRACE_1, traceMetric.getName());
    Assert.assertEquals(1, traceMetric.getClientStartTimeUs());
    Assert.assertEquals(1, traceMetric.getDurationUs());
    Assert.assertEquals(0, traceMetric.getCountersCount());
    Assert.assertEquals(0, traceMetric.getSubtracesCount());
}
Also used : TraceMetric(com.google.firebase.perf.v1.TraceMetric) Test(org.junit.Test)

Example 40 with TraceMetric

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

the class TraceMetricBuilderTest method testAddingSubtraceAndCountersWithStartAndStop.

@Test
public void testAddingSubtraceAndCountersWithStartAndStop() {
    Trace trace = new Trace(TRACE_1, transportManager, clock, appStateMonitor);
    currentTime = 1;
    trace.start();
    currentTime = 2;
    trace.startStage(TRACE_2);
    trace.incrementMetric(METRIC_1, 1);
    trace.incrementMetric(METRIC_1, 1);
    trace.incrementMetric(METRIC_2, 1);
    trace.incrementMetric(METRIC_2, 1);
    trace.incrementMetric(METRIC_2, 1);
    currentTime = 3;
    trace.stop();
    TraceMetric traceMetric = new TraceMetricBuilder(trace).build();
    Assert.assertEquals(TRACE_1, traceMetric.getName());
    Assert.assertEquals(1, traceMetric.getClientStartTimeUs());
    Assert.assertEquals(2, traceMetric.getDurationUs());
    Map<String, Long> counterMap = traceMetric.getCountersMap();
    Assert.assertEquals(2, counterMap.size());
    Assert.assertEquals(Long.valueOf(2), counterMap.get(METRIC_1));
    Assert.assertEquals(Long.valueOf(3), counterMap.get(METRIC_2));
    Assert.assertEquals(1, traceMetric.getSubtracesCount());
    TraceMetric subtrace = traceMetric.getSubtraces(0);
    Assert.assertEquals(TRACE_2, subtrace.getName());
    Assert.assertEquals(2, subtrace.getClientStartTimeUs());
    Assert.assertEquals(1, subtrace.getDurationUs());
    Assert.assertEquals(0, subtrace.getCountersCount());
    Assert.assertEquals(0, subtrace.getSubtracesCount());
}
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