run method

  1. @override
Future<Profile> run()
override

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 = () {
    try {
      _profile.record('drawFrameDuration', () {
        final SceneBuilder sceneBuilder = SceneBuilder();
        onDrawFrame(sceneBuilder);
        _profile.record('sceneBuildDuration', () {
          final Scene scene = sceneBuilder.build();
          _profile.record('windowRenderDuration', () {
            // TODO(goderbauer): Migrate to PlatformDispatcher.implicitView once v3.9.0 is the oldest supported Flutter version.
            window.render(scene); // ignore: deprecated_member_use
          }, 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;
}