Skip to content

Stat series

include/stat_series.h View source View on GitHub

Generic 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

struct stat_bucket (4 fields) source
§ struct stat_series *parent

count for this bucket

optional aggregate

§ void *private

private, per subsystem

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

current bucket idx

§ time_us_t bucket_us

duration for each bucket

§ atomic_uint64_t last_update_us

last time we advanced

§ void *private

private, per subsystem

§ struct spinlock lock
typedef size_t (*stat_series_callback)(struct stat_bucket * bucket)
source
struct stat_series * stat_series_create(
    uint32_t nbuckets,
    time_us_t bucket_us,
    stat_series_callback bucket_reset,
    void *private
)
source
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
void stat_series_reset(struct stat_series *s)
source
void stat_series_record(
    struct stat_series *s,
    size_t value,
    stat_series_callback callback
)
source
void stat_series_advance(struct stat_series *s, time_us_t now_us)
source
#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++)
#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), \
    };
#define STAT_SERIES_CUR_BUCKET(s)
source
Expansion
#define STAT_SERIES_CUR_BUCKET(s) (&(s)->buckets[(s)->current])