debugInstrumentAction<T> function

Future<T> debugInstrumentAction <T>(
  1. String description,
  2. Future<T> action(
      )
    )

    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> action()) {
      bool instrument = false;
      assert(() {
        instrument = debugInstrumentationEnabled;
        return true;
      }());
      if (instrument) {
        final Stopwatch stopwatch = Stopwatch()..start();
        return action().whenComplete(() {
          stopwatch.stop();
          debugPrint('Action "$description" took ${stopwatch.elapsed}');
        });
      } else {
        return action();
      }
    }