Search in sources :

Example 6 with CpuMetricReading

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

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

the class CpuGaugeCollectorTest method testCollectingCpuMetricHasCorrectValuesFromProcPidStatFile.

@Test
public void testCollectingCpuMetricHasCorrectValuesFromProcPidStatFile() throws IOException {
    testGaugeCollector.startCollecting(500, new Timer());
    fakeScheduledExecutorService.simulateSleepExecutingAtMostOneTask();
    deleteFakeProcFile();
    createFakeFileToEmulateProcPidStat("200", "200", "400", "400");
    fakeScheduledExecutorService.simulateSleepExecutingAtMostOneTask();
    CpuMetricReading recordedReadingOne = testGaugeCollector.cpuMetricReadings.poll();
    CpuMetricReading recordedReadingTwo = testGaugeCollector.cpuMetricReadings.poll();
    assertThat(recordedReadingOne.getSystemTimeUs()).isEqualTo(convertClockTicksToMicroseconds(200, fakeClockTicksPerSecond));
    assertThat(recordedReadingOne.getUserTimeUs()).isEqualTo(convertClockTicksToMicroseconds(200, fakeClockTicksPerSecond));
    assertThat(recordedReadingTwo.getSystemTimeUs()).isEqualTo(convertClockTicksToMicroseconds(800, fakeClockTicksPerSecond));
    assertThat(recordedReadingTwo.getUserTimeUs()).isEqualTo(convertClockTicksToMicroseconds(400, fakeClockTicksPerSecond));
}
Also used : Timer(com.google.firebase.perf.util.Timer) CpuMetricReading(com.google.firebase.perf.v1.CpuMetricReading) Test(org.junit.Test)

Example 8 with CpuMetricReading

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

the class CpuGaugeCollectorTest method testCollectCpuMetricContainsApproximatelyCorrectTimestamp.

@Test
public void testCollectCpuMetricContainsApproximatelyCorrectTimestamp() {
    Timer testTimer = new Timer();
    testGaugeCollector.startCollecting(100, testTimer);
    long beforeTimestampUs = testTimer.getCurrentTimestampMicros();
    fakeScheduledExecutorService.simulateSleepExecutingAtMostOneTask();
    long afterTimestampUs = testTimer.getCurrentTimestampMicros();
    CpuMetricReading metricReading = testGaugeCollector.cpuMetricReadings.poll();
    assertThat(metricReading.getClientTimeUs()).isAtLeast(beforeTimestampUs);
    assertThat(metricReading.getClientTimeUs()).isAtMost(afterTimestampUs);
}
Also used : Timer(com.google.firebase.perf.util.Timer) CpuMetricReading(com.google.firebase.perf.v1.CpuMetricReading) Test(org.junit.Test)

Example 9 with CpuMetricReading

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

the class CpuGaugeCollectorTest method testCollectingCpuMetricHasCorrectValuesFromProcPidStatFileDifferentClockTicksPerSecond.

@Test
public void testCollectingCpuMetricHasCorrectValuesFromProcPidStatFileDifferentClockTicksPerSecond() throws IOException {
    final long differentClockTicksPerSecond = 200;
    testGaugeCollector = new CpuGaugeCollector(fakeScheduledExecutorService, fakeProcFile, differentClockTicksPerSecond);
    testGaugeCollector.startCollecting(500, new Timer());
    fakeScheduledExecutorService.simulateSleepExecutingAtMostOneTask();
    deleteFakeProcFile();
    createFakeFileToEmulateProcPidStat("200", "200", "400", "400");
    fakeScheduledExecutorService.simulateSleepExecutingAtMostOneTask();
    CpuMetricReading recordedReadingOne = testGaugeCollector.cpuMetricReadings.poll();
    CpuMetricReading recordedReadingTwo = testGaugeCollector.cpuMetricReadings.poll();
    assertThat(recordedReadingOne.getSystemTimeUs()).isEqualTo(convertClockTicksToMicroseconds(200, differentClockTicksPerSecond));
    assertThat(recordedReadingOne.getUserTimeUs()).isEqualTo(convertClockTicksToMicroseconds(200, differentClockTicksPerSecond));
    assertThat(recordedReadingTwo.getSystemTimeUs()).isEqualTo(convertClockTicksToMicroseconds(800, differentClockTicksPerSecond));
    assertThat(recordedReadingTwo.getUserTimeUs()).isEqualTo(convertClockTicksToMicroseconds(400, differentClockTicksPerSecond));
}
Also used : Timer(com.google.firebase.perf.util.Timer) CpuMetricReading(com.google.firebase.perf.v1.CpuMetricReading) Test(org.junit.Test)

Example 10 with CpuMetricReading

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

CpuMetricReading (com.google.firebase.perf.v1.CpuMetricReading)10 Test (org.junit.Test)10 GaugeMetric (com.google.firebase.perf.v1.GaugeMetric)7 AndroidMemoryReading (com.google.firebase.perf.v1.AndroidMemoryReading)6 PerfSession (com.google.firebase.perf.session.PerfSession)5 Clock (com.google.firebase.perf.util.Clock)5 Timer (com.google.firebase.perf.util.Timer)3 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