Search in sources :

Example 1 with CpuMetricReading

use of com.google.firebase.perf.v1.CpuMetricReading 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);
}
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 2 with CpuMetricReading

use of com.google.firebase.perf.v1.CpuMetricReading 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 3 with CpuMetricReading

use of com.google.firebase.perf.v1.CpuMetricReading 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);
}
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 4 with CpuMetricReading

use of com.google.firebase.perf.v1.CpuMetricReading in project firebase-android-sdk by firebase.

the class GaugeManagerTest method testStartGaugeManagerWithNewSessionIdAndNewAppState.

@Test
public void testStartGaugeManagerWithNewSessionIdAndNewAppState() {
    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 and new app state
    testGaugeManager.startCollectingGauges(fakeSession2, 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("sessionId2", recordedGaugeMetric3, fakeCpuMetricReading3);
    assertThatMemoryGaugeMetricWasSentToTransport("sessionId2", recordedGaugeMetric3, fakeMemoryMetricReading3);
}
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 5 with CpuMetricReading

use of com.google.firebase.perf.v1.CpuMetricReading in project firebase-android-sdk by firebase.

the class TransportManagerTest method validGaugeMetric_withCpuReadings_isLogged.

// endregion
// region Gauge Specific
@Test
public void validGaugeMetric_withCpuReadings_isLogged() {
    ApplicationProcessState expectedAppState = ApplicationProcessState.FOREGROUND;
    // 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));
    GaugeMetric validGauge = GaugeMetric.newBuilder().setSessionId("sessionId").addAllCpuMetricReadings(expectedCpuMetricReadings).build();
    testTransportManager.log(validGauge, expectedAppState);
    fakeExecutorService.runAll();
    PerfMetric loggedPerfMetric = getLastLoggedEvent(times(1));
    assertThat(loggedPerfMetric.getGaugeMetric().getCpuMetricReadingsList()).containsExactlyElementsIn(expectedCpuMetricReadings);
    assertThat(loggedPerfMetric.getGaugeMetric().getSessionId()).isEqualTo("sessionId");
}
Also used : ApplicationProcessState(com.google.firebase.perf.v1.ApplicationProcessState) CpuMetricReading(com.google.firebase.perf.v1.CpuMetricReading) PerfMetric(com.google.firebase.perf.v1.PerfMetric) ArrayList(java.util.ArrayList) GaugeMetric(com.google.firebase.perf.v1.GaugeMetric) Test(org.junit.Test)

Aggregations

CpuMetricReading (com.google.firebase.perf.v1.CpuMetricReading)10 Test (org.junit.Test)10 GaugeMetric (com.google.firebase.perf.v1.GaugeMetric)7 AndroidMemoryReading (com.google.firebase.perf.v1.AndroidMemoryReading)6 PerfSession (com.google.firebase.perf.session.PerfSession)5 Clock (com.google.firebase.perf.util.Clock)5 Timer (com.google.firebase.perf.util.Timer)3 ArrayList (java.util.ArrayList)2 ApplicationProcessState (com.google.firebase.perf.v1.ApplicationProcessState)1 GaugeMetadata (com.google.firebase.perf.v1.GaugeMetadata)1 PerfMetric (com.google.firebase.perf.v1.PerfMetric)1