Search in sources :

Example 6 with AndroidMemoryReading

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

the class TransportManagerTest method validGaugeMetric_withMemoryReadings_isLogged.

@Test
public void validGaugeMetric_withMemoryReadings_isLogged() {
    ApplicationProcessState expectedAppState = ApplicationProcessState.FOREGROUND;
    // Construct a list of Memory metric readings
    List<AndroidMemoryReading> expectedMemoryMetricReadings = new ArrayList<>();
    expectedMemoryMetricReadings.add(createValidAndroidMetricReading(/* currentUsedAppJavaHeapMemoryKb= */
    1234));
    expectedMemoryMetricReadings.add(createValidAndroidMetricReading(/* currentUsedAppJavaHeapMemoryKb= */
    23456));
    GaugeMetric validGauge = GaugeMetric.newBuilder().setSessionId("sessionId").addAllAndroidMemoryReadings(expectedMemoryMetricReadings).build();
    testTransportManager.log(validGauge, expectedAppState);
    fakeExecutorService.runAll();
    PerfMetric loggedPerfMetric = getLastLoggedEvent(times(1));
    assertThat(loggedPerfMetric.getGaugeMetric().getAndroidMemoryReadingsList()).containsExactlyElementsIn(expectedMemoryMetricReadings);
    assertThat(loggedPerfMetric.getGaugeMetric().getSessionId()).isEqualTo("sessionId");
}
Also used : AndroidMemoryReading(com.google.firebase.perf.v1.AndroidMemoryReading) ApplicationProcessState(com.google.firebase.perf.v1.ApplicationProcessState) PerfMetric(com.google.firebase.perf.v1.PerfMetric) ArrayList(java.util.ArrayList) GaugeMetric(com.google.firebase.perf.v1.GaugeMetric) Test(org.junit.Test)

Example 7 with AndroidMemoryReading

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

the class FirebasePerfGaugeManagerValidatorTest method testGaugeMetricIsValid.

@Test
public void testGaugeMetricIsValid() {
    // Construct a list of Cpu metric readings
    List<CpuMetricReading> expectedCpuMetricReadings = new ArrayList<>();
    expectedCpuMetricReadings.add(createValidCpuMetricReading(/* userTimeUs= */
    10, /* systemTimeUs= */
    20));
    expectedCpuMetricReadings.add(createValidCpuMetricReading(/* userTimeUs= */
    20, /* systemTimeUs= */
    30));
    // Construct a list of Memory metric readings
    List<AndroidMemoryReading> expectedMemoryMetricReadings = new ArrayList<>();
    expectedMemoryMetricReadings.add(createValidAndroidMetricReading(/* currentUsedAppJavaHeapMemoryKb= */
    1234));
    expectedMemoryMetricReadings.add(createValidAndroidMetricReading(/* currentUsedAppJavaHeapMemoryKb= */
    23456));
    // Construct GaugeMetadata
    GaugeMetadata gaugeMetadata = createValidGaugeMetadata("processName", /* deviceRamSizeKb= */
    2000, /* maxAppJavaHeapMemoryKb= */
    1000, /* maxEncouragedAppJavaHeapMemoryKb= */
    800);
    GaugeMetric.Builder gaugeMetricBuilder = GaugeMetric.newBuilder();
    gaugeMetricBuilder.setSessionId("sessionId");
    gaugeMetricBuilder.addAllCpuMetricReadings(expectedCpuMetricReadings);
    gaugeMetricBuilder.addAllAndroidMemoryReadings(expectedMemoryMetricReadings);
    gaugeMetricBuilder.setGaugeMetadata(gaugeMetadata);
    FirebasePerfGaugeMetricValidator validator = new FirebasePerfGaugeMetricValidator(gaugeMetricBuilder.build());
    assertThat(validator.isValidPerfMetric()).isTrue();
}
Also used : AndroidMemoryReading(com.google.firebase.perf.v1.AndroidMemoryReading) CpuMetricReading(com.google.firebase.perf.v1.CpuMetricReading) ArrayList(java.util.ArrayList) GaugeMetadata(com.google.firebase.perf.v1.GaugeMetadata) GaugeMetric(com.google.firebase.perf.v1.GaugeMetric) Test(org.junit.Test)

Example 8 with AndroidMemoryReading

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

Example 9 with AndroidMemoryReading

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

the class MemoryGaugeCollectorTest method testCollectedMemoryMetric_hasCorrectValues.

@Test
public void testCollectedMemoryMetric_hasCorrectValues() throws IOException {
    testGaugeCollector.startCollecting(/* memoryMetricCollectionRateMs= */
    500, new Timer());
    fakeScheduledExecutorService.simulateSleepExecutingAtMostOneTask();
    AndroidMemoryReading recordedReading = testGaugeCollector.memoryMetricReadings.poll();
    assertThat(recordedReading.getUsedAppJavaHeapMemoryKb()).isGreaterThan(0);
// assertThat(recordedReading.getUsedAppJavaHeapMemoryKb())
// .isEqualTo(
// StorageUnit.BYTES.toKilobytes(RUNTIME_TOTAL_MEMORY_BYTES -
// RUNTIME_FREE_MEMORY_BYTES));
}
Also used : AndroidMemoryReading(com.google.firebase.perf.v1.AndroidMemoryReading) Timer(com.google.firebase.perf.util.Timer) Test(org.junit.Test)

Aggregations

AndroidMemoryReading (com.google.firebase.perf.v1.AndroidMemoryReading)9 Test (org.junit.Test)9 GaugeMetric (com.google.firebase.perf.v1.GaugeMetric)7 CpuMetricReading (com.google.firebase.perf.v1.CpuMetricReading)6 PerfSession (com.google.firebase.perf.session.PerfSession)5 Clock (com.google.firebase.perf.util.Clock)5 Timer (com.google.firebase.perf.util.Timer)2 ArrayList (java.util.ArrayList)2 ApplicationProcessState (com.google.firebase.perf.v1.ApplicationProcessState)1 GaugeMetadata (com.google.firebase.perf.v1.GaugeMetadata)1 PerfMetric (com.google.firebase.perf.v1.PerfMetric)1