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));
}
Aggregations