traceAction method

  1. @override
Future<Timeline> traceAction(
  1. Future action(), {
  2. List<TimelineStream> streams = const <TimelineStream>[TimelineStream.all],
  3. bool retainPriorEvents = false,
})
override

Runs action and outputs a performance trace for it.

Waits for the Future returned by action to complete prior to stopping the trace.

This is merely a convenience wrapper on top of startTracing and stopTracingAndDownloadTimeline.

streams limits the recorded timeline event streams to only the ones listed. By default, all streams are recorded.

If retainPriorEvents is true, retains events recorded prior to calling action. Otherwise, prior events are cleared before calling action. By default, prior events are cleared.

If this is run in debug mode, a warning message will be printed to suggest running the benchmark in profile mode instead.

For WebFlutterDriver, this is only supported for Chrome.

Implementation

@override
Future<Timeline> traceAction(
    Future<dynamic> Function() action, {
      List<TimelineStream> streams = const <TimelineStream>[TimelineStream.all],
      bool retainPriorEvents = false,
    }) async {
  if (retainPriorEvents) {
    await startTracing(streams: streams);
    await action();

    if (!(await _isPrecompiledMode())) {
      _log(_kDebugWarning);
    }

    return stopTracingAndDownloadTimeline();
  }

  await clearTimeline();

  final vms.Timestamp startTimestamp = await _getVMTimelineMicros();
  await startTracing(streams: streams);
  await action();
  final vms.Timestamp endTimestamp = await _getVMTimelineMicros();

  if (!(await _isPrecompiledMode())) {
    _log(_kDebugWarning);
  }

  return stopTracingAndDownloadTimeline(
    startTime: startTimestamp.timestamp,
    endTime: endTimestamp.timestamp,
  );
}