getSystemStats static method

Map<String, dynamic> getSystemStats()

Get detailed statistics about the entire Zen system Useful for monitoring and performance analysis

Implementation

static Map<String, dynamic> getSystemStats() {
  final allScopes = ZenScopeManager.getAllScopes();
  var totalDependencies = 0;
  var totalControllers = 0;
  var totalServices = 0;

  for (final scope in allScopes) {
    if (scope.isDisposed) continue; // Skip disposed scopes

    final breakdown = ZenScopeInspector.getDependencyBreakdown(scope);
    final summary = breakdown['summary'] as Map<String, dynamic>? ?? {};

    totalDependencies += (summary['grandTotal'] as int?) ?? 0;
    totalControllers += (summary['totalControllers'] as int?) ?? 0;
    totalServices += (summary['totalServices'] as int?) ?? 0;
  }

  final activeScopes = allScopes.where((s) => !s.isDisposed).length;
  final disposedScopes = allScopes.where((s) => s.isDisposed).length;

  return {
    'scopes': {
      'total': allScopes.length,
      'active': activeScopes,
      'disposed': disposedScopes,
    },
    'dependencies': {
      'total': totalDependencies,
      'controllers': totalControllers,
      'services': totalServices,
      'others': totalDependencies - totalControllers - totalServices,
    },
    'performance': {
      'averageDependenciesPerScope': activeScopes > 0
          ? (totalDependencies / activeScopes).toStringAsFixed(2)
          : '0',
    }
  };
}