Search in sources :

Example 31 with Timer

use of com.google.firebase.perf.util.Timer 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 32 with Timer

use of com.google.firebase.perf.util.Timer in project firebase-android-sdk by firebase.

the class CpuGaugeCollectorTest method testCollectingCpuMetricDoesntAddAnythingToQueueWhenCannotParseIntegersFromFile.

@Test
public void testCollectingCpuMetricDoesntAddAnythingToQueueWhenCannotParseIntegersFromFile() throws IOException {
    deleteFakeProcFile();
    createFakeFileToEmulateProcPidStat("NaN", "NaN", "NaN", "NaN");
    testGaugeCollector.startCollecting(500, new Timer());
    fakeScheduledExecutorService.simulateSleepExecutingAtMostOneTask();
    assertThat(testGaugeCollector.cpuMetricReadings).hasSize(0);
}
Also used : Timer(com.google.firebase.perf.util.Timer) Test(org.junit.Test)

Example 33 with Timer

use of com.google.firebase.perf.util.Timer in project firebase-android-sdk by firebase.

the class CpuGaugeCollectorTest method testStartCollection_doesNotAddAnythingToQueueWhenFileNotFound.

@Test
public void testStartCollection_doesNotAddAnythingToQueueWhenFileNotFound() {
    deleteFakeProcFile();
    testGaugeCollector.startCollecting(500, new Timer());
    fakeScheduledExecutorService.simulateSleepExecutingAtMostOneTask();
    assertThat(testGaugeCollector.cpuMetricReadings).hasSize(0);
}
Also used : Timer(com.google.firebase.perf.util.Timer) Test(org.junit.Test)

Example 34 with Timer

use of com.google.firebase.perf.util.Timer 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 35 with Timer

use of com.google.firebase.perf.util.Timer in project firebase-android-sdk by firebase.

the class GaugeManagerTest method testCollectGaugeMetricOnceCollectAllMetricsWhenCollectionIsEnabled.

@Test
public void testCollectGaugeMetricOnceCollectAllMetricsWhenCollectionIsEnabled() {
    // Default Cpu and Memory metrics collection is enabled
    testGaugeManager.collectGaugeMetricOnce(new Timer());
    // Verify that Cpu metric collection is started
    verify(fakeCpuGaugeCollector).collectOnce(ArgumentMatchers.any());
    // Verify that Memory metric collection is started
    verify(fakeMemoryGaugeCollector).collectOnce(ArgumentMatchers.any());
}
Also used : Timer(com.google.firebase.perf.util.Timer) Test(org.junit.Test)

Aggregations

Timer (com.google.firebase.perf.util.Timer)38 Test (org.junit.Test)29 Before (org.junit.Before)7 TransportManager (com.google.firebase.perf.transport.TransportManager)4 TraceMetric (com.google.firebase.perf.v1.TraceMetric)4 Truth.assertThat (com.google.common.truth.Truth.assertThat)3 FirebasePerformanceTestBase (com.google.firebase.perf.FirebasePerformanceTestBase)3 ConfigResolver (com.google.firebase.perf.config.ConfigResolver)3 DeviceCacheManager (com.google.firebase.perf.config.DeviceCacheManager)3 Clock (com.google.firebase.perf.util.Clock)3 Constants (com.google.firebase.perf.util.Constants)3 ApplicationProcessState (com.google.firebase.perf.v1.ApplicationProcessState)3 CpuMetricReading (com.google.firebase.perf.v1.CpuMetricReading)3 RunWith (org.junit.runner.RunWith)3 ArgumentCaptor (org.mockito.ArgumentCaptor)3 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)3 ArgumentMatchers.nullable (org.mockito.ArgumentMatchers.nullable)3 Mock (org.mockito.Mock)3 Mockito.doAnswer (org.mockito.Mockito.doAnswer)3 Mockito.mock (org.mockito.Mockito.mock)3