run method
The implementation of the benchmark that will produce a Profile.
Implementation
@override
Future<Profile> run() async {
_runCompleter = Completer<void>();
final Profile localProfile =
profile = Profile(name: name, useCustomWarmUp: useCustomWarmUp);
final _RecordingWidgetsBinding binding =
_RecordingWidgetsBinding.ensureInitialized();
final Widget widget = createWidget();
registerEngineBenchmarkValueListener(BenchmarkMetric.prerollFrame.label,
(num value) {
localProfile.addDataPoint(
BenchmarkMetric.prerollFrame.label,
Duration(microseconds: value.toInt()),
reported: false,
);
});
registerEngineBenchmarkValueListener(BenchmarkMetric.applyFrame.label,
(num value) {
localProfile.addDataPoint(
BenchmarkMetric.applyFrame.label,
Duration(microseconds: value.toInt()),
reported: false,
);
});
late void Function(List<FrameTiming> frameTimings) frameTimingsCallback;
binding.addTimingsCallback(
frameTimingsCallback = (List<FrameTiming> frameTimings) {
for (final FrameTiming frameTiming in frameTimings) {
localProfile.addDataPoint(
BenchmarkMetric.flutterFrameTotalTime.label,
frameTiming.totalSpan,
reported: false,
);
localProfile.addDataPoint(
BenchmarkMetric.flutterFrameBuildTime.label,
frameTiming.buildDuration,
reported: false,
);
localProfile.addDataPoint(
BenchmarkMetric.flutterFrameRasterTime.label,
frameTiming.rasterDuration,
reported: false,
);
}
});
binding._beginRecording(this, widget);
try {
await _runCompleter.future;
return localProfile;
} finally {
stopListeningToEngineBenchmarkValues(BenchmarkMetric.prerollFrame.label);
stopListeningToEngineBenchmarkValues(BenchmarkMetric.applyFrame.label);
binding.removeTimingsCallback(frameTimingsCallback);
}
}