Skip to main content

qubit_thread_pool/
thread_pool_stats.rs

1/*******************************************************************************
2 *
3 *    Copyright (c) 2025 - 2026 Haixing Hu.
4 *
5 *    SPDX-License-Identifier: Apache-2.0
6 *
7 *    Licensed under the Apache License, Version 2.0.
8 *
9 ******************************************************************************/
10use crate::ExecutorServiceLifecycle;
11
12/// Point-in-time counters reported by [`crate::ThreadPool`].
13///
14/// The snapshot is intended for monitoring and tests. It is not a stable
15/// synchronization primitive; concurrent submissions and completions may make
16/// the next snapshot different immediately after this one is returned.
17///
18#[derive(Debug, Clone, Copy, PartialEq, Eq)]
19pub struct ThreadPoolStats {
20    /// Observed lifecycle state.
21    pub lifecycle: ExecutorServiceLifecycle,
22
23    /// Configured core pool size.
24    pub core_pool_size: usize,
25
26    /// Configured maximum pool size.
27    pub maximum_pool_size: usize,
28
29    /// Number of live worker loops.
30    pub live_workers: usize,
31
32    /// Number of workers currently waiting for work.
33    pub idle_workers: usize,
34
35    /// Number of queued tasks waiting for a worker.
36    pub queued_tasks: usize,
37
38    /// Number of tasks currently held by workers.
39    pub running_tasks: usize,
40
41    /// Number of tasks accepted since pool creation.
42    pub submitted_tasks: usize,
43
44    /// Number of accepted jobs completed or otherwise made inactive without
45    /// queued cancellation.
46    pub completed_tasks: usize,
47
48    /// Number of queued jobs cancelled by immediate shutdown.
49    pub cancelled_tasks: usize,
50
51    /// Whether the pool has fully terminated.
52    pub terminated: bool,
53}
54
55impl Default for ThreadPoolStats {
56    fn default() -> Self {
57        Self {
58            lifecycle: ExecutorServiceLifecycle::Running,
59            core_pool_size: 0,
60            maximum_pool_size: 0,
61            live_workers: 0,
62            idle_workers: 0,
63            queued_tasks: 0,
64            running_tasks: 0,
65            submitted_tasks: 0,
66            completed_tasks: 0,
67            cancelled_tasks: 0,
68            terminated: false,
69        }
70    }
71}