Search in sources :

Example 1 with AppStateMonitor

use of com.google.firebase.perf.application.AppStateMonitor in project firebase-android-sdk by firebase.

the class FirebasePerfProvider method attachInfo.

@Override
public void attachInfo(Context context, ProviderInfo info) {
    // super.attachInfo calls onCreate(). Fail as early as possible.
    checkContentProviderAuthority(info);
    super.attachInfo(context, info);
    // Initialize ConfigResolver early for accessing device caching layer.
    ConfigResolver configResolver = ConfigResolver.getInstance();
    configResolver.setContentProviderContext(getContext());
    AppStateMonitor appStateMonitor = AppStateMonitor.getInstance();
    appStateMonitor.registerActivityLifecycleCallbacks(getContext());
    appStateMonitor.registerForAppColdStart(new FirebasePerformanceInitializer());
    AppStartTrace appStartTrace = AppStartTrace.getInstance();
    appStartTrace.registerActivityLifecycleCallbacks(getContext());
    mainHandler.post(new AppStartTrace.StartFromBackgroundRunnable(appStartTrace));
    // In the case of cold start, we create a session and start collecting gauges as early as
    // possible.
    // There is code in SessionManager that prevents us from resetting the session twice in case
    // of app cold start.
    SessionManager.getInstance().initializeGaugeCollection();
}
Also used : ConfigResolver(com.google.firebase.perf.config.ConfigResolver) AppStartTrace(com.google.firebase.perf.metrics.AppStartTrace) AppStateMonitor(com.google.firebase.perf.application.AppStateMonitor) FirebasePerformanceInitializer(com.google.firebase.perf.FirebasePerformanceInitializer)

Example 2 with AppStateMonitor

use of com.google.firebase.perf.application.AppStateMonitor in project firebase-android-sdk by firebase.

the class FirebasePerfTraceValidatorTest method createValidTraceMetric.

private TraceMetric.Builder createValidTraceMetric() {
    String traceName = "trace_1";
    long expectedClientStartTime = 1;
    long expectedTraceDuration = 50;
    TransportManager transportManager = mock(TransportManager.class);
    AppStateMonitor appStateMonitor = mock(AppStateMonitor.class);
    ArgumentCaptor<TraceMetric> argMetric = ArgumentCaptor.forClass(TraceMetric.class);
    Trace trace = new Trace(traceName, transportManager, clock, appStateMonitor);
    currentTime = expectedClientStartTime;
    trace.start();
    currentTime += expectedTraceDuration;
    trace.stop();
    verify(transportManager).log(argMetric.capture(), ArgumentMatchers.nullable(ApplicationProcessState.class));
    TraceMetric traceMetric = argMetric.getValue();
    assertThat(traceMetric.getName()).isEqualTo(traceName);
    assertThat(traceMetric.getClientStartTimeUs()).isEqualTo(expectedClientStartTime);
    assertThat(traceMetric.getDurationUs()).isEqualTo(expectedTraceDuration);
    return traceMetric.toBuilder();
}
Also used : Trace(com.google.firebase.perf.metrics.Trace) TraceMetric(com.google.firebase.perf.v1.TraceMetric) ApplicationProcessState(com.google.firebase.perf.v1.ApplicationProcessState) AppStateMonitor(com.google.firebase.perf.application.AppStateMonitor) TransportManager(com.google.firebase.perf.transport.TransportManager)

Aggregations

AppStateMonitor (com.google.firebase.perf.application.AppStateMonitor)2 FirebasePerformanceInitializer (com.google.firebase.perf.FirebasePerformanceInitializer)1 ConfigResolver (com.google.firebase.perf.config.ConfigResolver)1 AppStartTrace (com.google.firebase.perf.metrics.AppStartTrace)1 Trace (com.google.firebase.perf.metrics.Trace)1 TransportManager (com.google.firebase.perf.transport.TransportManager)1 ApplicationProcessState (com.google.firebase.perf.v1.ApplicationProcessState)1 TraceMetric (com.google.firebase.perf.v1.TraceMetric)1