use of com.google.firebase.perf.util.Clock in project firebase-android-sdk by firebase.
the class AppStateMonitorTest method setUp.
@Before
public void setUp() {
currentTime = 0;
initMocks(this);
doAnswer((Answer<Timer>) invocationOnMock -> new Timer(currentTime)).when(clock).getTime();
activity1 = createFakeActivity(/* isHardwareAccelerated= */
true);
activity2 = createFakeActivity(/* isHardwareAccelerated= */
true);
DeviceCacheManager.clearInstance();
ConfigResolver.clearInstance();
ConfigResolver configResolver = ConfigResolver.getInstance();
configResolver.setDeviceCacheManager(new DeviceCacheManager(new FakeDirectExecutorService()));
}
use of com.google.firebase.perf.util.Clock in project firebase-android-sdk by firebase.
the class FragmentStateMonitorTest method setUp.
@Before
public void setUp() {
currentTime = 0;
initMocks(this);
doAnswer((Answer<Timer>) invocationOnMock -> new Timer(currentTime)).when(clock).getTime();
DeviceCacheManager.clearInstance();
when(configResolver.isPerformanceMonitoringEnabled()).thenReturn(true);
doNothing().when(recorder).start();
doNothing().when(recorder).startFragment(any());
activity = createFakeActivity(true);
// Sample frame counts.
frameCounts1 = new PerfFrameMetrics(9, 5, 3);
frameCounts2 = new PerfFrameMetrics(14, 9, 4);
savedInstanceState = mock(Bundle.class);
appStateMonitor = mock(AppStateMonitor.class);
mockFragment1 = mock(Fragment.class);
mockFragment2 = mock(Fragment.class);
}
use of com.google.firebase.perf.util.Clock in project firebase-android-sdk by firebase.
the class PerfSession method create.
/*
* Creates a PerfSession object and decides what metrics to collect.
*/
public static PerfSession create() {
String sessionId = UUID.randomUUID().toString().replace("-", "");
PerfSession session = new PerfSession(sessionId, new Clock());
session.setGaugeAndEventCollectionEnabled(shouldCollectGaugesAndEvents());
return session;
}
use of com.google.firebase.perf.util.Clock in project firebase-android-sdk by firebase.
the class GaugeManagerTest method testStartCollectingGaugesStartsCollectingMetricsInForegroundState.
@Test
public void testStartCollectingGaugesStartsCollectingMetricsInForegroundState() {
PerfSession fakeSession = new PerfSession("sessionId", new Clock());
testGaugeManager.startCollectingGauges(fakeSession, ApplicationProcessState.FOREGROUND);
verify(fakeCpuGaugeCollector).startCollecting(eq(DEFAULT_CPU_GAUGE_COLLECTION_FREQUENCY_FG_MS), ArgumentMatchers.nullable(Timer.class));
verify(fakeMemoryGaugeCollector).startCollecting(eq(DEFAULT_MEMORY_GAUGE_COLLECTION_FREQUENCY_FG_MS), ArgumentMatchers.nullable(Timer.class));
}
use of com.google.firebase.perf.util.Clock in project firebase-android-sdk by firebase.
the class GaugeManagerTest method testStartGaugeManagerWithSameSessionIdButDifferentAppState.
@Test
public void testStartGaugeManagerWithSameSessionIdButDifferentAppState() {
PerfSession fakeSession = new PerfSession("sessionId", new Clock());
// Start collecting Gauges.
testGaugeManager.startCollectingGauges(fakeSession, 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);
// Start collecting gauges for same session, but new app state
testGaugeManager.startCollectingGauges(fakeSession, ApplicationProcessState.FOREGROUND);
// 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.FOREGROUND, 1);
assertThatCpuGaugeMetricWasSentToTransport("sessionId", recordedGaugeMetric3, fakeCpuMetricReading3);
assertThatMemoryGaugeMetricWasSentToTransport("sessionId", recordedGaugeMetric3, fakeMemoryMetricReading3);
}
Aggregations