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