profile method

  1. @override
Future<CockpitPerformanceReport> profile(
  1. Future<void> action(), {
  2. String name = 'performance',
})
override

Implementation

@override
Future<CockpitPerformanceReport> profile(
  Future<void> Function() action, {
  String name = 'performance',
}) async {
  final performance = _performance;
  if (performance == null) {
    throw const CockpitTestCapabilityException('performance');
  }
  final request = CockpitPerformanceCaptureRequest(name: name);
  await performance.startPerformance(request);
  Object? actionError;
  StackTrace? actionStackTrace;
  try {
    await action();
  } on Object catch (error, stackTrace) {
    actionError = error;
    actionStackTrace = stackTrace;
  }

  late final CockpitPerformanceReport report;
  try {
    report = await performance.stopPerformance();
  } on Object catch (cleanupError, cleanupStackTrace) {
    if (actionError != null) {
      throw CockpitTestCleanupException(
        primaryError: actionError,
        primaryStackTrace: actionStackTrace!,
        cleanupError: cleanupError,
        cleanupStackTrace: cleanupStackTrace,
      );
    }
    rethrow;
  }
  if (actionError != null) {
    Error.throwWithStackTrace(actionError, actionStackTrace!);
  }
  return report;
}