rate_ctr.h
Go to the documentation of this file.
#pragma once
#include <stdint.h>
#include <osmocom/core/linuxlist.h>
#define RATE_CTR_INTV_NUM 4
enum rate_ctr_intv {
RATE_CTR_INTV_SEC,
RATE_CTR_INTV_MIN,
RATE_CTR_INTV_HOUR,
RATE_CTR_INTV_DAY,
};
struct rate_ctr_per_intv {
uint64_t last;
uint64_t rate;
};
struct rate_ctr {
uint64_t current;
uint64_t previous;
struct rate_ctr_per_intv intv[RATE_CTR_INTV_NUM];
};
struct rate_ctr_desc {
const char *name;
const char *description;
};
struct rate_ctr_group_desc {
const char *group_name_prefix;
const char *group_description;
int class_id;
unsigned int num_ctr;
const struct rate_ctr_desc *ctr_desc;
};
struct rate_ctr_group {
struct llist_head list;
const struct rate_ctr_group_desc *desc;
unsigned int idx;
struct rate_ctr ctr[0];
};
struct rate_ctr_group *rate_ctr_group_alloc(void *ctx,
const struct rate_ctr_group_desc *desc,
unsigned int idx);
static inline void rate_ctr_group_upd_idx(struct rate_ctr_group *grp, unsigned int idx)
{
grp->idx = idx;
}
void rate_ctr_group_free(struct rate_ctr_group *grp);
void rate_ctr_add(struct rate_ctr *ctr, int inc);
static inline void rate_ctr_inc(struct rate_ctr *ctr)
{
rate_ctr_add(ctr, 1);
}
static inline void rate_ctr_inc2(struct rate_ctr_group *ctrg, unsigned int idx)
{
rate_ctr_inc(&ctrg->ctr[idx]);
}
int64_t rate_ctr_difference(struct rate_ctr *ctr);
int rate_ctr_init(void *tall_ctx);
struct rate_ctr_group *rate_ctr_get_group_by_name_idx(const char *name, const unsigned int idx);
const struct rate_ctr *rate_ctr_get_by_name(const struct rate_ctr_group *ctrg, const char *name);
typedef int (*rate_ctr_handler_t)(
struct rate_ctr_group *, struct rate_ctr *,
const struct rate_ctr_desc *, void *);
typedef int (*rate_ctr_group_handler_t)(struct rate_ctr_group *, void *);
int rate_ctr_for_each_counter(struct rate_ctr_group *ctrg,
rate_ctr_handler_t handle_counter, void *data);
int rate_ctr_for_each_group(rate_ctr_group_handler_t handle_group, void *data);
rate_ctr_for_each_counter
int rate_ctr_for_each_counter(struct rate_ctr_group *ctrg, rate_ctr_handler_t handle_counter, void *data)
Iterate over all counters.
Definition: rate_ctr.c:389
RATE_CTR_INTV_HOUR
@ RATE_CTR_INTV_HOUR
last hour
Definition: rate_ctr.h:18
rate_ctr_group_desc::ctr_desc
const struct rate_ctr_desc * ctr_desc
Pointer to array of counter names.
Definition: rate_ctr.h:53
rate_ctr_desc
rate counter description
Definition: rate_ctr.h:37
rate_ctr_init
int rate_ctr_init(void *tall_ctx)
Initialize the counter module.
Definition: rate_ctr.c:331
rate_ctr_add
void rate_ctr_add(struct rate_ctr *ctr, int inc)
Increment the counter by inc.
Definition: rate_ctr.c:263
rate_ctr_group::desc
const struct rate_ctr_group_desc * desc
Pointer to the counter group class.
Definition: rate_ctr.h:61
rate_ctr_group_free
void rate_ctr_group_free(struct rate_ctr_group *grp)
Free the memory for the specified group of counters.
Definition: rate_ctr.c:256
rate_ctr_group_desc::class_id
int class_id
The class to which this group belongs.
Definition: rate_ctr.h:49
rate_ctr_per_intv::rate
uint64_t rate
counter rate
Definition: rate_ctr.h:25
RATE_CTR_INTV_MIN
@ RATE_CTR_INTV_MIN
last minute
Definition: rate_ctr.h:17
rate_ctr_desc::description
const char * description
description of the counter
Definition: rate_ctr.h:39
name
char name[32]
source file name
Definition: gsmtap.h:13
rate_ctr_group_upd_idx
static void rate_ctr_group_upd_idx(struct rate_ctr_group *grp, unsigned int idx)
Definition: rate_ctr.h:72
rate_ctr_inc
static void rate_ctr_inc(struct rate_ctr *ctr)
Increment the counter by 1.
Definition: rate_ctr.h:86
rate_ctr_get_by_name
const struct rate_ctr * rate_ctr_get_by_name(const struct rate_ctr_group *ctrg, const char *name)
Search for counter based on group + name.
Definition: rate_ctr.c:365
rate_ctr_group
One instance of a counter group class.
Definition: rate_ctr.h:57
rate_ctr_group_desc::group_description
const char * group_description
The human-readable description of the group.
Definition: rate_ctr.h:47
rate_ctr_get_group_by_name_idx
struct rate_ctr_group * rate_ctr_get_group_by_name_idx(const char *name, const unsigned int idx)
Search for counter group based on group name and index.
Definition: rate_ctr.c:344
rate_ctr_group::list
struct llist_head list
Linked list of all counter groups in the system.
Definition: rate_ctr.h:59
rate_ctr_handler_t
int(* rate_ctr_handler_t)(struct rate_ctr_group *, struct rate_ctr *, const struct rate_ctr_desc *, void *)
Definition: rate_ctr.h:108
rate_ctr_group_desc::num_ctr
unsigned int num_ctr
The number of counters in this group.
Definition: rate_ctr.h:51
rate_ctr_group_handler_t
int(* rate_ctr_group_handler_t)(struct rate_ctr_group *, void *)
Definition: rate_ctr.h:111
rate_ctr_group::ctr
struct rate_ctr ctr[0]
Actual counter structures below.
Definition: rate_ctr.h:65
rate_ctr_group_alloc
struct rate_ctr_group * rate_ctr_group_alloc(void *ctx, const struct rate_ctr_group_desc *desc, unsigned int idx)
Allocate a new group of counters according to description.
Definition: rate_ctr.c:213
rate_ctr_desc::name
const char * name
name of the counter
Definition: rate_ctr.h:38
rate_ctr_per_intv
data we keep for each of the intervals
Definition: rate_ctr.h:23
llist_head
(double) linked list header structure
Definition: linuxlist.h:46
rate_ctr_group_desc::group_name_prefix
const char * group_name_prefix
The prefix to the name of all counters in this group.
Definition: rate_ctr.h:45
rate_ctr_difference
int64_t rate_ctr_difference(struct rate_ctr *ctr)
Return the counter difference since the last call to this function.
Definition: rate_ctr.c:269
rate_ctr_intv
rate_ctr_intv
Rate counter interval.
Definition: rate_ctr.h:15
handle_counter
static int handle_counter(struct osmo_counter *counter, void *sctx_)
Definition: stats.c:672
rate_ctr::previous
uint64_t previous
previous value, used for delta
Definition: rate_ctr.h:31
rate_ctr_inc2
static void rate_ctr_inc2(struct rate_ctr_group *ctrg, unsigned int idx)
Increment the counter by 1.
Definition: rate_ctr.h:94
rate_ctr::current
uint64_t current
current value
Definition: rate_ctr.h:30
rate_ctr::intv
struct rate_ctr_per_intv intv[RATE_CTR_INTV_NUM]
per-interval data
Definition: rate_ctr.h:33
rate_ctr_group_desc
description of a rate counter group
Definition: rate_ctr.h:43
RATE_CTR_INTV_NUM
#define RATE_CTR_INTV_NUM
Number of rate counter intervals.
Definition: rate_ctr.h:12
rate_ctr_for_each_group
int rate_ctr_for_each_group(rate_ctr_group_handler_t handle_group, void *data)
Iterate over all counter groups.
Definition: rate_ctr.c:411
linuxlist.h
rate_ctr_per_intv::last
uint64_t last
counter value in last interval
Definition: rate_ctr.h:24
RATE_CTR_INTV_DAY
@ RATE_CTR_INTV_DAY
last day
Definition: rate_ctr.h:19
RATE_CTR_INTV_SEC
@ RATE_CTR_INTV_SEC
last second
Definition: rate_ctr.h:16
rate_ctr
data we keep for each actual value
Definition: rate_ctr.h:29
rate_ctr_group::idx
unsigned int idx
The index of this ctr_group within its class.
Definition: rate_ctr.h:63