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);
}
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);
}
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);
}
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));
}
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());
}
Aggregations