|
Network System 0.1.1
High-performance modular networking library for scalable client-server applications
|
Time-windowed histogram for tracking recent latency distributions. More...
#include <sliding_histogram.h>

Classes | |
| struct | time_bucket |
Public Member Functions | |
| sliding_histogram (sliding_histogram_config cfg=sliding_histogram_config::default_config()) | |
| Construct sliding histogram with configuration. | |
| ~sliding_histogram ()=default | |
| Destructor. | |
| sliding_histogram (const sliding_histogram &)=delete | |
| auto | operator= (const sliding_histogram &) -> sliding_histogram &=delete |
| sliding_histogram (sliding_histogram &&other) noexcept | |
| auto | operator= (sliding_histogram &&other) noexcept -> sliding_histogram & |
| void | record (double value) |
| Record a value observation. | |
| auto | count () const -> uint64_t |
| Get total number of observations in current window. | |
| auto | sum () const -> double |
| Get sum of all observations in current window. | |
| auto | mean () const -> double |
| Get mean of all observations in current window. | |
| auto | percentile (double p) const -> double |
| Calculate percentile value for current window. | |
| auto | p50 () const -> double |
| Get 50th percentile (median) for current window. | |
| auto | p95 () const -> double |
| Get 95th percentile for current window. | |
| auto | p99 () const -> double |
| Get 99th percentile for current window. | |
| auto | p999 () const -> double |
| Get 99.9th percentile for current window. | |
| auto | snapshot (const std::map< std::string, std::string > &labels={}) const -> histogram_snapshot |
| Create snapshot aggregating all time buckets in current window. | |
| auto | window_duration () const -> std::chrono::seconds |
| Get the window duration. | |
| void | reset () |
| Reset all data. | |
Private Member Functions | |
| void | expire_old_buckets () |
| Expire old buckets outside the window. | |
| auto | get_current_bucket () -> time_bucket & |
| Get or create current time bucket. | |
| auto | aggregate () const -> histogram_snapshot |
| Create aggregated histogram from all buckets. | |
Private Attributes | |
| sliding_histogram_config | config_ |
| std::chrono::milliseconds | bucket_duration_ |
| std::deque< std::unique_ptr< time_bucket > > | buckets_ |
| std::mutex | mutex_ |
Time-windowed histogram for tracking recent latency distributions.
This class maintains a sliding window of histogram data, automatically expiring old measurements. Useful for monitoring recent performance without accumulating historical data indefinitely.
Definition at line 66 of file sliding_histogram.h.
|
explicit |
Construct sliding histogram with configuration.
| cfg | Configuration for the sliding window |
Definition at line 13 of file sliding_histogram.cpp.
References kcenon::network::metrics::sliding_histogram_config::bucket_count, and config_.
|
default |
Destructor.
|
delete |
|
noexcept |
Definition at line 26 of file sliding_histogram.cpp.
|
nodiscardprivate |
Create aggregated histogram from all buckets.
Definition at line 186 of file sliding_histogram.cpp.
References kcenon::network::metrics::histogram_snapshot::buckets, buckets_, kcenon::network::metrics::histogram_snapshot::count, expire_old_buckets(), kcenon::network::metrics::histogram_snapshot::max_value, kcenon::network::metrics::histogram_snapshot::min_value, mutex_, kcenon::network::metrics::histogram_snapshot::percentiles, and kcenon::network::metrics::histogram_snapshot::sum.

|
nodiscard |
Get total number of observations in current window.
Definition at line 53 of file sliding_histogram.cpp.
References buckets_, expire_old_buckets(), and mutex_.
Referenced by mean().


|
private |
Expire old buckets outside the window.
Definition at line 154 of file sliding_histogram.cpp.
References buckets_, config_, and kcenon::network::metrics::sliding_histogram_config::window_duration.
Referenced by aggregate(), count(), record(), and sum().

|
private |
Get or create current time bucket.
Definition at line 165 of file sliding_histogram.cpp.
Referenced by record().

|
nodiscard |
Get mean of all observations in current window.
Definition at line 79 of file sliding_histogram.cpp.
References count(), and sum().

|
delete |
|
noexcept |
Definition at line 33 of file sliding_histogram.cpp.
|
inlinenodiscard |
Get 50th percentile (median) for current window.
Definition at line 126 of file sliding_histogram.h.
References percentile().

|
inlinenodiscard |
Get 95th percentile for current window.
Definition at line 132 of file sliding_histogram.h.
References percentile().

|
inlinenodiscard |
Get 99th percentile for current window.
Definition at line 138 of file sliding_histogram.h.
References percentile().

|
inlinenodiscard |
Get 99.9th percentile for current window.
Definition at line 144 of file sliding_histogram.h.
References percentile().

|
nodiscard |
Calculate percentile value for current window.
| p | Percentile (0.0 to 1.0) |
Definition at line 89 of file sliding_histogram.cpp.
Referenced by p50(), p95(), p99(), and p999().

| void kcenon::network::metrics::sliding_histogram::record | ( | double | value | ) |
Record a value observation.
| value | The value to record |
Thread-safe. Automatically creates new time buckets as needed and expires old ones.
Definition at line 45 of file sliding_histogram.cpp.
References expire_old_buckets(), get_current_bucket(), and mutex_.

| void kcenon::network::metrics::sliding_histogram::reset | ( | ) |
|
nodiscard |
Create snapshot aggregating all time buckets in current window.
| labels | Additional labels to include in snapshot |
Definition at line 140 of file sliding_histogram.cpp.
|
nodiscard |
Get sum of all observations in current window.
Definition at line 66 of file sliding_histogram.cpp.
References buckets_, expire_old_buckets(), and mutex_.
Referenced by mean().


|
inlinenodiscard |
Get the window duration.
Definition at line 158 of file sliding_histogram.h.
References config_, and kcenon::network::metrics::sliding_histogram_config::window_duration.
|
private |
Definition at line 183 of file sliding_histogram.h.
|
private |
Definition at line 184 of file sliding_histogram.h.
Referenced by aggregate(), count(), expire_old_buckets(), reset(), and sum().
|
private |
Definition at line 182 of file sliding_histogram.h.
Referenced by expire_old_buckets(), sliding_histogram(), and window_duration().
|
mutableprivate |
Definition at line 185 of file sliding_histogram.h.
Referenced by aggregate(), count(), record(), reset(), and sum().