debugInstrumentAction<T> function
Runs the specified action
, timing how long the action takes in debug
builds when debugInstrumentationEnabled is true.
The instrumentation will be printed to the logs using debugPrint. In
non-debug builds, or when debugInstrumentationEnabled is false, this will
run action
without any instrumentation.
Returns the result of running action
.
See also:
- Timeline, which is used to record synchronous tracing events for visualization in Chrome's tracing format. This method does not implicitly add any timeline events.
Implementation
Future<T> debugInstrumentAction<T>(String description, Future<T> Function() action) async {
bool instrument = false;
assert(() {
instrument = debugInstrumentationEnabled;
return true;
}());
if (instrument) {
final Stopwatch stopwatch = Stopwatch()..start(); // flutter_ignore: stopwatch (see analyze.dart)
// Ignore context: The framework does not use this function internally so it will not cause flakes.
try {
return await action();
} finally {
stopwatch.stop();
debugPrint('Action "$description" took ${stopwatch.elapsed}');
}
} else {
return action();
}
}