From 14b5cb047e87f5aa40a33839c3f0e32a1ee3570e Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Mon, 20 Nov 2017 17:37:14 -0800 Subject: [PATCH] Use duration not threadDuration for frame duration (#13117) 1. We want to measure wall-clock duration for the benchmarks, as opposed to thread duration (e.g., waiting on a mutex should accrue time) and 'dur' is the metric to use for that. 2. On Darwin-based systems (macOS and iOS) 'tdur' is the result of a mach syscall lookup to thread_info. This call returns unreliable data on iOS. Chromium, for example, disables thread time support entirely for iOS. --- .../lib/src/timeline_summary.dart | 17 ++++++++--------- .../test/src/timeline_summary_test.dart | 2 +- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/packages/flutter_driver/lib/src/timeline_summary.dart b/packages/flutter_driver/lib/src/timeline_summary.dart index bc1e3c62ba..99a70c68df 100644 --- a/packages/flutter_driver/lib/src/timeline_summary.dart +++ b/packages/flutter_driver/lib/src/timeline_summary.dart @@ -30,19 +30,19 @@ class TimelineSummary { /// /// Returns null if no frames were recorded. double computeAverageFrameBuildTimeMillis() { - return _averageInMillis(_extractFrameThreadDurations()); + return _averageInMillis(_extractFrameDurations()); } /// The longest frame build time in milliseconds. /// /// Returns null if no frames were recorded. double computeWorstFrameBuildTimeMillis() { - return _maxInMillis(_extractFrameThreadDurations()); + return _maxInMillis(_extractFrameDurations()); } /// The number of frames that missed the [kBuildBudget] and therefore are /// in the danger of missing frames. - int computeMissedFrameBuildBudgetCount([Duration frameBuildBudget = kBuildBudget]) => _extractFrameThreadDurations() + int computeMissedFrameBuildBudgetCount([Duration frameBuildBudget = kBuildBudget]) => _extractFrameDurations() .where((Duration duration) => duration > kBuildBudget) .length; @@ -67,7 +67,7 @@ class TimelineSummary { .length; /// The total number of frames recorded in the timeline. - int countFrames() => _extractFrameThreadDurations().length; + int countFrames() => _extractFrameDurations().length; /// Encodes this summary as JSON. Map get summaryJson { @@ -79,7 +79,7 @@ class TimelineSummary { 'worst_frame_rasterizer_time_millis': computeWorstFrameRasterizerTimeMillis(), 'missed_frame_rasterizer_budget_count': computeMissedFrameRasterizerBudgetCount(), 'frame_count': countFrames(), - 'frame_build_times': _extractFrameThreadDurations() + 'frame_build_times': _extractFrameDurations() .map((Duration duration) => duration.inMicroseconds) .toList(), 'frame_rasterizer_times': _extractGpuRasterizerDrawEvents() @@ -124,9 +124,8 @@ class TimelineSummary { .toList(); } - List _extractThreadDurations(String name) { - return _extractNamedEvents(name) - .map((TimelineEvent event) => event.threadDuration).toList(); + List _extractDurations(String name) { + return _extractNamedEvents(name).map((TimelineEvent event) => event.duration).toList(); } /// Extracts timed events that are reported as a pair of begin/end events. @@ -171,7 +170,7 @@ class TimelineSummary { List _extractGpuRasterizerDrawEvents() => _extractBeginEndEvents('GPURasterizer::Draw'); - List _extractFrameThreadDurations() => _extractThreadDurations('Frame'); + List _extractFrameDurations() => _extractDurations('Frame'); Iterable _extractDuration(Iterable events) { return events.map((TimedEvent e) => e.duration); diff --git a/packages/flutter_driver/test/src/timeline_summary_test.dart b/packages/flutter_driver/test/src/timeline_summary_test.dart index 9fea04efb6..d96887c67c 100644 --- a/packages/flutter_driver/test/src/timeline_summary_test.dart +++ b/packages/flutter_driver/test/src/timeline_summary_test.dart @@ -20,7 +20,7 @@ void main() { } Map build(int timeStamp, int duration) => { - 'name': 'Frame', 'ph': 'X', 'ts': timeStamp, 'tdur': duration + 'name': 'Frame', 'ph': 'X', 'ts': timeStamp, 'dur': duration }; Map begin(int timeStamp) => {