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 worker-held jobs finished since pool creation.
45 pub completed_tasks: usize,
46
47 /// Number of queued jobs cancelled by immediate shutdown.
48 pub cancelled_tasks: usize,
49
50 /// Whether the pool has fully terminated.
51 pub terminated: bool,
52}
53
54impl Default for ThreadPoolStats {
55 fn default() -> Self {
56 Self {
57 lifecycle: ExecutorServiceLifecycle::Running,
58 core_pool_size: 0,
59 maximum_pool_size: 0,
60 live_workers: 0,
61 idle_workers: 0,
62 queued_tasks: 0,
63 running_tasks: 0,
64 submitted_tasks: 0,
65 completed_tasks: 0,
66 cancelled_tasks: 0,
67 terminated: false,
68 }
69 }
70}