threadman 0.1.0
Header-only C++23 managed threads, dynamic pools, futures, and executors
Loading...
Searching...
No Matches
stats.hpp
Go to the documentation of this file.
1#pragma once
2
9
10#include <chrono>
11#include <cstdint>
12#include <optional>
13#include <string>
14#include <vector>
15
16namespace threadman {
17
21enum class ThreadState : std::uint8_t {
22 Starting,
23 Running,
24 Idle,
25 Retiring,
26 Completed,
27 Failed,
28};
29
31enum class TaskState : std::uint8_t {
32 Queued,
33 Running,
34 Completed,
35 Failed,
36 Cancelled,
37};
38
40enum class PoolState : std::uint8_t {
41 Running,
45};
46
49 std::uint64_t id = 0;
50 std::string name;
51 std::uint64_t native_id = 0;
52 std::optional<std::uint64_t> pool_id;
54 std::chrono::nanoseconds run_duration{0};
55 bool failed = false;
56 bool is_core = true;
57};
58
61 std::uint64_t pool_id = 0;
62 std::string name;
64 std::size_t workers = 0;
65 std::size_t core_workers = 0;
66 std::size_t max_workers = 0;
67 std::size_t active = 0;
68 std::size_t idle = 0;
69 std::size_t queued = 0;
70 std::uint64_t completed = 0;
71 std::uint64_t failed = 0;
72 std::chrono::nanoseconds avg_execution_duration{
73 0};
74 std::uint64_t scale_ups = 0;
75 std::uint64_t scale_downs = 0;
76};
77
80 std::uint64_t id = 0;
81 std::optional<std::string> name;
82 std::uint64_t pool_id = 0;
84 std::chrono::steady_clock::time_point created_at;
85 std::optional<std::chrono::steady_clock::time_point> started_at;
86 std::optional<std::chrono::steady_clock::time_point> finished_at;
87 bool failed = false;
88};
89
92 bool ready = false;
93 bool has_exception = false;
94 std::uint32_t continuation_count = 0;
95 bool shared = false;
96};
97
102 std::chrono::system_clock::time_point wall_clock;
103 std::size_t live_threads = 0;
104 std::size_t total_pools = 0;
105 std::size_t total_live_workers = 0;
106 std::size_t total_queued = 0;
107 std::uint64_t total_completed = 0;
108 std::uint64_t total_failed = 0;
109 std::vector<ThreadPoolStats> per_pool_stats;
110 std::vector<TaskSnapshot> stuck_tasks;
111};
112
116 std::chrono::nanoseconds running_for{0};
117 std::uint64_t pool_id = 0;
118};
119
120} // namespace threadman
Definition exceptions.hpp:22
TaskState
Lifecycle state of a TaskHandle.
Definition stats.hpp:31
@ Queued
Submitted, waiting for a worker.
@ Cancelled
Discarded before running (shutdown_now, etc.).
ThreadState
Lifecycle state of a ManagedThread / pool worker.
Definition stats.hpp:21
@ Completed
Body returned normally; thread joined or about to.
@ Retiring
Pool worker stop-requested; will exit on next loop check.
@ Running
User body is actively executing.
@ Starting
Constructed; user body not yet entered.
@ Failed
Body threw an exception; reason captured in ControlBlock.
@ Idle
Pool worker sleeping on the queue, no task.
PoolState
Lifecycle state of a ThreadPool.
Definition stats.hpp:40
@ ShuttingDown
shutdown() requested; draining queue, no new submits.
@ Running
Accepting submissions.
@ ShutdownNow
shutdown_now() requested; queue cancelled, workers stopping.
@ Terminated
All workers joined.
A snapshot of a future-state object. Useful for diagnostics.
Definition stats.hpp:91
bool shared
Definition stats.hpp:95
std::uint32_t continuation_count
Definition stats.hpp:94
bool has_exception
Definition stats.hpp:93
bool ready
Definition stats.hpp:92
Aggregate publish-payload produced periodically by the ThreadManager's housekeeper.
Definition stats.hpp:101
std::size_t total_live_workers
Definition stats.hpp:105
std::size_t live_threads
Definition stats.hpp:103
std::size_t total_pools
Definition stats.hpp:104
std::vector< TaskSnapshot > stuck_tasks
Definition stats.hpp:110
std::vector< ThreadPoolStats > per_pool_stats
Definition stats.hpp:109
std::chrono::system_clock::time_point wall_clock
Definition stats.hpp:102
std::size_t total_queued
Definition stats.hpp:106
std::uint64_t total_completed
Definition stats.hpp:107
std::uint64_t total_failed
Definition stats.hpp:108
A single stuck-task event published to StuckTaskListeners.
Definition stats.hpp:114
std::uint64_t pool_id
Definition stats.hpp:117
TaskSnapshot task
Definition stats.hpp:115
std::chrono::nanoseconds running_for
Definition stats.hpp:116
A snapshot of a single task's lifecycle.
Definition stats.hpp:79
std::chrono::steady_clock::time_point created_at
Definition stats.hpp:84
std::optional< std::chrono::steady_clock::time_point > finished_at
Definition stats.hpp:86
std::uint64_t pool_id
Definition stats.hpp:82
std::optional< std::string > name
Definition stats.hpp:81
TaskState state
Definition stats.hpp:83
std::optional< std::chrono::steady_clock::time_point > started_at
Definition stats.hpp:85
bool failed
Definition stats.hpp:87
A snapshot of a pool's headline counters.
Definition stats.hpp:60
std::size_t queued
Tasks waiting in the queue.
Definition stats.hpp:69
std::uint64_t completed
Definition stats.hpp:70
std::uint64_t failed
Definition stats.hpp:71
std::size_t workers
Currently live workers.
Definition stats.hpp:64
std::uint64_t scale_ups
Definition stats.hpp:74
std::uint64_t scale_downs
Definition stats.hpp:75
std::uint64_t pool_id
Definition stats.hpp:61
std::size_t idle
Workers currently in Idle.
Definition stats.hpp:68
std::size_t active
Workers currently in Running.
Definition stats.hpp:67
PoolState state
Definition stats.hpp:63
std::size_t max_workers
Definition stats.hpp:66
std::string name
Definition stats.hpp:62
std::size_t core_workers
min_workers.
Definition stats.hpp:65
std::chrono::nanoseconds avg_execution_duration
Rolling average across completed tasks.
Definition stats.hpp:72
A point-in-time snapshot of a ManagedThread's control block.
Definition stats.hpp:48
bool failed
True iff state == Failed.
Definition stats.hpp:55
std::uint64_t native_id
OS-level thread id, when known.
Definition stats.hpp:51
std::string name
User-chosen name.
Definition stats.hpp:50
std::optional< std::uint64_t > pool_id
Owning pool, when this is a pool worker.
Definition stats.hpp:52
std::chrono::nanoseconds run_duration
Time the body has been running (or ran).
Definition stats.hpp:54
bool is_core
Pool worker: not subject to idle retirement.
Definition stats.hpp:56
ThreadState state
Definition stats.hpp:53