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
Stopwatch _drawFrameStopwatch;
@override
void _frameWillDraw() {
@mustCallSuper
void frameWillDraw() {
_drawFrameStopwatch = Stopwatch()..start();
}
@override
void _frameDidDraw() {
@mustCallSuper
void frameDidDraw() {
profile.addDataPoint('drawFrameDuration', _drawFrameStopwatch.elapsed);
if (profile.shouldContinue()) {
......@@ -321,6 +323,18 @@ abstract class WidgetBuildRecorder extends Recorder
/// consider using [WidgetRecorder].
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
Profile profile;
......@@ -331,13 +345,13 @@ abstract class WidgetBuildRecorder extends Recorder
/// Whether in this frame we should call [createWidget] and render it.
///
/// If false, then this frame will clear the screen.
bool _showWidget = true;
bool showWidget = true;
/// The state that hosts the widget under test.
_WidgetBuildRecorderHostState _hostState;
Widget _getWidgetForFrame() {
if (_showWidget) {
if (showWidget) {
return createWidget();
} else {
return null;
......@@ -345,19 +359,21 @@ abstract class WidgetBuildRecorder extends Recorder
}
@override
void _frameWillDraw() {
@mustCallSuper
void frameWillDraw() {
_drawFrameStopwatch = Stopwatch()..start();
}
@override
void _frameDidDraw() {
@mustCallSuper
void frameDidDraw() {
// Only record frames that show the widget.
if (_showWidget) {
if (showWidget) {
profile.addDataPoint('drawFrameDuration', _drawFrameStopwatch.elapsed);
}
if (profile.shouldContinue()) {
_showWidget = !_showWidget;
showWidget = !showWidget;
_hostState._setStateTrampoline();
} else {
_profileCompleter.complete(profile);
......@@ -372,11 +388,13 @@ abstract class WidgetBuildRecorder extends Recorder
@override
Future<Profile> run() {
profile = Profile(name: name);
setUpAll();
final _RecordingWidgetsBinding binding =
_RecordingWidgetsBinding.ensureInitialized();
binding._beginRecording(this, _WidgetBuildRecorderHost(this));
_profileCompleter.future.whenComplete(() {
tearDownAll();
profile = null;
});
return _profileCompleter.future;
......@@ -561,7 +579,7 @@ class Profile {
buffer.writeln('name: $name');
for (final String key in scoreData.keys) {
final Timeseries timeseries = scoreData[key];
buffer.writeln('$key:');
buffer.writeln('$key: (samples=${timeseries.count})');
buffer.writeln(' | average: ${timeseries.average} μs');
buffer.writeln(' | noise: ${_ratioToPercent(timeseries.noise)}');
}
......@@ -613,10 +631,10 @@ abstract class RecordingWidgetsBindingListener {
Profile profile;
/// Called just before calling [SchedulerBinding.handleDrawFrame].
void _frameWillDraw();
void frameWillDraw();
/// Called immediately after calling [SchedulerBinding.handleDrawFrame].
void _frameDidDraw();
void frameDidDraw();
/// Reports an error.
///
......@@ -697,8 +715,8 @@ class _RecordingWidgetsBinding extends BindingBase
if (_hasErrored) {
return;
}
_listener._frameWillDraw();
_listener.frameWillDraw();
super.handleDrawFrame();
_listener._frameDidDraw();
_listener.frameDidDraw();
}
}
......@@ -37,6 +37,8 @@ final Map<String, RecorderFactory> benchmarks = <String, RecorderFactory>{
BenchTextLayout.canvasBenchmarkName: () => BenchTextLayout(useCanvas: true),
BenchTextCachedLayout.domBenchmarkName: () => BenchTextCachedLayout(useCanvas: false),
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 {
return await inDirectory(macrobenchmarksDirectory, () async {
await evalFlutter('build', options: <String>[
'web',
'--dart-define=FLUTTER_WEB_ENABLE_PROFILING=true',
if (useCanvasKit)
'--dart-define=FLUTTER_WEB_USE_SKIA=true',
'--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