|
Monitoring System 0.1.0
System resource monitoring with pluggable collectors and alerting
|
Thread-local buffer for lock-free metric collection. More...
#include <thread_local_buffer.h>

Classes | |
| struct | stats |
| Get statistics about buffer operations. More... | |
Public Member Functions | |
| thread_local_buffer (size_t capacity=DEFAULT_CAPACITY, std::shared_ptr< central_collector > collector=nullptr) | |
| Construct a thread-local buffer. | |
| ~thread_local_buffer () | |
| Destructor - flushes any remaining samples. | |
| thread_local_buffer (const thread_local_buffer &)=delete | |
| thread_local_buffer & | operator= (const thread_local_buffer &)=delete |
| thread_local_buffer (thread_local_buffer &&)=delete | |
| thread_local_buffer & | operator= (thread_local_buffer &&)=delete |
| bool | record (const metric_sample &sample) |
| Record a metric sample (lock-free) | |
| bool | record_auto_flush (const metric_sample &sample) |
| Record a metric sample with automatic flush on overflow. | |
| size_t | flush () |
| Flush buffered samples to central collector. | |
| size_t | size () const |
| Get current number of buffered samples. | |
| bool | is_full () const |
| Check if buffer is full. | |
| size_t | capacity () const |
| Get buffer capacity. | |
| void | set_collector (std::shared_ptr< central_collector > collector) |
| Set the central collector. | |
| const stats & | get_stats () const |
| Get buffer statistics. | |
Static Public Attributes | |
| static constexpr size_t | DEFAULT_CAPACITY = 256 |
Private Attributes | |
| std::vector< metric_sample > | buffer_ |
| size_t | capacity_ |
| size_t | write_index_ {0} |
| std::shared_ptr< central_collector > | collector_ |
| stats | stats_ |
Thread-local buffer for lock-free metric collection.
Each thread maintains its own buffer for recording metrics without locks. When the buffer fills up, it flushes to a central collector.
Uses lazy initialization: capacity is reserved at construction but elements are constructed on first use. This avoids wasting memory for short-lived threads that never record any metrics.
Definition at line 66 of file thread_local_buffer.h.
|
explicit |
Construct a thread-local buffer.
| capacity | Maximum number of samples before flush |
| collector | Central collector to receive flushed samples |
| kcenon::monitoring::thread_local_buffer::~thread_local_buffer | ( | ) |
Destructor - flushes any remaining samples.
|
delete |
|
delete |
|
inline |
Get buffer capacity.
Definition at line 137 of file thread_local_buffer.h.
References capacity_.
| size_t kcenon::monitoring::thread_local_buffer::flush | ( | ) |
Flush buffered samples to central collector.
Referenced by TEST_F(), TEST_F(), TEST_F(), TEST_F(), and TEST_F().

|
inline |
Get buffer statistics.
Definition at line 160 of file thread_local_buffer.h.
References stats_.
|
inline |
Check if buffer is full.
Definition at line 131 of file thread_local_buffer.h.
References capacity_, and write_index_.
Referenced by TEST_F().

|
delete |
|
delete |
| bool kcenon::monitoring::thread_local_buffer::record | ( | const metric_sample & | sample | ) |
Record a metric sample (lock-free)
| sample | Metric sample to record |
Referenced by TEST_F(), TEST_F(), TEST_F(), and TEST_F().

| bool kcenon::monitoring::thread_local_buffer::record_auto_flush | ( | const metric_sample & | sample | ) |
Record a metric sample with automatic flush on overflow.
| sample | Metric sample to record |
Referenced by TEST_F(), TEST_F(), and TEST_F().

|
inline |
Set the central collector.
| collector | Central collector to receive flushed samples |
Definition at line 143 of file thread_local_buffer.h.
References collector_.
|
inline |
Get current number of buffered samples.
Definition at line 125 of file thread_local_buffer.h.
References write_index_.
Referenced by TEST_F(), and TEST_F().

|
private |
Definition at line 163 of file thread_local_buffer.h.
|
private |
Definition at line 164 of file thread_local_buffer.h.
Referenced by capacity(), and is_full().
|
private |
Definition at line 166 of file thread_local_buffer.h.
Referenced by set_collector().
|
staticconstexpr |
Definition at line 68 of file thread_local_buffer.h.
|
private |
Definition at line 167 of file thread_local_buffer.h.
Referenced by get_stats().
|
private |
Definition at line 165 of file thread_local_buffer.h.