Search in sources :

Example 11 with PerfFrameMetrics

use of com.google.firebase.perf.metrics.FrameMetricsCalculator.PerfFrameMetrics in project firebase-android-sdk by firebase.

the class FrameMetricsRecorder method stopFragment.

/**
 * Stops the sub-recording associated with the given Fragment. Fragments are sub-recordings due to
 * the way frame metrics work: frame metrics can only comes from an activity's window. An analogy
 * for sub-recording is a lap in a stopwatch.
 *
 * @param fragment the Fragment associated with the sub-recording to be stopped.
 * @return FrameMetrics accumulated during this sub-recording.
 */
public Optional<PerfFrameMetrics> stopFragment(Fragment fragment) {
    if (!isRecording) {
        logger.debug("Cannot stop sub-recording because FrameMetricsAggregator is not recording");
        return Optional.absent();
    }
    if (!fragmentSnapshotMap.containsKey(fragment)) {
        logger.debug("Sub-recording associated with key %s was not started or does not exist", fragment.getClass().getSimpleName());
        return Optional.absent();
    }
    PerfFrameMetrics snapshotStart = fragmentSnapshotMap.remove(fragment);
    Optional<PerfFrameMetrics> snapshotEnd = this.snapshot();
    if (!snapshotEnd.isAvailable()) {
        logger.debug("stopFragment(%s): snapshot() failed", fragment.getClass().getSimpleName());
        return Optional.absent();
    }
    return Optional.of(snapshotEnd.get().deltaFrameMetricsFromSnapshot(snapshotStart));
}
Also used : PerfFrameMetrics(com.google.firebase.perf.metrics.FrameMetricsCalculator.PerfFrameMetrics)

Aggregations

PerfFrameMetrics (com.google.firebase.perf.metrics.FrameMetricsCalculator.PerfFrameMetrics)11 Fragment (androidx.fragment.app.Fragment)8 Test (org.junit.Test)8 Trace (com.google.firebase.perf.metrics.Trace)3 Activity (android.app.Activity)1 Bundle (android.os.Bundle)1 WindowManager (android.view.WindowManager)1 AppCompatActivity (androidx.appcompat.app.AppCompatActivity)1 FragmentManager (androidx.fragment.app.FragmentManager)1 Truth.assertThat (com.google.common.truth.Truth.assertThat)1 FirebasePerformanceTestBase (com.google.firebase.perf.FirebasePerformanceTestBase)1 ConfigResolver (com.google.firebase.perf.config.ConfigResolver)1 DeviceCacheManager (com.google.firebase.perf.config.DeviceCacheManager)1 TransportManager (com.google.firebase.perf.transport.TransportManager)1 Clock (com.google.firebase.perf.util.Clock)1 Constants (com.google.firebase.perf.util.Constants)1 CounterNames (com.google.firebase.perf.util.Constants.CounterNames)1 Optional (com.google.firebase.perf.util.Optional)1 Timer (com.google.firebase.perf.util.Timer)1 ApplicationProcessState (com.google.firebase.perf.v1.ApplicationProcessState)1