Thread System 0.3.1
High-performance C++20 thread pool with work stealing and DAG scheduling
Loading...
Searching...
No Matches
thread_pool_metrics.h
Go to the documentation of this file.
1// BSD 3-Clause License
2// Copyright (c) 2024, 🍀☀🌕🌥 🌊
3// See the LICENSE file in the project root for full license information.
4
12#pragma once
13
15
17
52public:
58 struct Snapshot {
59 std::uint64_t tasks_submitted;
60 std::uint64_t tasks_enqueued;
61 std::uint64_t tasks_executed;
62 std::uint64_t tasks_failed;
63 std::uint64_t total_busy_time_ns;
64 std::uint64_t total_idle_time_ns;
65 };
66
70 ThreadPoolMetrics() = default;
71
75 ~ThreadPoolMetrics() override = default;
76
81 void record_enqueue(std::size_t count = 1) {
82 tasks_enqueued_.fetch_add(count, std::memory_order_relaxed);
83 }
84
89 [[nodiscard]] std::uint64_t tasks_enqueued() const {
90 return tasks_enqueued_.load(std::memory_order_relaxed);
91 }
92
96 void reset() override {
98 tasks_enqueued_.store(0, std::memory_order_relaxed);
99 }
100
105 [[nodiscard]] Snapshot snapshot() const {
106 return Snapshot{
108 tasks_enqueued_.load(std::memory_order_relaxed),
110 tasks_failed(),
113 };
114 }
115
116private:
123 std::atomic<std::uint64_t> tasks_enqueued_{0};
124};
125
126} // namespace kcenon::thread::metrics
Abstract base class for thread pool metrics.
std::uint64_t total_busy_time_ns() const
Get the total busy time in nanoseconds.
std::uint64_t tasks_executed() const
Get the total number of tasks successfully executed.
std::uint64_t tasks_submitted() const
Get the total number of tasks submitted.
std::uint64_t tasks_failed() const
Get the total number of failed tasks.
std::uint64_t total_idle_time_ns() const
Get the total idle time in nanoseconds.
virtual void reset()
Reset all metrics to their initial state.
Lightweight metrics container shared between thread_pool and workers.
ThreadPoolMetrics()=default
Default constructor.
std::atomic< std::uint64_t > tasks_enqueued_
Counter for enqueued tasks.
void record_enqueue(std::size_t count=1)
Record enqueue operation(s).
Snapshot snapshot() const
Get a snapshot of all metrics.
void reset() override
Reset all metrics to their initial state.
std::uint64_t tasks_enqueued() const
Get the total number of tasks enqueued.
~ThreadPoolMetrics() override=default
Virtual destructor.
Thread pool metrics collection, histograms, and observability.
Snapshot structure containing all metric values.