Stat series
include/stat_series.h View source View on GitHubGeneric time-bucketed statistics series.
Subsystems can embed one or more struct stat_series to track short-term rates (e.g., allocations/sec, frees/sec, requests/sec, etc).
Each bucket represents a fixed-duration window The current bucket advances as time passes
Structs
Section titled “Structs”stat_bucket
Section titled “stat_bucket” struct stat_bucket (4 fields) source
§
struct stat_series *parent §
atomic_size_t count count for this bucket
§
atomic_size_t sum optional aggregate
§
void *private private, per subsystem
stat_series
Section titled “stat_series” struct stat_series (8 fields) source
§
stat_series_callback bucket_reset to call upon bucket reset
§
struct stat_bucket *buckets cc_counted_by(nbuckets) ringbuffer
§
uint32_t nbuckets how many buckets
§
atomic_uint32_t current current bucket idx
§
atomic_uint64_t last_update_us last time we advanced
§
void *private private, per subsystem
Type Aliases
Section titled “Type Aliases”stat_series_callback
Section titled “stat_series_callback”typedef size_t (*stat_series_callback)(struct stat_bucket * bucket) source Functions
Section titled “Functions”stat_series_create
Section titled “stat_series_create”struct stat_series * stat_series_create(
uint32_t nbuckets,
time_us_t bucket_us,
stat_series_callback bucket_reset,
void *private
) source stat_series_init
Section titled “stat_series_init”void stat_series_init(
struct stat_series *s,
struct stat_bucket *buckets,
uint32_t nbuckets,
time_us_t bucket_us,
stat_series_callback bucket_reset,
void *private
) source stat_series_reset
Section titled “stat_series_reset”void stat_series_reset(struct stat_series *s) source stat_series_record
Section titled “stat_series_record”void stat_series_record(
struct stat_series *s,
size_t value,
stat_series_callback callback
) source stat_series_advance
Section titled “stat_series_advance”void stat_series_advance(struct stat_series *s, time_us_t now_us) source Macros
Section titled “Macros”stat_series_for_each
Section titled “stat_series_for_each”#define stat_series_for_each(iter_, series_) source Expansion
#define stat_series_for_each(iter_, series_) \
for (uint32_t __stat_idx = 0; \
__stat_idx < (series_)->nbuckets && \
(((iter_) = &((series_)->buckets[__stat_idx])), true); \
__stat_idx++) STAT_SERIES_DEFINE
Section titled “STAT_SERIES_DEFINE”#define STAT_SERIES_DEFINE(name, n, bucket_us) source Expansion
#define STAT_SERIES_DEFINE(name, n, bucket_us) \
static struct stat_bucket name##_buckets[(n)] = {0}; \
static struct stat_series name = { \
.buckets = name##_buckets, \
.nbuckets = (n), \
.bucket_us = (bucket_us), \
}; STAT_SERIES_CUR_BUCKET
Section titled “STAT_SERIES_CUR_BUCKET”#define STAT_SERIES_CUR_BUCKET(s) source Expansion
#define STAT_SERIES_CUR_BUCKET(s) (&(s)->buckets[(s)->current])