use of com.google.firebase.perf.session.PerfSession in project firebase-android-sdk by firebase.
the class GaugeManagerTest method testStopCollectingGaugesCreatesOneLastJobToConsumeAnyPendingMetrics.
@Test
public void testStopCollectingGaugesCreatesOneLastJobToConsumeAnyPendingMetrics() {
PerfSession fakeSession = new PerfSession("sessionId", new Clock());
testGaugeManager.startCollectingGauges(fakeSession, ApplicationProcessState.BACKGROUND);
assertThat(fakeScheduledExecutorService.isEmpty()).isFalse();
testGaugeManager.stopCollectingGauges();
assertThat(fakeScheduledExecutorService.isEmpty()).isFalse();
CpuMetricReading fakeCpuMetricReading = createFakeCpuMetricReading(200, 100);
fakeCpuGaugeCollector.cpuMetricReadings.add(fakeCpuMetricReading);
AndroidMemoryReading fakeMemoryMetricReading = createFakeAndroidMetricReading(/* currentUsedAppJavaHeapMemoryKb= */
23454678);
fakeMemoryGaugeCollector.memoryMetricReadings.add(fakeMemoryMetricReading);
assertThat(fakeScheduledExecutorService.getDelayToNextTask(TimeUnit.MILLISECONDS)).isEqualTo(TIME_TO_WAIT_BEFORE_FLUSHING_GAUGES_QUEUE_MS);
fakeScheduledExecutorService.simulateSleepExecutingAtMostOneTask();
GaugeMetric recordedGaugeMetric = getLastRecordedGaugeMetric(ApplicationProcessState.BACKGROUND, 1);
assertThatCpuGaugeMetricWasSentToTransport("sessionId", recordedGaugeMetric, fakeCpuMetricReading);
assertThatMemoryGaugeMetricWasSentToTransport("sessionId", recordedGaugeMetric, fakeMemoryMetricReading);
}
use of com.google.firebase.perf.session.PerfSession in project firebase-android-sdk by firebase.
the class GaugeManagerTest method stopCollectingCPUMetric_invalidCPUCaptureFrequency_OtherMetricsWithValidFrequencyInBackground.
@Test
public void stopCollectingCPUMetric_invalidCPUCaptureFrequency_OtherMetricsWithValidFrequencyInBackground() {
// PASS 1: Test with 0
doReturn(0L).when(mockConfigResolver).getSessionsCpuCaptureFrequencyBackgroundMs();
PerfSession fakeSession1 = new PerfSession("sessionId", new Clock());
testGaugeManager.startCollectingGauges(fakeSession1, ApplicationProcessState.BACKGROUND);
// Verify that Cpu metric collection is not started
verify(fakeCpuGaugeCollector, never()).startCollecting(ArgumentMatchers.anyLong(), ArgumentMatchers.nullable(Timer.class));
// Verify that Memory metric collection is started
verify(fakeMemoryGaugeCollector).startCollecting(ArgumentMatchers.anyLong(), ArgumentMatchers.nullable(Timer.class));
// PASS 2: Test with -ve value
doReturn(-25L).when(mockConfigResolver).getSessionsCpuCaptureFrequencyBackgroundMs();
PerfSession fakeSession2 = new PerfSession("sessionId", new Clock());
testGaugeManager.startCollectingGauges(fakeSession2, ApplicationProcessState.BACKGROUND);
// Verify that Cpu metric collection is not started
verify(fakeCpuGaugeCollector, never()).startCollecting(ArgumentMatchers.anyLong(), ArgumentMatchers.nullable(Timer.class));
// Verify that Memory metric collection is started
verify(fakeMemoryGaugeCollector, times(2)).startCollecting(ArgumentMatchers.anyLong(), ArgumentMatchers.any(Timer.class));
}
use of com.google.firebase.perf.session.PerfSession in project firebase-android-sdk by firebase.
the class GaugeManagerTest method startCollectingGaugesOnBackground_invalidMemoryCaptureMs_onlyDisableMemoryCollection.
@Test
public void startCollectingGaugesOnBackground_invalidMemoryCaptureMs_onlyDisableMemoryCollection() {
// PASS 1: Test with 0
doReturn(0L).when(mockConfigResolver).getSessionsMemoryCaptureFrequencyBackgroundMs();
PerfSession fakeSession1 = new PerfSession("sessionId", new Clock());
testGaugeManager.startCollectingGauges(fakeSession1, ApplicationProcessState.BACKGROUND);
// Verify that Memory metric collection is not started
verify(fakeMemoryGaugeCollector, never()).startCollecting(ArgumentMatchers.anyLong(), ArgumentMatchers.nullable(Timer.class));
// Verify that Cpu metric collection is started
verify(fakeCpuGaugeCollector).startCollecting(ArgumentMatchers.anyLong(), ArgumentMatchers.nullable(Timer.class));
// PASS 2: Test with -ve value
doReturn(-25L).when(mockConfigResolver).getSessionsMemoryCaptureFrequencyBackgroundMs();
PerfSession fakeSession2 = new PerfSession("sessionId", new Clock());
testGaugeManager.startCollectingGauges(fakeSession2, ApplicationProcessState.BACKGROUND);
// Verify that Memory metric collection is not started
verify(fakeMemoryGaugeCollector, never()).startCollecting(ArgumentMatchers.anyLong(), ArgumentMatchers.nullable(Timer.class));
// Verify that Cpu metric collection is started
verify(fakeCpuGaugeCollector, times(2)).startCollecting(ArgumentMatchers.anyLong(), ArgumentMatchers.any(Timer.class));
}
use of com.google.firebase.perf.session.PerfSession in project firebase-android-sdk by firebase.
the class GaugeManagerTest method stopCollectingGauges_invalidMemoryCollectionFrequency_appInForeground.
@Test
public void stopCollectingGauges_invalidMemoryCollectionFrequency_appInForeground() {
// PASS 1: Test with 0
doReturn(0L).when(mockConfigResolver).getSessionsMemoryCaptureFrequencyForegroundMs();
PerfSession fakeSession1 = new PerfSession("sessionId", new Clock());
testGaugeManager.startCollectingGauges(fakeSession1, ApplicationProcessState.FOREGROUND);
assertThat(fakeScheduledExecutorService.isEmpty()).isFalse();
// PASS 2: Test with -ve value
doReturn(-25L).when(mockConfigResolver).getSessionsMemoryCaptureFrequencyForegroundMs();
PerfSession fakeSession2 = new PerfSession("sessionId", new Clock());
testGaugeManager.startCollectingGauges(fakeSession2, ApplicationProcessState.FOREGROUND);
assertThat(fakeScheduledExecutorService.isEmpty()).isFalse();
}
use of com.google.firebase.perf.session.PerfSession in project firebase-android-sdk by firebase.
the class GaugeManagerTest method testStartingGaugeManagerWithNewSessionIdButSameAppState.
@Test
public void testStartingGaugeManagerWithNewSessionIdButSameAppState() {
PerfSession fakeSession1 = new PerfSession("sessionId", new Clock());
// Start collecting Gauges.
testGaugeManager.startCollectingGauges(fakeSession1, ApplicationProcessState.BACKGROUND);
CpuMetricReading fakeCpuMetricReading1 = createFakeCpuMetricReading(200, 100);
fakeCpuGaugeCollector.cpuMetricReadings.add(fakeCpuMetricReading1);
AndroidMemoryReading fakeMemoryMetricReading1 = createFakeAndroidMetricReading(/* currentUsedAppJavaHeapMemoryKb= */
1234);
fakeMemoryGaugeCollector.memoryMetricReadings.add(fakeMemoryMetricReading1);
fakeScheduledExecutorService.simulateSleepExecutingAtMostOneTask();
GaugeMetric recordedGaugeMetric1 = getLastRecordedGaugeMetric(ApplicationProcessState.BACKGROUND, 1);
assertThatCpuGaugeMetricWasSentToTransport("sessionId", recordedGaugeMetric1, fakeCpuMetricReading1);
assertThatMemoryGaugeMetricWasSentToTransport("sessionId", recordedGaugeMetric1, fakeMemoryMetricReading1);
// One Cpu and Memory metric was added when the gauge was collecting for the previous sessionId.
CpuMetricReading fakeCpuMetricReading2 = createFakeCpuMetricReading(400, 500);
fakeCpuGaugeCollector.cpuMetricReadings.add(fakeCpuMetricReading2);
AndroidMemoryReading fakeMemoryMetricReading2 = createFakeAndroidMetricReading(/* currentUsedAppJavaHeapMemoryKb= */
2345);
fakeMemoryGaugeCollector.memoryMetricReadings.add(fakeMemoryMetricReading2);
PerfSession fakeSession2 = new PerfSession("sessionId2", new Clock());
// Start collecting gauges for new session, but same app state.
testGaugeManager.startCollectingGauges(fakeSession2, ApplicationProcessState.BACKGROUND);
// The next sweep conducted by GaugeManager still associates metrics to old sessionId and state.
fakeScheduledExecutorService.simulateSleepExecutingAtMostOneTask();
GaugeMetric recordedGaugeMetric2 = getLastRecordedGaugeMetric(ApplicationProcessState.BACKGROUND, 1);
assertThatCpuGaugeMetricWasSentToTransport("sessionId", recordedGaugeMetric2, fakeCpuMetricReading2);
assertThatMemoryGaugeMetricWasSentToTransport("sessionId", recordedGaugeMetric2, fakeMemoryMetricReading2);
// Collect some more Cpu and Memory metrics and verify that they're associated with new
// sessionId and state.
CpuMetricReading fakeCpuMetricReading3 = createFakeCpuMetricReading(500, 600);
fakeCpuGaugeCollector.cpuMetricReadings.add(fakeCpuMetricReading3);
AndroidMemoryReading fakeMemoryMetricReading3 = createFakeAndroidMetricReading(/* currentUsedAppJavaHeapMemoryKb= */
3456);
fakeMemoryGaugeCollector.memoryMetricReadings.add(fakeMemoryMetricReading3);
fakeScheduledExecutorService.simulateSleepExecutingAtMostOneTask();
GaugeMetric recordedGaugeMetric3 = getLastRecordedGaugeMetric(ApplicationProcessState.BACKGROUND, 1);
assertThatCpuGaugeMetricWasSentToTransport("sessionId2", recordedGaugeMetric3, fakeCpuMetricReading3);
assertThatMemoryGaugeMetricWasSentToTransport("sessionId2", recordedGaugeMetric3, fakeMemoryMetricReading3);
}
Aggregations