Search in sources :

Example 6 with Trace

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

the class FirebasePerformance method startTrace.

/**
 * Creates a Trace object with given name and start the trace.
 *
 * @param traceName name of the trace. Requires no leading or trailing whitespace, no leading
 *     underscore [_] character, max length of {@link #MAX_TRACE_NAME_LENGTH} characters.
 * @return the new Trace object.
 */
@NonNull
public static Trace startTrace(@NonNull String traceName) {
    Trace trace = Trace.create(traceName);
    trace.start();
    return trace;
}
Also used : Trace(com.google.firebase.perf.metrics.Trace) NonNull(androidx.annotation.NonNull)

Example 7 with Trace

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

the class AppStateMonitor method onActivityStarted.

@Override
public synchronized void onActivityStarted(Activity activity) {
    if (isScreenTraceSupported() && configResolver.isPerformanceMonitoringEnabled()) {
        if (!activityToRecorderMap.containsKey(activity)) {
            // If performance monitoring is disabled at start and enabled at runtime, start monitoring
            // the activity as the app comes to foreground.
            startFrameMonitoring(activity);
        }
        // Starts recording frame metrics for this activity.
        activityToRecorderMap.get(activity).start();
        // Start the Trace
        Trace screenTrace = new Trace(getScreenTraceName(activity), transportManager, clock, this);
        screenTrace.start();
        activityToScreenTraceMap.put(activity, screenTrace);
    }
}
Also used : Trace(com.google.firebase.perf.metrics.Trace)

Example 8 with Trace

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

the class AnotherActivity method onCreate.

@Override
@AddTrace(name = "AnotherActivity.onCreate", enabled = true)
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Log.d(LOG_TAG, "AnotherActivity.onCreate");
    setContentView(R.layout.another_activity);
    Trace trace = getIntent().getParcelableExtra("trace");
    trace.stop();
    finish();
}
Also used : Trace(com.google.firebase.perf.metrics.Trace) AddTrace(com.google.firebase.perf.metrics.AddTrace) AddTrace(com.google.firebase.perf.metrics.AddTrace)

Example 9 with Trace

use of com.google.firebase.perf.metrics.Trace in project SORMAS-Project by hzi-braunschweig.

the class SynchronizeDataAsync method doInBackground.

@Override
protected Void doInBackground(Void... params) {
    if (!RetroProvider.isConnected()) {
        return null;
    }
    if (ConfigProvider.isRepullNeeded()) {
        syncMode = SyncMode.CompleteAndRepull;
    }
    try {
        Trace syncModeTrace;
        switch(syncMode) {
            case Changes:
                syncModeTrace = FirebasePerformance.getInstance().newTrace("syncModeChangesTrace");
                syncModeTrace.start();
                // Prioritize pushing new data
                pushNewData();
                // Infrastructure always has to be pulled - otherwise referenced data may be lost (e.g. #586)
                pullInfrastructure();
                // Pull and remove deleted entities when the last time this has been done is more than 24 hours ago
                if (ConfigProvider.getLastDeletedSyncDate() == null || DateHelper.getFullDaysBetween(ConfigProvider.getLastDeletedSyncDate(), new Date()) >= 1) {
                    pullAndRemoveDeletedUuidsSince(ConfigProvider.getLastDeletedSyncDate());
                }
                // Pull and remove archived entities when the last time this has been done is more than 24 hours ago
                if (ConfigProvider.getLastArchivedSyncDate() == null || DateHelper.getFullDaysBetween(ConfigProvider.getLastArchivedSyncDate(), new Date()) >= 1) {
                    pullAndRemoveArchivedUuidsSince(ConfigProvider.getLastArchivedSyncDate());
                }
                // Pull changed data and push existing data that has been changed on the mobile device
                synchronizeChangedData();
                syncModeTrace.stop();
                break;
            case Complete:
                syncModeTrace = FirebasePerformance.getInstance().newTrace("syncModeCompleteTrace");
                syncModeTrace.start();
                // do before missing, because we may have a completely empty database
                pullInfrastructure();
                pullMissingAndDeleteInvalidInfrastructure();
                pushNewPullMissingAndDeleteInvalidData();
                synchronizeChangedData();
                syncModeTrace.stop();
                break;
            case CompleteAndRepull:
                syncModeTrace = FirebasePerformance.getInstance().newTrace("syncModeCompleteAndRepullTrace");
                syncModeTrace.start();
                // do before missing, because we may have a completely empty database
                pullInfrastructure();
                pullMissingAndDeleteInvalidInfrastructure();
                repullData();
                pushNewPullMissingAndDeleteInvalidData();
                synchronizeChangedData();
                ConfigProvider.setRepullNeeded(false);
                syncModeTrace.stop();
                break;
            default:
                throw new IllegalArgumentException(syncMode.toString());
        }
        if (syncMode == SyncMode.Changes && hasAnyUnsynchronizedData()) {
            Log.w(getClass().getName(), "Still having unsynchronized data. Trying again in complete mode.");
            syncMode = SyncMode.Complete;
            doInBackground(params);
        }
    } catch (ServerConnectionException e) {
        syncFailed = true;
        syncFailedMessage = e.getMessage(context);
        RetroProvider.disconnect();
    } catch (NoConnectionException | ServerCommunicationException e) {
        Log.e(getClass().getName(), "Error trying to synchronizing data in mode '" + syncMode + "'", e);
        ErrorReportingHelper.sendCaughtException(e);
        syncFailed = true;
        syncFailedMessage = DatabaseHelper.getContext().getString(R.string.error_server_communication);
        RetroProvider.disconnect();
    } catch (RuntimeException | DaoException e) {
        SyncMode newSyncMode = null;
        switch(syncMode) {
            case Changes:
                newSyncMode = SyncMode.Complete;
                break;
            case Complete:
                newSyncMode = SyncMode.CompleteAndRepull;
                break;
            case CompleteAndRepull:
                break;
            default:
                throw new IllegalArgumentException(syncMode.toString());
        }
        if (newSyncMode != null) {
            Log.w(getClass().getName(), "Error trying to synchronizing data in mode '" + syncMode + "'", e);
            ErrorReportingHelper.sendCaughtException(e);
            syncMode = newSyncMode;
            doInBackground(params);
        } else {
            Log.e(getClass().getName(), "Error trying to synchronizing data in mode '" + syncMode + "'", e);
            ErrorReportingHelper.sendCaughtException(e);
            syncFailed = true;
            syncFailedMessage = DatabaseHelper.getContext().getString(R.string.error_synchronization);
            RetroProvider.disconnect();
        }
    }
    return null;
}
Also used : AddTrace(com.google.firebase.perf.metrics.AddTrace) Trace(com.google.firebase.perf.metrics.Trace) DaoException(de.symeda.sormas.app.backend.common.DaoException) Date(java.util.Date)

