stopTracingAndDownloadTimeline method

  1. @override
Future<Timeline> stopTracingAndDownloadTimeline({
  1. Duration timeout = kUnusuallyLongTimeout,
})
override

Stops recording performance traces and downloads the timeline.

The timeout argument causes a warning to be displayed to the user if the operation exceeds the specified timeout; it does not actually cancel the operation.

For WebFlutterDriver, this is only supported for Chrome.

Implementation

@override
Future<Timeline> stopTracingAndDownloadTimeline({Duration timeout = kUnusuallyLongTimeout}) async {
  _checkBrowserSupportsTimeline();

  final List<Map<String, dynamic>> events = <Map<String, dynamic>>[];
  for (final async_io.LogEntry entry in await _connection.logs.toList()) {
    if (_startTime.isBefore(entry.timestamp)) {
      final Map<String, dynamic> data = (jsonDecode(entry.message!) as Map<String, dynamic>)['message'] as Map<String, dynamic>;
      if (data['method'] == 'Tracing.dataCollected') {
        // 'ts' data collected from Chrome is in double format, conversion needed
        try {
          final Map<String, dynamic> params = data['params'] as Map<String, dynamic>;
          params['ts'] = double.parse(params['ts'].toString()).toInt();
        } on FormatException catch (_) {
          // data is corrupted, skip
          continue;
        }
        events.add(data['params']! as Map<String, dynamic>);
      }
    }
  }
  final Map<String, dynamic> json = <String, dynamic>{
    'traceEvents': events,
  };
  return Timeline.fromJson(json);
}