Search in sources :

Example 41 with TraceMetric

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

the class TraceMetricBuilderTest method testRemovingNonExistingCustomAttributes.

@Test
public void testRemovingNonExistingCustomAttributes() {
    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.removeAttribute(TRACE_ATTRIBUTE_KEY + "NonExisting");
    trace.stop();
    TraceMetric traceMetric = new TraceMetricBuilder(trace).build();
    Assert.assertEquals(TRACE_ATTRIBUTE_VALUE, 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 42 with TraceMetric

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

the class TraceMetricBuilderTest method testAddingCountersWithStartAndStop.

@Test
public void testAddingCountersWithStartAndStop() {
    Trace trace = new Trace(TRACE_1, transportManager, clock, appStateMonitor);
    currentTime = 1;
    trace.start();
    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 = 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());
    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(0, traceMetric.getSubtracesCount());
}
Also used : TraceMetric(com.google.firebase.perf.v1.TraceMetric) Test(org.junit.Test)

Example 43 with TraceMetric

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

the class TraceMetricBuilderTest method testIncrementingCounterByX.

@Test
public void testIncrementingCounterByX() {
    Trace trace = new Trace(TRACE_1, transportManager, clock, appStateMonitor);
    currentTime = 1;
    trace.start();
    trace.incrementMetric(METRIC_1, 5);
    trace.incrementMetric(METRIC_2, 1);
    trace.incrementMetric(METRIC_2, 10);
    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());
    Map<String, Long> counterMap = traceMetric.getCountersMap();
    Assert.assertEquals(2, counterMap.size());
    Assert.assertEquals(Long.valueOf(5), counterMap.get(METRIC_1));
    Assert.assertEquals(Long.valueOf(11), counterMap.get(METRIC_2));
    Assert.assertEquals(0, traceMetric.getSubtracesCount());
}
Also used : TraceMetric(com.google.firebase.perf.v1.TraceMetric) Test(org.junit.Test)

Example 44 with TraceMetric

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

the class TraceMetricBuilderTest method testAddingSubtraceWithStartAndStop.

@Test
public void testAddingSubtraceWithStartAndStop() {
    Trace trace = new Trace(TRACE_1, transportManager, clock, appStateMonitor);
    currentTime = 1;
    trace.start();
    currentTime = 2;
    trace.startStage(TRACE_2);
    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());
    Assert.assertEquals(0, traceMetric.getCountersCount());
    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)

Example 45 with TraceMetric

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

the class TraceMetricBuilderTest method testAddingAttributeWithNullKey.

@Test
public void testAddingAttributeWithNullKey() {
    Trace trace = new Trace(TRACE_1, transportManager, clock, appStateMonitor);
    currentTime = 1;
    trace.start();
    currentTime = 2;
    trace.putAttribute(null, TRACE_ATTRIBUTE_VALUE);
    currentTime = 3;
    trace.stop();
    TraceMetric traceMetric = new TraceMetricBuilder(trace).build();
    Assert.assertEquals(TRACE_1, traceMetric.getName());
    Assert.assertEquals(0, traceMetric.getCustomAttributesCount());
}
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