101 void record(std::chrono::nanoseconds value);
107 void record_ns(std::uint64_t nanoseconds);
118 [[nodiscard]]
double percentile(
double p)
const;
157 [[nodiscard]]
double mean()
const;
165 [[nodiscard]]
double stddev()
const;
173 [[nodiscard]] std::uint64_t
min()
const;
181 [[nodiscard]] std::uint64_t
max()
const;
187 [[nodiscard]] std::uint64_t
count()
const;
193 [[nodiscard]] std::uint64_t
sum()
const;
207 [[nodiscard]]
bool empty()
const;
222 [[nodiscard]] std::uint64_t
bucket_count(std::size_t bucket_index)
const;
257 std::atomic<std::uint64_t>
min_value_{std::numeric_limits<std::uint64_t>::max()};
HDR-style histogram for latency distribution with logarithmic buckets.
LatencyHistogram()
Default constructor - initializes all buckets to zero.
void record(std::chrono::nanoseconds value)
Record a latency value.
double mean() const
Calculate the arithmetic mean.
static constexpr std::size_t BUCKET_COUNT
Number of histogram buckets.
std::uint64_t count() const
Get the total count of recorded values.
std::uint64_t sum() const
Get the sum of all recorded values.
std::uint64_t bucket_count(std::size_t bucket_index) const
Get the bucket count at a specific index.
static std::size_t compute_bucket_index(std::uint64_t value)
Compute the bucket index for a given value.
std::atomic< std::uint64_t > min_value_
Minimum recorded value.
double p50() const
Get the 50th percentile (median).
std::atomic< std::uint64_t > total_count_
Total number of recorded values.
std::array< std::atomic< std::uint64_t >, BUCKET_COUNT > buckets_
Histogram buckets using logarithmic distribution.
bool empty() const
Check if the histogram is empty.
double p95() const
Get the 95th percentile.
double p90() const
Get the 90th percentile.
static std::uint64_t bucket_lower_bound(std::size_t bucket_index)
Get the lower bound of a bucket.
double stddev() const
Calculate the standard deviation.
double p99() const
Get the 99th percentile.
double percentile(double p) const
Calculate the value at a given percentile.
std::atomic< std::uint64_t > max_value_
Maximum recorded value.
static std::uint64_t bucket_upper_bound(std::size_t bucket_index)
Get the upper bound of a bucket.
std::uint64_t min() const
Get the minimum recorded value.
std::atomic< std::uint64_t > total_sum_
Sum of all recorded values.
void reset()
Reset all buckets and counters to zero.
~LatencyHistogram()=default
Destructor.
static double bucket_midpoint(std::size_t bucket_index)
Get the midpoint value of a bucket for estimation.
void record_ns(std::uint64_t nanoseconds)
Record a raw nanosecond value.
LatencyHistogram & operator=(const LatencyHistogram &other)
Copy assignment operator.
std::uint64_t max() const
Get the maximum recorded value.
void merge(const LatencyHistogram &other)
Merge another histogram into this one.
double p999() const
Get the 99.9th percentile.