run method
The implementation of the benchmark that will produce a Profile.
Implementation
@override
Future<Profile> run() {
final Completer<Profile> profileCompleter = Completer<Profile>();
_profile = Profile(name: name);
PlatformDispatcher.instance.onBeginFrame = (_) {
try {
startMeasureFrame(profile);
onBeginFrame();
} catch (error, stackTrace) {
profileCompleter.completeError(error, stackTrace);
rethrow;
}
};
PlatformDispatcher.instance.onDrawFrame = () {
final FlutterView? view = PlatformDispatcher.instance.implicitView;
try {
_profile.record('drawFrameDuration', () {
final SceneBuilder sceneBuilder = SceneBuilder();
onDrawFrame(sceneBuilder);
_profile.record('sceneBuildDuration', () {
final Scene scene = sceneBuilder.build();
_profile.record('windowRenderDuration', () {
assert(view != null,
'Cannot profile windowRenderDuration on a null View.');
view!.render(scene);
}, reported: false);
}, reported: false);
}, reported: true);
endMeasureFrame();
if (shouldContinue()) {
PlatformDispatcher.instance.scheduleFrame();
} else {
profileCompleter.complete(_profile);
}
} catch (error, stackTrace) {
profileCompleter.completeError(error, stackTrace);
rethrow;
}
};
PlatformDispatcher.instance.scheduleFrame();
return profileCompleter.future;
}