Unverified Commit 45a8b3db authored by Mouad Debbar's avatar Mouad Debbar Committed by GitHub

complete text layout benchmark (#53295)

parent ac3b77bd
...@@ -268,12 +268,14 @@ abstract class WidgetRecorder extends Recorder ...@@ -268,12 +268,14 @@ abstract class WidgetRecorder extends Recorder
Stopwatch _drawFrameStopwatch; Stopwatch _drawFrameStopwatch;
@override @override
void _frameWillDraw() { @mustCallSuper
void frameWillDraw() {
_drawFrameStopwatch = Stopwatch()..start(); _drawFrameStopwatch = Stopwatch()..start();
} }
@override @override
void _frameDidDraw() { @mustCallSuper
void frameDidDraw() {
profile.addDataPoint('drawFrameDuration', _drawFrameStopwatch.elapsed); profile.addDataPoint('drawFrameDuration', _drawFrameStopwatch.elapsed);
if (profile.shouldContinue()) { if (profile.shouldContinue()) {
...@@ -321,6 +323,18 @@ abstract class WidgetBuildRecorder extends Recorder ...@@ -321,6 +323,18 @@ abstract class WidgetBuildRecorder extends Recorder
/// consider using [WidgetRecorder]. /// consider using [WidgetRecorder].
Widget createWidget(); Widget createWidget();
/// Called once before all runs of this benchmark recorder.
///
/// This is useful for doing one-time setup work that's needed for the
/// benchmark.
void setUpAll() {}
/// Called once after all runs of this benchmark recorder.
///
/// This is useful for doing one-time clean up work after the benchmark is
/// complete.
void tearDownAll() {}
@override @override
Profile profile; Profile profile;
...@@ -331,13 +345,13 @@ abstract class WidgetBuildRecorder extends Recorder ...@@ -331,13 +345,13 @@ abstract class WidgetBuildRecorder extends Recorder
/// Whether in this frame we should call [createWidget] and render it. /// Whether in this frame we should call [createWidget] and render it.
/// ///
/// If false, then this frame will clear the screen. /// If false, then this frame will clear the screen.
bool _showWidget = true; bool showWidget = true;
/// The state that hosts the widget under test. /// The state that hosts the widget under test.
_WidgetBuildRecorderHostState _hostState; _WidgetBuildRecorderHostState _hostState;
Widget _getWidgetForFrame() { Widget _getWidgetForFrame() {
if (_showWidget) { if (showWidget) {
return createWidget(); return createWidget();
} else { } else {
return null; return null;
...@@ -345,19 +359,21 @@ abstract class WidgetBuildRecorder extends Recorder ...@@ -345,19 +359,21 @@ abstract class WidgetBuildRecorder extends Recorder
} }
@override @override
void _frameWillDraw() { @mustCallSuper
void frameWillDraw() {
_drawFrameStopwatch = Stopwatch()..start(); _drawFrameStopwatch = Stopwatch()..start();
} }
@override @override
void _frameDidDraw() { @mustCallSuper
void frameDidDraw() {
// Only record frames that show the widget. // Only record frames that show the widget.
if (_showWidget) { if (showWidget) {
profile.addDataPoint('drawFrameDuration', _drawFrameStopwatch.elapsed); profile.addDataPoint('drawFrameDuration', _drawFrameStopwatch.elapsed);
} }
if (profile.shouldContinue()) { if (profile.shouldContinue()) {
_showWidget = !_showWidget; showWidget = !showWidget;
_hostState._setStateTrampoline(); _hostState._setStateTrampoline();
} else { } else {
_profileCompleter.complete(profile); _profileCompleter.complete(profile);
...@@ -372,11 +388,13 @@ abstract class WidgetBuildRecorder extends Recorder ...@@ -372,11 +388,13 @@ abstract class WidgetBuildRecorder extends Recorder
@override @override
Future<Profile> run() { Future<Profile> run() {
profile = Profile(name: name); profile = Profile(name: name);
setUpAll();
final _RecordingWidgetsBinding binding = final _RecordingWidgetsBinding binding =
_RecordingWidgetsBinding.ensureInitialized(); _RecordingWidgetsBinding.ensureInitialized();
binding._beginRecording(this, _WidgetBuildRecorderHost(this)); binding._beginRecording(this, _WidgetBuildRecorderHost(this));
_profileCompleter.future.whenComplete(() { _profileCompleter.future.whenComplete(() {
tearDownAll();
profile = null; profile = null;
}); });
return _profileCompleter.future; return _profileCompleter.future;
...@@ -561,7 +579,7 @@ class Profile { ...@@ -561,7 +579,7 @@ class Profile {
buffer.writeln('name: $name'); buffer.writeln('name: $name');
for (final String key in scoreData.keys) { for (final String key in scoreData.keys) {
final Timeseries timeseries = scoreData[key]; final Timeseries timeseries = scoreData[key];
buffer.writeln('$key:'); buffer.writeln('$key: (samples=${timeseries.count})');
buffer.writeln(' | average: ${timeseries.average} μs'); buffer.writeln(' | average: ${timeseries.average} μs');
buffer.writeln(' | noise: ${_ratioToPercent(timeseries.noise)}'); buffer.writeln(' | noise: ${_ratioToPercent(timeseries.noise)}');
} }
...@@ -613,10 +631,10 @@ abstract class RecordingWidgetsBindingListener { ...@@ -613,10 +631,10 @@ abstract class RecordingWidgetsBindingListener {
Profile profile; Profile profile;
/// Called just before calling [SchedulerBinding.handleDrawFrame]. /// Called just before calling [SchedulerBinding.handleDrawFrame].
void _frameWillDraw(); void frameWillDraw();
/// Called immediately after calling [SchedulerBinding.handleDrawFrame]. /// Called immediately after calling [SchedulerBinding.handleDrawFrame].
void _frameDidDraw(); void frameDidDraw();
/// Reports an error. /// Reports an error.
/// ///
...@@ -697,8 +715,8 @@ class _RecordingWidgetsBinding extends BindingBase ...@@ -697,8 +715,8 @@ class _RecordingWidgetsBinding extends BindingBase
if (_hasErrored) { if (_hasErrored) {
return; return;
} }
_listener._frameWillDraw(); _listener.frameWillDraw();
super.handleDrawFrame(); super.handleDrawFrame();
_listener._frameDidDraw(); _listener.frameDidDraw();
} }
} }
...@@ -37,6 +37,8 @@ final Map<String, RecorderFactory> benchmarks = <String, RecorderFactory>{ ...@@ -37,6 +37,8 @@ final Map<String, RecorderFactory> benchmarks = <String, RecorderFactory>{
BenchTextLayout.canvasBenchmarkName: () => BenchTextLayout(useCanvas: true), BenchTextLayout.canvasBenchmarkName: () => BenchTextLayout(useCanvas: true),
BenchTextCachedLayout.domBenchmarkName: () => BenchTextCachedLayout(useCanvas: false), BenchTextCachedLayout.domBenchmarkName: () => BenchTextCachedLayout(useCanvas: false),
BenchTextCachedLayout.canvasBenchmarkName: () => BenchTextCachedLayout(useCanvas: true), BenchTextCachedLayout.canvasBenchmarkName: () => BenchTextCachedLayout(useCanvas: true),
BenchBuildColorsGrid.domBenchmarkName: () => BenchBuildColorsGrid(useCanvas: false),
BenchBuildColorsGrid.canvasBenchmarkName: () => BenchBuildColorsGrid(useCanvas: true),
} }
}; };
......
...@@ -24,6 +24,7 @@ Future<TaskResult> runWebBenchmark({ @required bool useCanvasKit }) async { ...@@ -24,6 +24,7 @@ Future<TaskResult> runWebBenchmark({ @required bool useCanvasKit }) async {
return await inDirectory(macrobenchmarksDirectory, () async { return await inDirectory(macrobenchmarksDirectory, () async {
await evalFlutter('build', options: <String>[ await evalFlutter('build', options: <String>[
'web', 'web',
'--dart-define=FLUTTER_WEB_ENABLE_PROFILING=true',
if (useCanvasKit) if (useCanvasKit)
'--dart-define=FLUTTER_WEB_USE_SKIA=true', '--dart-define=FLUTTER_WEB_USE_SKIA=true',
'--profile', '--profile',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment