Lightweight 0.20260921.0
Loading...
Searching...
No Matches
Lightweight::SqlLatencyHistogram Struct Reference

#include <SqlStatistics.hpp>

Public Member Functions

LIGHTWEIGHT_API double AverageMicroseconds () const noexcept
 
LIGHTWEIGHT_API std::uint64_t PercentileMicroseconds (double percentile) const noexcept
 

Static Public Member Functions

static constexpr std::size_t BucketOf (std::uint64_t microseconds) noexcept
 

Public Attributes

std::array< std::uint64_t, BucketCount > buckets {}
 Per-bucket sample counts; bucket i covers [2^(i-1), 2^i) microseconds.
 
std::uint64_t count {}
 Total number of samples recorded.
 
std::uint64_t totalMicroseconds {}
 Sum of all sample values, in microseconds.
 
std::uint64_t minMicroseconds {}
 Smallest sample recorded, in microseconds; 0 when count is 0.
 
std::uint64_t maxMicroseconds {}
 Largest sample recorded, in microseconds; 0 when count is 0.
 

Static Public Attributes

static constexpr std::size_t BucketCount = 32
 Number of histogram buckets.
 

Detailed Description

A fixed-bucket latency histogram, in microseconds.

Buckets are power-of-two spaced: bucket i counts samples in [2^(i-1), 2^i) microseconds, with bucket 0 counting [0, 1) and the last bucket acting as an open-ended overflow. That covers sub-microsecond calls up to ~35 minutes in BucketCount buckets, and makes bucket selection a single std::bit_width rather than a search — cheap enough to sit on the hot path.

This is the plain-struct snapshot type. It is a value: copy it, export it, diff two of them. The live counters are held separately by SqlStatistics.

Definition at line 83 of file SqlStatistics.hpp.

Member Function Documentation

◆ AverageMicroseconds()

LIGHTWEIGHT_API double Lightweight::SqlLatencyHistogram::AverageMicroseconds ( ) const
noexcept

Retrieves the arithmetic mean sample value.

Returns
The mean, in microseconds; 0.0 when no samples were recorded.

◆ PercentileMicroseconds()

LIGHTWEIGHT_API std::uint64_t Lightweight::SqlLatencyHistogram::PercentileMicroseconds ( double  percentile) const
noexcept

Estimates a percentile from the bucket counts.

The result is the upper bound of the bucket the percentile falls into, so it is an over-estimate bounded by a factor of two — the standard trade-off for a power-of-two histogram, and accurate enough to spot a regression without storing every sample.

Parameters
percentileThe percentile to estimate, in [0.0, 1.0] (e.g. 0.99 for p99).
Returns
The estimated latency, in microseconds; 0 when no samples were recorded.

◆ BucketOf()

static constexpr std::size_t Lightweight::SqlLatencyHistogram::BucketOf ( std::uint64_t  microseconds)
inlinestaticconstexprnoexcept

Retrieves the index of the bucket a given sample value falls into.

Parameters
microsecondsThe sample value.
Returns
The bucket index, clamped to BucketCount - 1.

Definition at line 123 of file SqlStatistics.hpp.

References BucketCount.

Member Data Documentation

◆ BucketCount

constexpr std::size_t Lightweight::SqlLatencyHistogram::BucketCount = 32
staticconstexpr

Number of histogram buckets.

Definition at line 86 of file SqlStatistics.hpp.

Referenced by BucketOf().

◆ buckets

std::array<std::uint64_t, BucketCount> Lightweight::SqlLatencyHistogram::buckets {}

Per-bucket sample counts; bucket i covers [2^(i-1), 2^i) microseconds.

Definition at line 89 of file SqlStatistics.hpp.

◆ count

std::uint64_t Lightweight::SqlLatencyHistogram::count {}

Total number of samples recorded.

Definition at line 92 of file SqlStatistics.hpp.

◆ totalMicroseconds

std::uint64_t Lightweight::SqlLatencyHistogram::totalMicroseconds {}

Sum of all sample values, in microseconds.

Definition at line 95 of file SqlStatistics.hpp.

◆ minMicroseconds

std::uint64_t Lightweight::SqlLatencyHistogram::minMicroseconds {}

Smallest sample recorded, in microseconds; 0 when count is 0.

Definition at line 98 of file SqlStatistics.hpp.

◆ maxMicroseconds

std::uint64_t Lightweight::SqlLatencyHistogram::maxMicroseconds {}

Largest sample recorded, in microseconds; 0 when count is 0.

Definition at line 101 of file SqlStatistics.hpp.


The documentation for this struct was generated from the following file: