From 265168170d04fb1fd395dfd235588e1df3dad664 Mon Sep 17 00:00:00 2001 From: Kaushik Iska Date: Mon, 27 Apr 2020 14:03:43 -0700 Subject: [PATCH] [timeline] Sort timeline events before summarizing (#55763) --- .../lib/src/driver/timeline.dart | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/packages/flutter_driver/lib/src/driver/timeline.dart b/packages/flutter_driver/lib/src/driver/timeline.dart index 963379cc3fe..a12f903383a 100644 --- a/packages/flutter_driver/lib/src/driver/timeline.dart +++ b/packages/flutter_driver/lib/src/driver/timeline.dart @@ -34,12 +34,8 @@ class TimelineEvent { json['ph'] as String, json['pid'] as int, json['tid'] as int, - json['dur'] != null - ? Duration(microseconds: json['dur'] as int) - : null, - json['tdur'] != null - ? Duration(microseconds: json['tdur'] as int) - : null, + json['dur'] != null ? Duration(microseconds: json['dur'] as int) : null, + json['tdur'] != null ? Duration(microseconds: json['tdur'] as int) : null, json['ts'] as int, json['tts'] as int, json['args'] as Map, @@ -124,11 +120,20 @@ class TimelineEvent { List _parseEvents(Map json) { final List jsonEvents = json['traceEvents'] as List; - if (jsonEvents == null) + if (jsonEvents == null) { return null; + } // TODO(vegorov): use instance method version of castFrom when it is available. - return Iterable.castFrom>(jsonEvents) - .map((Map eventJson) => TimelineEvent(eventJson)) - .toList(); + final List timelineEvents = + Iterable.castFrom>(jsonEvents) + .map( + (Map eventJson) => TimelineEvent(eventJson)) + .toList(); + + timelineEvents.sort((TimelineEvent e1, TimelineEvent e2) { + return e1.timestampMicros.compareTo(e2.timestampMicros); + }); + + return timelineEvents; }