diff --git a/dev/benchmarks/macrobenchmarks/lib/src/web/bench_mouse_region_grid_hover.dart b/dev/benchmarks/macrobenchmarks/lib/src/web/bench_mouse_region_grid_hover.dart index d43e1b321b..291cc796f7 100644 --- a/dev/benchmarks/macrobenchmarks/lib/src/web/bench_mouse_region_grid_hover.dart +++ b/dev/benchmarks/macrobenchmarks/lib/src/web/bench_mouse_region_grid_hover.dart @@ -36,11 +36,17 @@ class _NestedMouseRegion extends StatelessWidget { /// /// Measures our ability to hit test mouse regions. class BenchMouseRegionGridHover extends WidgetRecorder { - BenchMouseRegionGridHover() : super(name: benchmarkName); + BenchMouseRegionGridHover() : super(name: benchmarkName) { + tester = _Tester(onDataPoint: handleDataPoint); + } static const String benchmarkName = 'bench_mouse_region_grid_hover'; - final _Tester tester = _Tester(); + _Tester tester; + + void handleDataPoint(Duration duration) { + profile.addDataPoint('hitTestDuration', duration, reported: true); + } // Use a non-trivial border to force Web to switch painter Border _getBorder(int columnIndex, int rowIndex) { @@ -62,6 +68,7 @@ class BenchMouseRegionGridHover extends WidgetRecorder { started = true; SchedulerBinding.instance.addPostFrameCallback((Duration timeStamp) async { tester.start(); + registerDidStop(tester.stop); }); } super.frameDidDraw(); @@ -127,6 +134,10 @@ class _UntilNextFrame { } class _Tester { + _Tester({this.onDataPoint}); + + final ValueSetter onDataPoint; + static const Duration hoverDuration = Duration(milliseconds: 20); bool _stopped = false; @@ -150,7 +161,11 @@ class _Tester { Future _hoverTo(Offset location, Duration duration) async { currentTime += duration; + final Stopwatch stopwatch = Stopwatch()..start(); await gesture.moveTo(location, timeStamp: currentTime); + stopwatch.stop(); + if (onDataPoint != null) + onDataPoint(stopwatch.elapsed); await _UntilNextFrame.wait(); } diff --git a/dev/benchmarks/macrobenchmarks/lib/src/web/bench_mouse_region_grid_scroll.dart b/dev/benchmarks/macrobenchmarks/lib/src/web/bench_mouse_region_grid_scroll.dart index c3732b80ef..b81f15da6a 100644 --- a/dev/benchmarks/macrobenchmarks/lib/src/web/bench_mouse_region_grid_scroll.dart +++ b/dev/benchmarks/macrobenchmarks/lib/src/web/bench_mouse_region_grid_scroll.dart @@ -43,12 +43,7 @@ class BenchMouseRegionGridScroll extends WidgetRecorder { started = true; SchedulerBinding.instance.addPostFrameCallback((Duration timeStamp) async { tester.start(); - final VoidCallback localDidStop = didStop; - didStop = () { - if (localDidStop != null) - localDidStop(); - tester.stop(); - }; + registerDidStop(tester.stop); }); } super.frameDidDraw(); diff --git a/dev/benchmarks/macrobenchmarks/lib/src/web/recorder.dart b/dev/benchmarks/macrobenchmarks/lib/src/web/recorder.dart index 366dfe5ea8..2c5f12084c 100644 --- a/dev/benchmarks/macrobenchmarks/lib/src/web/recorder.dart +++ b/dev/benchmarks/macrobenchmarks/lib/src/web/recorder.dart @@ -345,8 +345,11 @@ abstract class WidgetRecorder extends Recorder implements FrameRecorder { /// pumping frames automatically. Widget createWidget(); + final List _didStopCallbacks = []; @override - VoidCallback didStop; + void registerDidStop(VoidCallback fn) { + _didStopCallbacks.add(fn); + } @override Profile profile; @@ -373,7 +376,8 @@ abstract class WidgetRecorder extends Recorder implements FrameRecorder { if (shouldContinue()) { window.scheduleFrame(); } else { - didStop(); + for (final VoidCallback fn in _didStopCallbacks) + fn(); _runCompleter.complete(); } } @@ -437,8 +441,11 @@ abstract class WidgetBuildRecorder extends Recorder implements FrameRecorder { /// consider using [WidgetRecorder]. Widget createWidget(); + final List _didStopCallbacks = []; @override - VoidCallback didStop; + void registerDidStop(VoidCallback fn) { + _didStopCallbacks.add(fn); + } @override Profile profile; @@ -484,7 +491,8 @@ abstract class WidgetBuildRecorder extends Recorder implements FrameRecorder { showWidget = !showWidget; _hostState._setStateTrampoline(); } else { - didStop(); + for (final VoidCallback fn in _didStopCallbacks) + fn(); _runCompleter.complete(); } } @@ -942,9 +950,8 @@ String _ratioToPercent(double value) { /// Implemented by recorders that use [_RecordingWidgetsBinding] to receive /// frame life-cycle calls. abstract class FrameRecorder { - /// Called by the recorder when it stops recording and doesn't need to collect - /// any more data. - set didStop(VoidCallback cb); + /// Add a callback that will be called by the recorder when it stops recording. + void registerDidStop(VoidCallback cb); /// Called just before calling [SchedulerBinding.handleDrawFrame]. void frameWillDraw(); @@ -998,9 +1005,9 @@ class _RecordingWidgetsBinding extends BindingBase } final FlutterExceptionHandler originalOnError = FlutterError.onError; - recorder.didStop = () { + recorder.registerDidStop(() { _benchmarkStopped = true; - }; + }); // Fail hard and fast on errors. Benchmarks should not have any errors. FlutterError.onError = (FlutterErrorDetails details) {