use of com.google.firebase.perf.metrics.FrameMetricsCalculator.PerfFrameMetrics in project firebase-android-sdk by firebase.
the class FrameMetricsRecorderTest method startAndStopSubTrace_whenCalledTwice_ignoresSecondCall.
/**
* This scenario happens only when we hook on to the same instance of fragment twice, which should
* never happen
*/
@Test
public void startAndStopSubTrace_whenCalledTwice_ignoresSecondCall() {
Fragment fragment = new Fragment();
// comments are in this format: total frames, slow frames, frozen frames
recorder.start();
// 3, 2, 1
stubFrameMetricsAggregatorData(fma, new int[][] { { 1, 1 }, { 17, 1 }, { 800, 1 } });
recorder.startFragment(fragment);
// ignored
stubFrameMetricsAggregatorData(fma, new int[][] { { 1, 2 }, { 17, 3 }, { 800, 2 } });
// this call is ignored
recorder.startFragment(fragment);
// 14, 9, 5
stubFrameMetricsAggregatorData(fma, new int[][] { { 1, 5 }, { 17, 4 }, { 800, 5 } });
Optional<PerfFrameMetrics> result1 = recorder.stopFragment(fragment);
// ignored
stubFrameMetricsAggregatorData(fma, new int[][] { { 1, 6 }, { 17, 5 }, { 800, 5 } });
// this call is ignored
Optional<PerfFrameMetrics> result2 = recorder.stopFragment(fragment);
// total = 14 - 3 = 11, slow = 9 - 2 = 7, frozen = 5 - 1 = 4
assertThat(result1.get().getTotalFrames()).isEqualTo(14 - 3);
assertThat(result1.get().getSlowFrames()).isEqualTo(9 - 2);
assertThat(result1.get().getFrozenFrames()).isEqualTo(5 - 1);
assertThat(result2.isAvailable()).isFalse();
}
use of com.google.firebase.perf.metrics.FrameMetricsCalculator.PerfFrameMetrics in project firebase-android-sdk by firebase.
the class FrameMetricsRecorderTest method startAndStopSubTrace_notContainedWithinActivityRecordingStartAndStop_returnsEmptyResult.
/**
* This case happens when AppStateMonitor calls stop() before all Fragment traces are stopped by
* stopFragment(fragment), leaving some dangling fragment traces that are invalid. Even if
* activity recording starts again later, then stopFragment(fragment) is called, it should not
* return a result which is incorrect.
*/
@Test
public void startAndStopSubTrace_notContainedWithinActivityRecordingStartAndStop_returnsEmptyResult() {
Fragment fragment = new Fragment();
recorder.start();
stubFrameMetricsAggregatorData(fma, frameTimesDefault);
recorder.startFragment(fragment);
stubFrameMetricsAggregatorData(fma, frameTimes1);
recorder.stop();
recorder.start();
stubFrameMetricsAggregatorData(fma, frameTimes2);
// invalid dangling trace
Optional<PerfFrameMetrics> result = recorder.stopFragment(fragment);
assertThat(result.isAvailable()).isFalse();
}
use of com.google.firebase.perf.metrics.FrameMetricsCalculator.PerfFrameMetrics in project firebase-android-sdk by firebase.
the class FrameMetricsRecorderTest method startAndStopSubTrace_activityRecordingNeverStarted_returnsEmptyResult.
@Test
public void startAndStopSubTrace_activityRecordingNeverStarted_returnsEmptyResult() {
Fragment fragment = new Fragment();
stubFrameMetricsAggregatorData(fma, frameTimes1);
recorder.startFragment(fragment);
stubFrameMetricsAggregatorData(fma, frameTimes2);
Optional<PerfFrameMetrics> result = recorder.stopFragment(fragment);
assertThat(result.isAvailable()).isFalse();
}
use of com.google.firebase.perf.metrics.FrameMetricsCalculator.PerfFrameMetrics in project firebase-android-sdk by firebase.
the class AppStateMonitor method sendScreenTrace.
/**
* Sends the screen trace for the provided activity.
*
* @param activity activity object.
*/
private void sendScreenTrace(Activity activity) {
Trace screenTrace = activityToScreenTraceMap.get(activity);
if (screenTrace == null) {
return;
}
activityToScreenTraceMap.remove(activity);
Optional<PerfFrameMetrics> perfFrameMetrics = activityToRecorderMap.get(activity).stop();
if (!perfFrameMetrics.isAvailable()) {
logger.warn("Failed to record frame data for %s.", activity.getClass().getSimpleName());
return;
}
ScreenTraceUtil.addFrameCounters(screenTrace, perfFrameMetrics.get());
// Stop and record trace
screenTrace.stop();
}
use of com.google.firebase.perf.metrics.FrameMetricsCalculator.PerfFrameMetrics in project firebase-android-sdk by firebase.
the class FragmentStateMonitor method onFragmentPaused.
@Override
public void onFragmentPaused(@NonNull FragmentManager fm, @NonNull Fragment f) {
super.onFragmentPaused(fm, f);
// Stop Fragment screen trace
logger.debug("FragmentMonitor %s.onFragmentPaused ", f.getClass().getSimpleName());
if (!fragmentToTraceMap.containsKey(f)) {
logger.warn("FragmentMonitor: missed a fragment trace from %s", f.getClass().getSimpleName());
return;
}
Trace fragmentTrace = fragmentToTraceMap.get(f);
fragmentToTraceMap.remove(f);
Optional<PerfFrameMetrics> frameMetricsData = activityFramesRecorder.stopFragment(f);
if (!frameMetricsData.isAvailable()) {
logger.warn("onFragmentPaused: recorder failed to trace %s", f.getClass().getSimpleName());
return;
}
ScreenTraceUtil.addFrameCounters(fragmentTrace, frameMetricsData.get());
fragmentTrace.stop();
}
Aggregations