Search in sources :

Example 1 with SessionManager

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

the class NetworkRequestMetricBuilder method setRequestStartTimeMicros.

/**
 * Sets the clientStartTimeUs for the current {@link NetworkRequestMetric}.
 *
 * <p>Note: The start of the request also trigger collection of a single {@link GaugeMetric} data
 * point depending upon the current {@link PerfSession} verbosity.
 *
 * @see GaugeManager#collectGaugeMetricOnce(Timer)
 * @see PerfSession#isGaugeAndEventCollectionEnabled()
 */
public NetworkRequestMetricBuilder setRequestStartTimeMicros(long time) {
    SessionManager sessionManager = SessionManager.getInstance();
    PerfSession perfSession = sessionManager.perfSession();
    SessionManager.getInstance().registerForSessionUpdates(weakReference);
    builder.setClientStartTimeUs(time);
    updateSession(perfSession);
    if (perfSession.isGaugeAndEventCollectionEnabled()) {
        gaugeManager.collectGaugeMetricOnce(perfSession.getTimer());
    }
    return this;
}
Also used : SessionManager(com.google.firebase.perf.session.SessionManager) PerfSession(com.google.firebase.perf.session.PerfSession)

Example 2 with SessionManager

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

the class TraceTest method testSessionIdNotAddedIfPerfSessionIsNull.

@Test
public void testSessionIdNotAddedIfPerfSessionIsNull() {
    Trace trace = Trace.getTrace("myRandomTrace4");
    trace.start();
    assertThat(trace.getSessions()).isNotNull();
    int numberOfSessionIds = trace.getSessions().size();
    new SessionManager(mock(GaugeManager.class), null, mock(AppStateMonitor.class)).onUpdateAppState(ApplicationProcessState.FOREGROUND);
    assertThat(trace.getSessions()).hasSize(numberOfSessionIds);
    trace.stop();
}
Also used : SessionManager(com.google.firebase.perf.session.SessionManager) Test(org.junit.Test)

Example 3 with SessionManager

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

the class NetworkRequestMetricBuilderTest method testSessionIdNotAddedIfPerfSessionIsNull.

@Test
public void testSessionIdNotAddedIfPerfSessionIsNull() {
    NetworkRequestMetricBuilder metricBuilder = NetworkRequestMetricBuilder.builder(mockTransportManager);
    metricBuilder.setRequestStartTimeMicros(/* time= */
    2000);
    assertThat(this.networkMetricBuilder.getSessions()).isNotNull();
    assertThat(this.networkMetricBuilder.getSessions()).isEmpty();
    int numberOfSessionIds = metricBuilder.getSessions().size();
    new SessionManager(mock(GaugeManager.class), null, mock(AppStateMonitor.class)).onUpdateAppState(ApplicationProcessState.FOREGROUND);
    assertThat(metricBuilder.getSessions()).hasSize(numberOfSessionIds);
}
Also used : SessionManager(com.google.firebase.perf.session.SessionManager) Test(org.junit.Test)

Example 4 with SessionManager

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

the class Trace method start.

/**
 * Starts this trace.
 */
@Keep
public void start() {
    if (!ConfigResolver.getInstance().isPerformanceMonitoringEnabled()) {
        logger.debug("Trace feature is disabled.");
        return;
    }
    String err = validateTraceName(name);
    if (err != null) {
        logger.error("Cannot start trace '%s'. Trace name is invalid.(%s)", name, err);
        return;
    }
    if (startTime != null) {
        logger.error("Trace '%s' has already started, should not start again!", name);
        return;
    }
    startTime = clock.getTime();
    registerForAppState();
    SessionManager sessionManager = SessionManager.getInstance();
    PerfSession perfSession = sessionManager.perfSession();
    SessionManager.getInstance().registerForSessionUpdates(sessionAwareObject);
    updateSession(perfSession);
    if (perfSession.isGaugeAndEventCollectionEnabled()) {
        gaugeManager.collectGaugeMetricOnce(perfSession.getTimer());
    }
}
Also used : SessionManager(com.google.firebase.perf.session.SessionManager) PerfSession(com.google.firebase.perf.session.PerfSession) Keep(androidx.annotation.Keep)

Aggregations

SessionManager (com.google.firebase.perf.session.SessionManager)4 PerfSession (com.google.firebase.perf.session.PerfSession)2 Test (org.junit.Test)2 Keep (androidx.annotation.Keep)1