Example 10 with Trace

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

the class AppStateMonitorTest method testAppStateCallbackWithTrace.

@Test
public void testAppStateCallbackWithTrace() {
    AppStateMonitor monitor = new AppStateMonitor(transportManager, clock);
    Trace trace = new Trace("TRACE_1", transportManager, clock, monitor);
    // Trace is not started yet, default state is APPLICATION_PROCESS_STATE_UNKNOWN
    Assert.assertEquals(ApplicationProcessState.APPLICATION_PROCESS_STATE_UNKNOWN, trace.getAppState());
    // activity1 comes to foreground.
    currentTime = 1;
    // registerForAppState() is called by Trace.start().
    trace.start();
    // Trace started, get state from AppStateMonitor.
    Assert.assertEquals(ApplicationProcessState.BACKGROUND, trace.getAppState());
    monitor.onActivityResumed(activity1);
    Assert.assertTrue(monitor.isForeground());
    Assert.assertEquals(FOREGROUND_BACKGROUND, trace.getAppState());
    verify(transportManager, times(0)).log(argTraceMetric.capture(), nullable(ApplicationProcessState.class));
    // activity1 goes to background.
    currentTime = 2;
    monitor.onActivityStopped(activity1);
    Assert.assertFalse(monitor.isForeground());
    // Foreground session trace.
    verify(transportManager, times(1)).log(argTraceMetric.capture(), eq(FOREGROUND_BACKGROUND));
    // Trace is updated through AppStatCallback.
    Assert.assertEquals(FOREGROUND_BACKGROUND, trace.getAppState());
    // unregisterForAppState() is called by Trace.stop()
    trace.stop();
    // trace has been through FOREGROUND_BACKGROUND
    Assert.assertEquals(FOREGROUND_BACKGROUND, trace.getAppState());
    // a TraceMetric is sent for this trace object.
    verify(transportManager, times(2)).log(argTraceMetric.capture(), eq(FOREGROUND_BACKGROUND));
    TraceMetric metric = argTraceMetric.getValue();
    Assert.assertEquals("TRACE_1", metric.getName());
}
Also used : Trace(com.google.firebase.perf.metrics.Trace) ApplicationProcessState(com.google.firebase.perf.v1.ApplicationProcessState) TraceMetric(com.google.firebase.perf.v1.TraceMetric) Test(org.junit.Test)

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