getWorkerPoolStats method

AsyncWorkerPoolStats getWorkerPoolStats()

Returns a Dart-side snapshot of worker pool routing and health counters.

Implementation

AsyncWorkerPoolStats getWorkerPoolStats() {
  final workers = _workers.map(_statsForWorker).toList(growable: false);
  return AsyncWorkerPoolStats(
    workerCount: workerCount,
    activeRequests: workers.fold<int>(
      0,
      (total, worker) => total + worker.activeRequests,
    ),
    pendingRequests: workers.fold<int>(
      0,
      (total, worker) => total + worker.pendingRequests,
    ),
    totalRouted: workers.fold<int>(
      0,
      (total, worker) => total + worker.totalRouted,
    ),
    completedRequests: workers.fold<int>(
      0,
      (total, worker) => total + worker.completedRequests,
    ),
    failedRequests: workers.fold<int>(
      0,
      (total, worker) => total + worker.failedRequests,
    ),
    timeouts: workers.fold<int>(
      0,
      (total, worker) => total + worker.timeouts,
    ),
    fallbacksToBlocking: workers.fold<int>(
      0,
      (total, worker) => total + worker.fallbacksToBlocking,
    ),
    cancelAttempts: workers.fold<int>(
      0,
      (total, worker) => total + worker.cancelAttempts,
    ),
    cancelSucceeded: workers.fold<int>(
      0,
      (total, worker) => total + worker.cancelSucceeded,
    ),
    cancelUnsupported: workers.fold<int>(
      0,
      (total, worker) => total + worker.cancelUnsupported,
    ),
    latencyAvgMicros: _weightedAverageLatency(),
    latencyP95Micros: _aggregateP95(_WorkerMetricSample.latency),
    latencyMaxMicros: workers.fold<int>(
      0,
      (max, worker) =>
          worker.latencyMaxMicros > max ? worker.latencyMaxMicros : max,
    ),
    queueWaitAvgMicros: _weightedAverage(
      (worker) => worker.queueWaitTotalMicros,
    ),
    queueWaitP95Micros: _aggregateP95(_WorkerMetricSample.queueWait),
    queueWaitMaxMicros: workers.fold<int>(
      0,
      (max, worker) =>
          worker.queueWaitMaxMicros > max ? worker.queueWaitMaxMicros : max,
    ),
    executionAvgMicros: _weightedAverage(
      (worker) => worker.executionTotalMicros,
    ),
    executionP95Micros: _aggregateP95(_WorkerMetricSample.execution),
    executionMaxMicros: workers.fold<int>(
      0,
      (max, worker) =>
          worker.executionMaxMicros > max ? worker.executionMaxMicros : max,
    ),
    workers: workers,
  );
}