improve web benchmark error reporting (#51490)

This commit is contained in:
Yegor
2020-02-28 10:14:22 -08:00
committed by GitHub
parent 213027dd82
commit cd0fbd3205
4 changed files with 85 additions and 18 deletions

View File

@@ -18,10 +18,15 @@ class BenchBuildMaterialCheckbox extends WidgetBuildRecorder {
@override
Widget createWidget() {
return Column(
children: List<Widget>.generate(10, (int i) {
return _buildRow();
}),
return Directionality(
textDirection: TextDirection.ltr,
child: Material(
child: Column(
children: List<Widget>.generate(10, (int i) {
return _buildRow();
}),
),
),
);
}

View File

@@ -218,6 +218,11 @@ abstract class WidgetRecorder extends Recorder implements _RecordingWidgetsBindi
}
}
@override
void _onError(dynamic error, StackTrace stackTrace) {
_profileCompleter.completeError(error, stackTrace);
}
@override
Future<Profile> run() {
final _RecordingWidgetsBinding binding =
@@ -289,6 +294,11 @@ abstract class WidgetBuildRecorder extends Recorder implements _RecordingWidgets
}
}
@override
void _onError(dynamic error, StackTrace stackTrace) {
_profileCompleter.completeError(error, stackTrace);
}
@override
Future<Profile> run() {
final _RecordingWidgetsBinding binding =
@@ -512,9 +522,19 @@ double _computeStandardDeviationForPopulation(Iterable<double> population) {
/// Implemented by recorders that use [_RecordingWidgetsBinding] to receive
/// frame life-cycle calls.
abstract class _RecordingWidgetsBindingListener {
/// Whether the binding should continue pumping frames.
bool _shouldContinue();
/// Called just before calling [SchedulerBinding.handleDrawFrame].
void _frameWillDraw();
/// Called immediately after calling [SchedulerBinding.handleDrawFrame].
void _frameDidDraw();
/// Reports an error.
///
/// The implementation is expected to halt benchmark execution as soon as possible.
void _onError(dynamic error, StackTrace stackTrace);
}
/// A variant of [WidgetsBinding] that collaborates with a [Recorder] to decide
@@ -543,8 +563,20 @@ class _RecordingWidgetsBinding extends BindingBase
}
_RecordingWidgetsBindingListener _listener;
bool _hasErrored = false;
void _beginRecording(_RecordingWidgetsBindingListener recorder, Widget widget) {
final FlutterExceptionHandler originalOnError = FlutterError.onError;
// Fail hard and fast on errors. Benchmarks should not have any errors.
FlutterError.onError = (FlutterErrorDetails details) {
if (_hasErrored) {
return;
}
_listener._onError(details.exception, details.stack);
_hasErrored = true;
originalOnError(details);
};
_listener = recorder;
runApp(widget);
}
@@ -555,19 +587,28 @@ class _RecordingWidgetsBinding extends BindingBase
@override
void handleBeginFrame(Duration rawTimeStamp) {
// Don't keep on truckin' if there's an error.
if (_hasErrored) {
return;
}
_benchmarkStopped = !_listener._shouldContinue();
super.handleBeginFrame(rawTimeStamp);
}
@override
void scheduleFrame() {
if (!_benchmarkStopped) {
// Don't keep on truckin' if there's an error.
if (!_benchmarkStopped && !_hasErrored) {
super.scheduleFrame();
}
}
@override
void handleDrawFrame() {
// Don't keep on truckin' if there's an error.
if (_hasErrored) {
return;
}
_listener._frameWillDraw();
super.handleDrawFrame();
_listener._frameDidDraw();