Search in sources :

Example 1 with GaugeMetric

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

the class GaugeManager method logGaugeMetadata.

/**
 * Log the Gauge Metadata information to the transport.
 *
 * @param sessionId The {@link PerfSession#sessionId()} to which the collected Gauge Metrics
 *     should be associated with.
 * @param appState The {@link ApplicationProcessState} for which these gauges are collected.
 * @return true if GaugeMetadata was logged, false otherwise.
 */
public boolean logGaugeMetadata(String sessionId, ApplicationProcessState appState) {
    if (gaugeMetadataManager != null) {
        GaugeMetric gaugeMetric = GaugeMetric.newBuilder().setSessionId(sessionId).setGaugeMetadata(getGaugeMetadata()).build();
        transportManager.log(gaugeMetric, appState);
        return true;
    }
    return false;
}
Also used : GaugeMetric(com.google.firebase.perf.v1.GaugeMetric)

Example 2 with GaugeMetric

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

the class GaugeManagerTest method testStartGaugeManagerWithSameSessionIdButDifferentAppState.

@Test
public void testStartGaugeManagerWithSameSessionIdButDifferentAppState() {
    PerfSession fakeSession = new PerfSession("sessionId", new Clock());
    // Start collecting Gauges.
    testGaugeManager.startCollectingGauges(fakeSession, ApplicationProcessState.BACKGROUND);
    CpuMetricReading fakeCpuMetricReading1 = createFakeCpuMetricReading(200, 100);
    fakeCpuGaugeCollector.cpuMetricReadings.add(fakeCpuMetricReading1);
    AndroidMemoryReading fakeMemoryMetricReading1 = createFakeAndroidMetricReading(/* currentUsedAppJavaHeapMemoryKb= */
    1234);
    fakeMemoryGaugeCollector.memoryMetricReadings.add(fakeMemoryMetricReading1);
    fakeScheduledExecutorService.simulateSleepExecutingAtMostOneTask();
    GaugeMetric recordedGaugeMetric1 = getLastRecordedGaugeMetric(ApplicationProcessState.BACKGROUND, 1);
    assertThatCpuGaugeMetricWasSentToTransport("sessionId", recordedGaugeMetric1, fakeCpuMetricReading1);
    assertThatMemoryGaugeMetricWasSentToTransport("sessionId", recordedGaugeMetric1, fakeMemoryMetricReading1);
    // One Cpu and Memory metric was added when the gauge was collecting for the previous sessionId.
    CpuMetricReading fakeCpuMetricReading2 = createFakeCpuMetricReading(400, 500);
    fakeCpuGaugeCollector.cpuMetricReadings.add(fakeCpuMetricReading2);
    AndroidMemoryReading fakeMemoryMetricReading2 = createFakeAndroidMetricReading(/* currentUsedAppJavaHeapMemoryKb= */
    2345);
    fakeMemoryGaugeCollector.memoryMetricReadings.add(fakeMemoryMetricReading2);
    // Start collecting gauges for same session, but new app state
    testGaugeManager.startCollectingGauges(fakeSession, ApplicationProcessState.FOREGROUND);
    // The next sweep conducted by GaugeManager still associates metrics to old sessionId and state.
    fakeScheduledExecutorService.simulateSleepExecutingAtMostOneTask();
    GaugeMetric recordedGaugeMetric2 = getLastRecordedGaugeMetric(ApplicationProcessState.BACKGROUND, 1);
    assertThatCpuGaugeMetricWasSentToTransport("sessionId", recordedGaugeMetric2, fakeCpuMetricReading2);
    assertThatMemoryGaugeMetricWasSentToTransport("sessionId", recordedGaugeMetric2, fakeMemoryMetricReading2);
    // Collect some more Cpu and Memory metrics and verify that they're associated with new
    // sessionId and state.
    CpuMetricReading fakeCpuMetricReading3 = createFakeCpuMetricReading(500, 600);
    fakeCpuGaugeCollector.cpuMetricReadings.add(fakeCpuMetricReading3);
    AndroidMemoryReading fakeMemoryMetricReading3 = createFakeAndroidMetricReading(/* currentUsedAppJavaHeapMemoryKb= */
    3456);
    fakeMemoryGaugeCollector.memoryMetricReadings.add(fakeMemoryMetricReading3);
    fakeScheduledExecutorService.simulateSleepExecutingAtMostOneTask();
    GaugeMetric recordedGaugeMetric3 = getLastRecordedGaugeMetric(ApplicationProcessState.FOREGROUND, 1);
    assertThatCpuGaugeMetricWasSentToTransport("sessionId", recordedGaugeMetric3, fakeCpuMetricReading3);
    assertThatMemoryGaugeMetricWasSentToTransport("sessionId", recordedGaugeMetric3, fakeMemoryMetricReading3);
}
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)

Example 3 with GaugeMetric

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

the class GaugeManagerTest method testStopCollectingGaugesCreatesOneLastJobToConsumeAnyPendingMetrics.

