Search in sources :

Example 16 with PerfSession

use of com.google.firebase.perf.session.PerfSession in project firebase-android-sdk by firebase.

the class GaugeManagerTest method testStopCollectingGaugesStopsCollectingAllGaugeMetrics.

@Test
public void testStopCollectingGaugesStopsCollectingAllGaugeMetrics() {
    PerfSession fakeSession = new PerfSession("sessionId", new Clock());
    testGaugeManager.startCollectingGauges(fakeSession, ApplicationProcessState.BACKGROUND);
    verify(fakeCpuGaugeCollector).startCollecting(eq(DEFAULT_CPU_GAUGE_COLLECTION_FREQUENCY_BG_MS), ArgumentMatchers.any());
    testGaugeManager.stopCollectingGauges();
    verify(fakeCpuGaugeCollector).stopCollecting();
    verify(fakeMemoryGaugeCollector).stopCollecting();
}
Also used : PerfSession(com.google.firebase.perf.session.PerfSession) Clock(com.google.firebase.perf.util.Clock) Test(org.junit.Test)

Example 17 with PerfSession

use of com.google.firebase.perf.session.PerfSession in project firebase-android-sdk by firebase.

the class GaugeManagerTest method startCollectingGaugesOnForeground_invalidMemoryCaptureMs_onlyDisableMemoryCollection.

@Test
public void startCollectingGaugesOnForeground_invalidMemoryCaptureMs_onlyDisableMemoryCollection() {
    // PASS 1: Test with 0
    doReturn(0L).when(mockConfigResolver).getSessionsMemoryCaptureFrequencyForegroundMs();
    PerfSession fakeSession1 = new PerfSession("sessionId", new Clock());
    testGaugeManager.startCollectingGauges(fakeSession1, ApplicationProcessState.FOREGROUND);
    // Verify that Memory metric collection is not started
    verify(fakeMemoryGaugeCollector, never()).startCollecting(ArgumentMatchers.anyLong(), ArgumentMatchers.any(Timer.class));
    // Verify that Cpu metric collection is started
    verify(fakeCpuGaugeCollector).startCollecting(ArgumentMatchers.anyLong(), ArgumentMatchers.any(Timer.class));
    // PASS 2: Test with -ve value
    doReturn(-25L).when(mockConfigResolver).getSessionsMemoryCaptureFrequencyForegroundMs();
    PerfSession fakeSession2 = new PerfSession("sessionId", new Clock());
    testGaugeManager.startCollectingGauges(fakeSession2, ApplicationProcessState.FOREGROUND);
    // 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 18 with PerfSession

use of com.google.firebase.perf.session.PerfSession in project firebase-android-sdk by firebase.

the class GaugeManagerTest method stopCollectingGauges_invalidGaugeCollectionFrequency_appInForeground.

@Test
public void stopCollectingGauges_invalidGaugeCollectionFrequency_appInForeground() {
    // PASS 1: Test with 0
    doReturn(0L).when(mockConfigResolver).getSessionsCpuCaptureFrequencyForegroundMs();
    doReturn(0L).when(mockConfigResolver).getSessionsMemoryCaptureFrequencyForegroundMs();
    PerfSession fakeSession1 = new PerfSession("sessionId", new Clock());
    testGaugeManager.startCollectingGauges(fakeSession1, ApplicationProcessState.FOREGROUND);
    assertThat(fakeScheduledExecutorService.isEmpty()).isTrue();
    // PASS 2: Test with -ve value
    doReturn(-25L).when(mockConfigResolver).getSessionsCpuCaptureFrequencyForegroundMs();
    doReturn(-25L).when(mockConfigResolver).getSessionsMemoryCaptureFrequencyForegroundMs();
    PerfSession fakeSession2 = new PerfSession("sessionId", new Clock());
    testGaugeManager.startCollectingGauges(fakeSession2, ApplicationProcessState.FOREGROUND);
    assertThat(fakeScheduledExecutorService.isEmpty()).isTrue();
}
Also used : PerfSession(com.google.firebase.perf.session.PerfSession) Clock(com.google.firebase.perf.util.Clock) Test(org.junit.Test)

Example 19 with PerfSession

use of com.google.firebase.perf.session.PerfSession in project firebase-android-sdk by firebase.

the class GaugeManagerTest method stopCollectingCPUMetric_invalidCPUCaptureFrequency_OtherMetricsWithValidFrequency.

@Test
public void stopCollectingCPUMetric_invalidCPUCaptureFrequency_OtherMetricsWithValidFrequency() {
    // PASS 1: Test with 0
    doReturn(0L).when(mockConfigResolver).getSessionsCpuCaptureFrequencyForegroundMs();
    PerfSession fakeSession1 = new PerfSession("sessionId", new Clock());
    testGaugeManager.startCollectingGauges(fakeSession1, ApplicationProcessState.FOREGROUND);
    // Verify that Cpu metric collection is not started
    verify(fakeCpuGaugeCollector, never()).startCollecting(ArgumentMatchers.anyLong(), ArgumentMatchers.any(Timer.class));
    // Verify that Memory metric collection is started
    verify(fakeMemoryGaugeCollector).startCollecting(ArgumentMatchers.anyLong(), ArgumentMatchers.any(Timer.class));
    // PASS 2: Test with -ve value
    doReturn(-25L).when(mockConfigResolver).getSessionsCpuCaptureFrequencyForegroundMs();
    PerfSession fakeSession2 = new PerfSession("sessionId", new Clock());
    testGaugeManager.startCollectingGauges(fakeSession2, ApplicationProcessState.FOREGROUND);
    // 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 20 with PerfSession

use of com.google.firebase.perf.session.PerfSession in project firebase-android-sdk by firebase.

the class GaugeManagerTest method startCollectingGauges_validGaugeCollectionFrequency_appInForeground.

@Test
public void startCollectingGauges_validGaugeCollectionFrequency_appInForeground() {
    doReturn(25L).when(mockConfigResolver).getSessionsCpuCaptureFrequencyForegroundMs();
    doReturn(15L).when(mockConfigResolver).getSessionsMemoryCaptureFrequencyForegroundMs();
    PerfSession fakeSession = new PerfSession("sessionId", new Clock());
    testGaugeManager.startCollectingGauges(fakeSession, ApplicationProcessState.FOREGROUND);
    assertThat(fakeScheduledExecutorService.isEmpty()).isFalse();
    assertThat(fakeScheduledExecutorService.getDelayToNextTask(TimeUnit.MILLISECONDS)).isEqualTo(15L * APPROX_NUMBER_OF_DATA_POINTS_PER_GAUGE_METRIC);
}
Also used : PerfSession(com.google.firebase.perf.session.PerfSession) Clock(com.google.firebase.perf.util.Clock) Test(org.junit.Test)

Aggregations

PerfSession (com.google.firebase.perf.session.PerfSession)22 Clock (com.google.firebase.perf.util.Clock)19 Test (org.junit.Test)19 Timer (com.google.firebase.perf.util.Timer)7 AndroidMemoryReading (com.google.firebase.perf.v1.AndroidMemoryReading)5 CpuMetricReading (com.google.firebase.perf.v1.CpuMetricReading)5 GaugeMetric (com.google.firebase.perf.v1.GaugeMetric)5 SessionManager (com.google.firebase.perf.session.SessionManager)2 Keep (androidx.annotation.Keep)1 NetworkRequestMetric (com.google.firebase.perf.v1.NetworkRequestMetric)1