Search in sources :

Example 1 with GaugeMetadata

use of com.google.firebase.perf.v1.GaugeMetadata 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 GaugeMetadata

use of com.google.firebase.perf.v1.GaugeMetadata 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 3 with GaugeMetadata

use of com.google.firebase.perf.v1.GaugeMetadata 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)

Example 4 with GaugeMetadata

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

the class TransportManagerTest method validGaugeMetric_withMetadata_isLogged.

@Test
public void validGaugeMetric_withMetadata_isLogged() {
    ApplicationProcessState expectedAppState = ApplicationProcessState.FOREGROUND;
    GaugeMetadata gaugeMetadata = GaugeMetadata.newBuilder().setDeviceRamSizeKb(2000).setMaxAppJavaHeapMemoryKb(1000).setMaxEncouragedAppJavaHeapMemoryKb(800).build();
    GaugeMetric validGauge = GaugeMetric.newBuilder().setSessionId("sessionId").setGaugeMetadata(gaugeMetadata).build();
    testTransportManager.log(validGauge, expectedAppState);
    fakeExecutorService.runAll();
    PerfMetric loggedPerfMetric = getLastLoggedEvent(times(1));
    assertThat(loggedPerfMetric.getGaugeMetric().getSessionId()).isEqualTo("sessionId");
    assertThat(loggedPerfMetric.getGaugeMetric().getGaugeMetadata().getDeviceRamSizeKb()).isEqualTo(2000);
    assertThat(loggedPerfMetric.getGaugeMetric().getGaugeMetadata().getMaxAppJavaHeapMemoryKb()).isEqualTo(1000);
    assertThat(loggedPerfMetric.getGaugeMetric().getGaugeMetadata().getMaxEncouragedAppJavaHeapMemoryKb()).isEqualTo(800);
}
Also used : ApplicationProcessState(com.google.firebase.perf.v1.ApplicationProcessState) PerfMetric(com.google.firebase.perf.v1.PerfMetric) GaugeMetadata(com.google.firebase.perf.v1.GaugeMetadata) GaugeMetric(com.google.firebase.perf.v1.GaugeMetric) Test(org.junit.Test)

Example 5 with GaugeMetadata

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

the class FirebasePerfGaugeManagerValidatorTest method testGaugeMetricWithOnlyGaugeMetadataIsValid.

@Test
public void testGaugeMetricWithOnlyGaugeMetadataIsValid() {
    GaugeMetadata gaugeMetadata = createValidGaugeMetadata("processName", /* deviceRamSizeKb= */
    2000, /* maxAppJavaHeapMemoryKb= */
    1000, /* maxEncouragedAppJavaHeapMemoryKb= */
    800);
    GaugeMetric.Builder gaugeMetricBuilder = GaugeMetric.newBuilder();
    gaugeMetricBuilder.setSessionId("sessionId");
    gaugeMetricBuilder.setGaugeMetadata(gaugeMetadata);
    FirebasePerfGaugeMetricValidator validator = new FirebasePerfGaugeMetricValidator(gaugeMetricBuilder.build());
    assertThat(validator.isValidPerfMetric()).isTrue();
}
Also used : GaugeMetadata(com.google.firebase.perf.v1.GaugeMetadata) GaugeMetric(com.google.firebase.perf.v1.GaugeMetric) Test(org.junit.Test)

Aggregations

GaugeMetric (com.google.firebase.perf.v1.GaugeMetric)7 GaugeMetadata (com.google.firebase.perf.v1.GaugeMetadata)6 Test (org.junit.Test)6 Lazy (com.google.firebase.components.Lazy)1 AndroidMemoryReading (com.google.firebase.perf.v1.AndroidMemoryReading)1 ApplicationProcessState (com.google.firebase.perf.v1.ApplicationProcessState)1 CpuMetricReading (com.google.firebase.perf.v1.CpuMetricReading)1 PerfMetric (com.google.firebase.perf.v1.PerfMetric)1 ArrayList (java.util.ArrayList)1