@Test
public void testStopCollectingGaugesCreatesOneLastJobToConsumeAnyPendingMetrics() {
    PerfSession fakeSession = new PerfSession("sessionId", new Clock());
    testGaugeManager.startCollectingGauges(fakeSession, ApplicationProcessState.BACKGROUND);
    assertThat(fakeScheduledExecutorService.isEmpty()).isFalse();
    testGaugeManager.stopCollectingGauges();
    assertThat(fakeScheduledExecutorService.isEmpty()).isFalse();
    CpuMetricReading fakeCpuMetricReading = createFakeCpuMetricReading(200, 100);
    fakeCpuGaugeCollector.cpuMetricReadings.add(fakeCpuMetricReading);
    AndroidMemoryReading fakeMemoryMetricReading = createFakeAndroidMetricReading(/* currentUsedAppJavaHeapMemoryKb= */
    23454678);
    fakeMemoryGaugeCollector.memoryMetricReadings.add(fakeMemoryMetricReading);
    assertThat(fakeScheduledExecutorService.getDelayToNextTask(TimeUnit.MILLISECONDS)).isEqualTo(TIME_TO_WAIT_BEFORE_FLUSHING_GAUGES_QUEUE_MS);
    fakeScheduledExecutorService.simulateSleepExecutingAtMostOneTask();
    GaugeMetric recordedGaugeMetric = getLastRecordedGaugeMetric(ApplicationProcessState.BACKGROUND, 1);
    assertThatCpuGaugeMetricWasSentToTransport("sessionId", recordedGaugeMetric, fakeCpuMetricReading);
    assertThatMemoryGaugeMetricWasSentToTransport("sessionId", recordedGaugeMetric, fakeMemoryMetricReading);
}
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)

Example 4 with GaugeMetric

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

the class GaugeManagerTest method testLogGaugeMetadataSendDataToTransport.

@Test
public void testLogGaugeMetadataSendDataToTransport() {
    when(fakeGaugeMetadataManager.getProcessName()).thenReturn("processName");
    when(fakeGaugeMetadataManager.getDeviceRamSizeKb()).thenReturn(2000);
    when(fakeGaugeMetadataManager.getMaxAppJavaHeapMemoryKb()).thenReturn(1000);
    when(fakeGaugeMetadataManager.getMaxEncouragedAppJavaHeapMemoryKb()).thenReturn(800);
    testGaugeManager.logGaugeMetadata("sessionId", ApplicationProcessState.FOREGROUND);
    GaugeMetric recordedGaugeMetric = getLastRecordedGaugeMetric(ApplicationProcessState.FOREGROUND, 1);
    GaugeMetadata recordedGaugeMetadata = recordedGaugeMetric.getGaugeMetadata();
    assertThat(recordedGaugeMetric.getSessionId()).isEqualTo("sessionId");
    assertThat(recordedGaugeMetadata.getProcessName()).isEqualTo("processName");
    assertThat(recordedGaugeMetadata.getDeviceRamSizeKb()).isEqualTo(fakeGaugeMetadataManager.getDeviceRamSizeKb());
    assertThat(recordedGaugeMetadata.getMaxAppJavaHeapMemoryKb()).isEqualTo(fakeGaugeMetadataManager.getMaxAppJavaHeapMemoryKb());
    assertThat(recordedGaugeMetadata.getMaxEncouragedAppJavaHeapMemoryKb()).isEqualTo(fakeGaugeMetadataManager.getMaxEncouragedAppJavaHeapMemoryKb());
}
Also used : GaugeMetric(com.google.firebase.perf.v1.GaugeMetric) GaugeMetadata(com.google.firebase.perf.v1.GaugeMetadata) Test(org.junit.Test)

Example 5 with GaugeMetric

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

the class GaugeManagerTest method testLogGaugeMetadataLogsAfterApplicationContextIsSet.

@Test
public void testLogGaugeMetadataLogsAfterApplicationContextIsSet() {
    testGaugeManager = new GaugeManager(new Lazy<>(() -> fakeScheduledExecutorService), mockTransportManager, mockConfigResolver, /* gaugeMetadataManager= */
    null, new Lazy<>(() -> fakeCpuGaugeCollector), new Lazy<>(() -> fakeMemoryGaugeCollector));
    assertThat(testGaugeManager.logGaugeMetadata("sessionId", ApplicationProcessState.FOREGROUND)).isFalse();
    testGaugeManager.initializeGaugeMetadataManager(ApplicationProvider.getApplicationContext());
    assertThat(testGaugeManager.logGaugeMetadata("sessionId", ApplicationProcessState.FOREGROUND)).isTrue();
    GaugeMetric recordedGaugeMetric = getLastRecordedGaugeMetric(ApplicationProcessState.FOREGROUND, 1);
    GaugeMetadata recordedGaugeMetadata = recordedGaugeMetric.getGaugeMetadata();
    assertThat(recordedGaugeMetric.getSessionId()).isEqualTo("sessionId");
    assertThat(recordedGaugeMetadata.hasProcessName()).isTrue();
}
Also used : Lazy(com.google.firebase.components.Lazy) GaugeMetric(com.google.firebase.perf.v1.GaugeMetric) GaugeMetadata(com.google.firebase.perf.v1.GaugeMetadata) Test(org.junit.Test)

Aggregations

GaugeMetric (com.google.firebase.perf.v1.GaugeMetric)18 Test (org.junit.Test)17 PerfMetric (com.google.firebase.perf.v1.PerfMetric)10 AndroidMemoryReading (com.google.firebase.perf.v1.AndroidMemoryReading)6 CpuMetricReading (com.google.firebase.perf.v1.CpuMetricReading)6 PerfSession (com.google.firebase.perf.session.PerfSession)5 Clock (com.google.firebase.perf.util.Clock)5 ApplicationProcessState (com.google.firebase.perf.v1.ApplicationProcessState)3 GaugeMetadata (com.google.firebase.perf.v1.GaugeMetadata)3 ArrayList (java.util.ArrayList)2 Lazy (com.google.firebase.components.Lazy)1 NetworkRequestMetric (com.google.firebase.perf.v1.NetworkRequestMetric)1 TraceMetric (com.google.firebase.perf.v1.TraceMetric)1