Search in sources :

Example 6 with Clock

use of com.google.firebase.perf.util.Clock in project firebase-android-sdk by firebase.

the class GaugeManagerTest method testGaugeManagerClearsTheQueueEachRun.

@Test
public void testGaugeManagerClearsTheQueueEachRun() {
    PerfSession fakeSession = new PerfSession("sessionId", new Clock());
    testGaugeManager.startCollectingGauges(fakeSession, ApplicationProcessState.BACKGROUND);
    fakeCpuGaugeCollector.cpuMetricReadings.add(createFakeCpuMetricReading(200, 100));
    fakeCpuGaugeCollector.cpuMetricReadings.add(createFakeCpuMetricReading(300, 400));
    fakeMemoryGaugeCollector.memoryMetricReadings.add(createFakeAndroidMetricReading(/* currentUsedAppJavaHeapMemoryKb= */
    1234));
    assertThat(fakeCpuGaugeCollector.cpuMetricReadings).isNotEmpty();
    assertThat(fakeMemoryGaugeCollector.memoryMetricReadings).isNotEmpty();
    fakeScheduledExecutorService.simulateSleepExecutingAtMostOneTask();
    assertThat(fakeCpuGaugeCollector.cpuMetricReadings).isEmpty();
    assertThat(fakeMemoryGaugeCollector.memoryMetricReadings).isEmpty();
    fakeCpuGaugeCollector.cpuMetricReadings.add(createFakeCpuMetricReading(200, 100));
    fakeMemoryGaugeCollector.memoryMetricReadings.add(createFakeAndroidMetricReading(/* currentUsedAppJavaHeapMemoryKb= */
    1234));
    fakeMemoryGaugeCollector.memoryMetricReadings.add(createFakeAndroidMetricReading(/* currentUsedAppJavaHeapMemoryKb= */
    2345));
    assertThat(fakeCpuGaugeCollector.cpuMetricReadings).isNotEmpty();
    assertThat(fakeMemoryGaugeCollector.memoryMetricReadings).isNotEmpty();
    fakeScheduledExecutorService.simulateSleepExecutingAtMostOneTask();
    assertThat(fakeCpuGaugeCollector.cpuMetricReadings).isEmpty();
    assertThat(fakeMemoryGaugeCollector.memoryMetricReadings).isEmpty();
}
Also used : PerfSession(com.google.firebase.perf.session.PerfSession) Clock(com.google.firebase.perf.util.Clock) Test(org.junit.Test)

Example 7 with Clock

use of com.google.firebase.perf.util.Clock 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);
}
Also used : AndroidMemoryReading(com.google.firebase.perf.v1.AndroidMemoryReading) CpuMetricReading(com.google.firebase.perf.v1.CpuMetricReading) PerfSession(com.google.firebase.perf.session.PerfSession) GaugeMetric(com.google.firebase.perf.v1.GaugeMetric) Clock(com.google.firebase.perf.util.Clock) Test(org.junit.Test)

Example 8 with Clock

use of com.google.firebase.perf.util.Clock 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));
}
Also used : Timer(com.google.firebase.perf.util.Timer) PerfSession(com.google.firebase.perf.session.PerfSession) Clock(com.google.firebase.perf.util.Clock) Test(org.junit.Test)

Example 9 with Clock

use of com.google.firebase.perf.util.Clock 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));
}
Also used : Timer(com.google.firebase.perf.util.Timer) PerfSession(com.google.firebase.perf.session.PerfSession) Clock(com.google.firebase.perf.util.Clock) Test(org.junit.Test)

Example 10 with Clock

use of com.google.firebase.perf.util.Clock 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();
}
Also used : PerfSession(com.google.firebase.perf.session.PerfSession) Clock(com.google.firebase.perf.util.Clock) Test(org.junit.Test)

Aggregations

Clock (com.google.firebase.perf.util.Clock)24 Test (org.junit.Test)23 PerfSession (com.google.firebase.perf.session.PerfSession)19 Timer (com.google.firebase.perf.util.Timer)9 AndroidMemoryReading (com.google.firebase.perf.v1.AndroidMemoryReading)5 CpuMetricReading (com.google.firebase.perf.v1.CpuMetricReading)5 GaugeMetric (com.google.firebase.perf.v1.GaugeMetric)5 TraceMetric (com.google.firebase.perf.v1.TraceMetric)3 Activity (android.app.Activity)2 Bundle (android.os.Bundle)2 Truth.assertThat (com.google.common.truth.Truth.assertThat)2 FirebasePerformanceTestBase (com.google.firebase.perf.FirebasePerformanceTestBase)2 ConfigResolver (com.google.firebase.perf.config.ConfigResolver)2 DeviceCacheManager (com.google.firebase.perf.config.DeviceCacheManager)2 Trace (com.google.firebase.perf.metrics.Trace)2 TransportManager (com.google.firebase.perf.transport.TransportManager)2 Constants (com.google.firebase.perf.util.Constants)2 ApplicationProcessState (com.google.firebase.perf.v1.ApplicationProcessState)2 PerfMetric (com.google.firebase.perf.v1.PerfMetric)2 PerfSession (com.google.firebase.perf.v1.PerfSession)2