Search in sources :

Example 21 with PerfSession

use of com.google.firebase.perf.session.PerfSession in project firebase-android-sdk by firebase.

the class GaugeManagerTest method testStartCollectingGaugesDoesNotStartCollectingMetricsWithUnknownApplicationProcessState.

@Test
public void testStartCollectingGaugesDoesNotStartCollectingMetricsWithUnknownApplicationProcessState() {
    PerfSession fakeSession = new PerfSession("sessionId", new Clock());
    testGaugeManager.startCollectingGauges(fakeSession, ApplicationProcessState.APPLICATION_PROCESS_STATE_UNKNOWN);
    verify(fakeCpuGaugeCollector, never()).startCollecting(ArgumentMatchers.anyLong(), ArgumentMatchers.nullable(Timer.class));
    verify(fakeMemoryGaugeCollector, never()).startCollecting(ArgumentMatchers.anyLong(), ArgumentMatchers.nullable(Timer.class));
}
Also used : Timer(com.google.firebase.perf.util.Timer) PerfSession(com.google.firebase.perf.session.PerfSession) Clock(com.google.firebase.perf.util.Clock) Test(org.junit.Test)

Example 22 with PerfSession

use of com.google.firebase.perf.session.PerfSession in project firebase-android-sdk by firebase.

the class GaugeManagerTest method testStartCollectingGaugesStartsAJobToConsumeTheGeneratedMetrics.

@Test
public void testStartCollectingGaugesStartsAJobToConsumeTheGeneratedMetrics() {
    PerfSession fakeSession = new PerfSession("sessionId", new Clock());
    testGaugeManager.startCollectingGauges(fakeSession, ApplicationProcessState.BACKGROUND);
    assertThat(fakeScheduledExecutorService.isEmpty()).isFalse();
    assertThat(fakeScheduledExecutorService.getDelayToNextTask(TimeUnit.MILLISECONDS)).isEqualTo(getMinimumBackgroundCollectionFrequency() * APPROX_NUMBER_OF_DATA_POINTS_PER_GAUGE_METRIC);
    CpuMetricReading fakeCpuMetricReading1 = createFakeCpuMetricReading(200, 100);
    CpuMetricReading fakeCpuMetricReading2 = createFakeCpuMetricReading(300, 200);
    fakeCpuGaugeCollector.cpuMetricReadings.add(fakeCpuMetricReading1);
    fakeCpuGaugeCollector.cpuMetricReadings.add(fakeCpuMetricReading2);
    AndroidMemoryReading fakeMemoryMetricReading1 = createFakeAndroidMetricReading(/* currentUsedAppJavaHeapMemoryKb= */
    123456);
    AndroidMemoryReading fakeMemoryMetricReading2 = createFakeAndroidMetricReading(/* currentUsedAppJavaHeapMemoryKb= */
    23454678);
    fakeMemoryGaugeCollector.memoryMetricReadings.add(fakeMemoryMetricReading1);
    fakeMemoryGaugeCollector.memoryMetricReadings.add(fakeMemoryMetricReading2);
    fakeScheduledExecutorService.simulateSleepExecutingAtMostOneTask();
    GaugeMetric recordedGaugeMetric = getLastRecordedGaugeMetric(ApplicationProcessState.BACKGROUND, 1);
    assertThatCpuGaugeMetricWasSentToTransport("sessionId", recordedGaugeMetric, fakeCpuMetricReading1, fakeCpuMetricReading2);
    assertThatMemoryGaugeMetricWasSentToTransport("sessionId", recordedGaugeMetric, fakeMemoryMetricReading1, fakeMemoryMetricReading2);
}
Also used : AndroidMemoryReading(com.google.firebase.perf.v1.AndroidMemoryReading) CpuMetricReading(com.google.firebase.perf.v1.CpuMetricReading) PerfSession(com.google.firebase.perf.session.PerfSession) GaugeMetric(com.google.firebase.perf.v1.GaugeMetric) Clock(com.google.firebase.perf.util.Clock) Test(org.junit.Test)

Aggregations

PerfSession (com.google.firebase.perf.session.PerfSession)22 Clock (com.google.firebase.perf.util.Clock)19 Test (org.junit.Test)19 Timer (com.google.firebase.perf.util.Timer)7 AndroidMemoryReading (com.google.firebase.perf.v1.AndroidMemoryReading)5 CpuMetricReading (com.google.firebase.perf.v1.CpuMetricReading)5 GaugeMetric (com.google.firebase.perf.v1.GaugeMetric)5 SessionManager (com.google.firebase.perf.session.SessionManager)2 Keep (androidx.annotation.Keep)1 NetworkRequestMetric (com.google.firebase.perf.v1.NetworkRequestMetric)1