|
Network System 0.1.1
High-performance modular networking library for scalable client-server applications
|
Thread-safe histogram for capturing value distributions. More...
#include <histogram.h>

Public Member Functions | |
| histogram (histogram_config cfg=histogram_config::default_latency_config()) | |
| Construct histogram with configuration. | |
| ~histogram ()=default | |
| Destructor. | |
| histogram (const histogram &)=delete | |
| auto | operator= (const histogram &) -> histogram &=delete |
| histogram (histogram &&other) noexcept | |
| auto | operator= (histogram &&other) noexcept -> histogram & |
| void | record (double value) |
| Record a value observation. | |
| auto | count () const -> uint64_t |
| Get total number of observations. | |
| auto | sum () const -> double |
| Get sum of all observations. | |
| auto | min () const -> double |
| Get minimum observed value. | |
| auto | max () const -> double |
| Get maximum observed value. | |
| auto | mean () const -> double |
| Get mean of all observations. | |
| auto | percentile (double p) const -> double |
| Calculate percentile value. | |
| auto | p50 () const -> double |
| Get 50th percentile (median) | |
| auto | p95 () const -> double |
| Get 95th percentile. | |
| auto | p99 () const -> double |
| Get 99th percentile. | |
| auto | p999 () const -> double |
| Get 99.9th percentile. | |
| auto | buckets () const -> std::vector< std::pair< double, uint64_t > > |
| Get all bucket counts. | |
| auto | snapshot (const std::map< std::string, std::string > &labels={}) const -> histogram_snapshot |
| Create immutable snapshot of current state. | |
| void | reset () |
| Reset all statistics. | |
Private Member Functions | |
| auto | find_bucket (double value) const -> size_t |
| Find bucket index for a value. | |
| void | update_min (double value) |
| Update min value atomically. | |
| void | update_max (double value) |
| Update max value atomically. | |
| void | add_to_sum (double value) |
| Add to sum atomically. | |
Private Attributes | |
| std::vector< double > | boundaries_ |
| std::unique_ptr< std::atomic< uint64_t >[]> | bucket_counts_ |
| size_t | bucket_count_ {0} |
| std::atomic< uint64_t > | count_ {0} |
| std::atomic< double > | sum_ {0.0} |
| std::atomic< double > | min_ {std::numeric_limits<double>::infinity()} |
| std::atomic< double > | max_ {-std::numeric_limits<double>::infinity()} |
| std::mutex | mutex_ |
Thread-safe histogram for capturing value distributions.
This histogram implementation uses predefined bucket boundaries to track the distribution of values. It supports:
Definition at line 105 of file histogram.h.
|
explicit |
Construct histogram with configuration.
| cfg | Configuration with bucket boundaries |
Definition at line 153 of file histogram.cpp.
References boundaries_, kcenon::network::metrics::histogram_config::bucket_boundaries, bucket_count_, bucket_counts_, and kcenon::network::metrics::histogram_config::default_latency_config().

|
default |
Destructor.
|
delete |
|
noexcept |
Definition at line 175 of file histogram.cpp.
|
private |
Add to sum atomically.
| value | Value to add |
Definition at line 390 of file histogram.cpp.
References sum_.
Referenced by record().

|
nodiscard |
Get all bucket counts.
Definition at line 305 of file histogram.cpp.
References boundaries_, bucket_count_, bucket_counts_, and mutex_.
|
nodiscard |
Get total number of observations.
Definition at line 214 of file histogram.cpp.
References count_.
Referenced by mean().

|
nodiscardprivate |
Find bucket index for a value.
| value | The value to classify |
Definition at line 360 of file histogram.cpp.
Referenced by record().

|
nodiscard |
Get maximum observed value.
Definition at line 229 of file histogram.cpp.
References max_.
|
nodiscard |
Get mean of all observations.
Definition at line 234 of file histogram.cpp.
References count(), and sum().

|
nodiscard |
Get minimum observed value.
Definition at line 224 of file histogram.cpp.
References min_.
|
delete |
Definition at line 187 of file histogram.cpp.
|
inlinenodiscard |
Get 50th percentile (median)
Definition at line 179 of file histogram.h.
|
inlinenodiscard |
|
inlinenodiscard |
|
inlinenodiscard |
|
nodiscard |
Calculate percentile value.
| p | Percentile (0.0 to 1.0) |
Uses linear interpolation within buckets for estimation.
Definition at line 244 of file histogram.cpp.
| void kcenon::network::metrics::histogram::record | ( | double | value | ) |
Record a value observation.
| value | The value to record |
Thread-safe. Values are placed in the appropriate bucket based on configured boundaries.
Definition at line 203 of file histogram.cpp.
References add_to_sum(), bucket_counts_, count_, find_bucket(), update_max(), and update_min().
Referenced by main().


| void kcenon::network::metrics::histogram::reset | ( | ) |
Reset all statistics.
Thread-safe. Clears all observations.
Definition at line 345 of file histogram.cpp.
References bucket_count_, bucket_counts_, count_, max_, min_, mutex_, and sum_.
|
nodiscard |
Create immutable snapshot of current state.
| labels | Additional labels to include in snapshot |
Definition at line 322 of file histogram.cpp.
References kcenon::network::metrics::histogram_snapshot::buckets, kcenon::network::metrics::histogram_snapshot::count, kcenon::network::metrics::histogram_snapshot::labels, kcenon::network::metrics::histogram_snapshot::max_value, kcenon::network::metrics::histogram_snapshot::min_value, kcenon::network::metrics::histogram_snapshot::percentiles, and kcenon::network::metrics::histogram_snapshot::sum.
|
nodiscard |
Get sum of all observations.
Definition at line 219 of file histogram.cpp.
References sum_.
Referenced by mean().

|
private |
Update max value atomically.
| value | New potential maximum |
Definition at line 380 of file histogram.cpp.
References max_.
Referenced by record().

|
private |
Update min value atomically.
| value | New potential minimum |
Definition at line 370 of file histogram.cpp.
References min_.
Referenced by record().

|
private |
Definition at line 221 of file histogram.h.
Referenced by buckets(), and histogram().
|
private |
Definition at line 223 of file histogram.h.
Referenced by buckets(), histogram(), and reset().
|
private |
Definition at line 222 of file histogram.h.
Referenced by buckets(), histogram(), record(), and reset().
|
private |
|
private |
Definition at line 227 of file histogram.h.
Referenced by max(), reset(), and update_max().
|
private |
Definition at line 226 of file histogram.h.
Referenced by min(), reset(), and update_min().
|
mutableprivate |
Definition at line 228 of file histogram.h.
|
private |
Definition at line 225 of file histogram.h.
Referenced by add_to_sum(), reset(), and sum().