Skip to content

Commit

Permalink
use epoch
Browse files Browse the repository at this point in the history
  • Loading branch information
buenaflor committed Feb 6, 2024
1 parent f2668bb commit 6a707da
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class NativeAppStartEventProcessor implements EventProcessor {
if (measurement.value >= _maxAppStartMillis) {
return event;
}
print('hello app');
event.measurements[measurement.name] = measurement;
}
return event;
Expand Down
23 changes: 18 additions & 5 deletions flutter/lib/src/navigation/sentry_navigator_observer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class SentryNavigatorObserver extends RouteObserver<PageRoute<dynamic>> {
SchedulerBinding.instance.addPostFrameCallback((timeStamp) {
approximationEndTimestamp = DateTime.now();
approximationDurationMillis =
approximationEndTimestamp!.millisecond - startTime.millisecond;
approximationEndTimestamp!.millisecondsSinceEpoch - startTime.millisecondsSinceEpoch;
});

SentryDisplayTracker().startTimeout(routeName ?? 'Unknown', () {
Expand All @@ -139,6 +139,7 @@ class SentryNavigatorObserver extends RouteObserver<PageRoute<dynamic>> {
'time_to_initial_display', approximationDurationMillis!,
unit: DurationSentryMeasurementUnit.milliSecond);
ttidSpan?.finish(endTimestamp: approximationEndTimestamp!);
print('finished already');
});
}

Expand Down Expand Up @@ -276,17 +277,29 @@ class SentryNavigatorObserver extends RouteObserver<PageRoute<dynamic>> {
return;
}

startTime = DateTime.now();
ttidSpan = _transaction2?.startChild('ui.load.initial_display', description: '$name initial display');
ttidSpan?.origin = 'auto.ui.time_to_display';
if (name == 'root ("/")') {
// root ttid spans have to align with app start
// so the ttid instrumentation needs to be different here.
startTime = DateTime.now();
ttidSpan = _transaction2?.startChild('ui.load.initial_display', description: '$name initial display', startTimestamp: startTime);
ttidSpan?.origin = 'auto.ui.time_to_display';
} else {
startTime = DateTime.now();
ttidSpan = _transaction2?.startChild('ui.load.initial_display', description: '$name initial display', startTimestamp: startTime);
ttidSpan?.origin = 'auto.ui.time_to_display';
}

// TODO: Needs to finish max within 30 seconds
// If timeout exceeds then it will finish with status deadline exceeded
// What to do if root also has TTFD but it's not finished yet and we start navigating to another?
// How to track the time that 30 sec have passed?
//
// temporarily disable ttfd for root since it somehow swallows other spans
// e.g the complex operation span in autoclosescreen
if ((_hub.options as SentryFlutterOptions).enableTimeToFullDisplayTracing && name != 'root ("/")') {
ttfdStopwatch = Stopwatch()..start();
ttfdSpan = _transaction2?.startChild('ui.load.full_display', description: '$name full display');
ttfdStartTime = DateTime.now();
ttfdSpan = _transaction2?.startChild('ui.load.full_display', description: '$name full display', startTimestamp: ttfdStartTime);
}

if (arguments != null) {
Expand Down
19 changes: 7 additions & 12 deletions flutter/lib/src/sentry_flutter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -235,25 +235,20 @@ mixin SentryFlutter {
if (!SentryDisplayTracker().reportManual(routeName)) {
SentryNavigatorObserver.transaction2?.setMeasurement(
'time_to_initial_display',
endTime.millisecond - SentryNavigatorObserver.startTime.millisecond,
endTime.millisecondsSinceEpoch - SentryNavigatorObserver.startTime.millisecondsSinceEpoch,
unit: DurationSentryMeasurementUnit.milliSecond);

SentryNavigatorObserver.ttidSpan?.setTag('measurement', 'manual');
SentryNavigatorObserver.ttidSpan?.finish(endTimestamp: endTime);
}
}

/// Reports the time it took for the screen to be fully displayed.
static void reportFullDisplay() {
if (SentryNavigatorObserver.ttfdStopwatch?.elapsedMilliseconds != null) {
SentryNavigatorObserver.ttfdStopwatch?.stop();
SentryNavigatorObserver.ttfdSpan?.setMeasurement(
'time_to_full_display',
SentryNavigatorObserver.ttfdStopwatch!.elapsedMilliseconds,
unit: DurationSentryMeasurementUnit.milliSecond);
SentryNavigatorObserver.ttfdStopwatch?.reset();
}
SentryNavigatorObserver.ttfdSpan?.finish();
final endTime = DateTime.now();
SentryNavigatorObserver.ttfdSpan?.setMeasurement(
'time_to_full_display',
endTime.millisecondsSinceEpoch - SentryNavigatorObserver.ttfdStartTime.millisecondsSinceEpoch,
unit: DurationSentryMeasurementUnit.milliSecond);
SentryNavigatorObserver.ttfdSpan?.finish(endTimestamp: endTime);
}

@internal
Expand Down
2 changes: 1 addition & 1 deletion flutter/lib/src/sentry_flutter_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ class SentryFlutterOptions extends SentryOptions {
/// Read timeout. This will only be synced to the Android native SDK.
Duration readTimeout = Duration(seconds: 5);

/// Enable or disable the tracing of time to full display.
/// Enable or disable the tracing of time to full display (TTFD).
/// This feature requires using the [Routing Instrumentation](https://docs.sentry.io/platforms/flutter/integrations/routing-instrumentation/).
bool enableTimeToFullDisplayTracing = false;

Expand Down

0 comments on commit 6a707da

Please sign in to comment.