traceTimeline method

Future<Timeline> traceTimeline(
  1. Future action(
      ),
    1. {List<String> streams = const <String>['all'],
    2. bool retainPriorEvents = false}
    )

    Runs action and returns a vm.Timeline trace for it.

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

    The streams parameter limits the recorded timeline event streams to only the ones listed. By default, all streams are recorded. See timeline_streams in Dart-SDK/runtime/vm/timeline.cc

    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.

    Implementation

    Future<vm.Timeline> traceTimeline(
      Future<dynamic> Function() action, {
      List<String> streams = const <String>['all'],
      bool retainPriorEvents = false,
    }) async {
      await enableTimeline(streams: streams);
      if (retainPriorEvents) {
        await action();
        return _vmService!.getVMTimeline();
      }
    
      await _vmService!.clearVMTimeline();
      final vm.Timestamp startTime = await _vmService!.getVMTimelineMicros();
      await action();
      final vm.Timestamp endTime = await _vmService!.getVMTimelineMicros();
      return _vmService!.getVMTimeline(
        timeOriginMicros: startTime.timestamp,
        timeExtentMicros: endTime.timestamp,
      );
    }