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