Search in sources :

Example 6 with PerfFrameMetrics

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();
}
Also used : PerfFrameMetrics(com.google.firebase.perf.metrics.FrameMetricsCalculator.PerfFrameMetrics) Fragment(androidx.fragment.app.Fragment) Test(org.junit.Test)

Example 7 with PerfFrameMetrics

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();
}
Also used : PerfFrameMetrics(com.google.firebase.perf.metrics.FrameMetricsCalculator.PerfFrameMetrics) Fragment(androidx.fragment.app.Fragment) Test(org.junit.Test)

Example 8 with PerfFrameMetrics

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();
}
Also used : PerfFrameMetrics(com.google.firebase.perf.metrics.FrameMetricsCalculator.PerfFrameMetrics) Fragment(androidx.fragment.app.Fragment) Test(org.junit.Test)

Example 9 with PerfFrameMetrics

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();
}
Also used : Trace(com.google.firebase.perf.metrics.Trace) PerfFrameMetrics(com.google.firebase.perf.metrics.FrameMetricsCalculator.PerfFrameMetrics)

Example 10 with PerfFrameMetrics

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();
}
Also used : Trace(com.google.firebase.perf.metrics.Trace) 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