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