Search in sources :

Example 11 with Trace

use of com.google.firebase.perf.metrics.Trace 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)

Example 12 with Trace

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

the class PerformanceMonitoringTest method trace.

@Test
public void trace() {
    Trace trace = FirebasePerformance.getInstance().newTrace("test_trace");
    trace.start();
    trace.putMetric("counter", 1);
    trace.incrementMetric("counter", 2);
    trace.putAttribute("is_test", "true");
    trace.stop();
    assertThat(trace.getLongMetric("counter")).isEqualTo(3);
    assertThat(trace.getAttribute("is_test")).isEqualTo("true");
}
Also used : Trace(com.google.firebase.perf.metrics.Trace) Test(org.junit.Test)

Example 13 with Trace

use of com.google.firebase.perf.metrics.Trace 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 14 with Trace

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

the class FragmentStateMonitor method onFragmentResumed.

@Override
public void onFragmentResumed(@NonNull FragmentManager fm, @NonNull Fragment f) {
    super.onFragmentResumed(fm, f);
    // Start Fragment screen trace
    logger.debug("FragmentMonitor %s.onFragmentResumed", f.getClass().getSimpleName());
    Trace fragmentTrace = new Trace(getFragmentScreenTraceName(f), transportManager, clock, appStateMonitor);
    fragmentTrace.start();
    fragmentTrace.putAttribute(Constants.PARENT_FRAGMENT_ATTRIBUTE_KEY, f.getParentFragment() == null ? Constants.PARENT_FRAGMENT_ATTRIBUTE_VALUE_NONE : f.getParentFragment().getClass().getSimpleName());
    if (f.getActivity() != null) {
        fragmentTrace.putAttribute(Constants.ACTIVITY_ATTRIBUTE_KEY, f.getActivity().getClass().getSimpleName());
    }
    fragmentToTraceMap.put(f, fragmentTrace);
    activityFramesRecorder.startFragment(f);
}
Also used : Trace(com.google.firebase.perf.metrics.Trace)

Example 15 with Trace

use of com.google.firebase.perf.metrics.Trace 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

Trace (com.google.firebase.perf.metrics.Trace)25 AddTrace (com.google.firebase.perf.metrics.AddTrace)11 SharedPreferences (android.content.SharedPreferences)6 ConnectivityManager (android.net.ConnectivityManager)6 LinkProperties (android.net.LinkProperties)6 Network (android.net.Network)6 FirebaseRemoteConfigSettings (com.google.firebase.remoteconfig.FirebaseRemoteConfigSettings)6 ITransaction (io.sentry.ITransaction)6 Intent (android.content.Intent)5 Bundle (android.os.Bundle)5 View (android.view.View)5 ImageView (android.widget.ImageView)5 WebView (android.webkit.WebView)3 PluginMethod (com.getcapacitor.PluginMethod)3 PerfFrameMetrics (com.google.firebase.perf.metrics.FrameMetricsCalculator.PerfFrameMetrics)2 ApplicationProcessState (com.google.firebase.perf.v1.ApplicationProcessState)2 TraceMetric (com.google.firebase.perf.v1.TraceMetric)2 Test (org.junit.Test)2 Button (android.widget.Button)1 CompoundButton (android.widget.CompoundButton)1