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