stat_item.h
Go to the documentation of this file.
#pragma once
#include <stdint.h>
#include <osmocom/core/linuxlist.h>
struct osmo_stat_item_desc;
#define STAT_ITEM_NOVALUE_ID 0
struct osmo_stat_item_value {
int32_t id;
int32_t value;
};
struct osmo_stat_item {
const struct osmo_stat_item_desc *desc;
int32_t last_value_index;
int16_t last_offs;
struct osmo_stat_item_value values[0];
};
struct osmo_stat_item_desc {
const char *name;
const char *description;
const char *unit;
unsigned int num_values;
int32_t default_value;
};
struct osmo_stat_item_group_desc {
const char *group_name_prefix;
const char *group_description;
int class_id;
const unsigned int num_items;
const struct osmo_stat_item_desc *item_desc;
};
struct osmo_stat_item_group {
struct llist_head list;
const struct osmo_stat_item_group_desc *desc;
unsigned int idx;
struct osmo_stat_item *items[0];
};
struct osmo_stat_item_group *osmo_stat_item_group_alloc(
void *ctx,
const struct osmo_stat_item_group_desc *desc,
unsigned int idx);
void osmo_stat_item_group_free(struct osmo_stat_item_group *statg);
void osmo_stat_item_set(struct osmo_stat_item *item, int32_t value);
int osmo_stat_item_init(void *tall_ctx);
struct osmo_stat_item_group *osmo_stat_item_get_group_by_name_idx(
const char *name, const unsigned int idx);
const struct osmo_stat_item *osmo_stat_item_get_by_name(
const struct osmo_stat_item_group *statg, const char *name);
int osmo_stat_item_get_next(const struct osmo_stat_item *item, int32_t *idx, int32_t *value);
static int32_t osmo_stat_item_get_last(const struct osmo_stat_item *item);
int osmo_stat_item_discard(const struct osmo_stat_item *item, int32_t *idx);
int osmo_stat_item_discard_all(int32_t *idx);
typedef int (*osmo_stat_item_handler_t)(
struct osmo_stat_item_group *, struct osmo_stat_item *, void *);
typedef int (*osmo_stat_item_group_handler_t)(struct osmo_stat_item_group *, void *);
int osmo_stat_item_for_each_item(struct osmo_stat_item_group *statg,
osmo_stat_item_handler_t handle_item, void *data);
int osmo_stat_item_for_each_group(osmo_stat_item_group_handler_t handle_group, void *data);
static inline int32_t osmo_stat_item_get_last(const struct osmo_stat_item *item)
{
return item->values[item->last_offs].value;
}
osmo_stat_item_group_desc
description of a statistics value group
Definition: stat_item.h:43
osmo_stat_item_group::desc
const struct osmo_stat_item_group_desc * desc
Pointer to the counter group class.
Definition: stat_item.h:61
osmo_stat_item_discard
int osmo_stat_item_discard(const struct osmo_stat_item *item, int32_t *idx)
Skip all values of the item and update idx accordingly.
Definition: stat_item.c:176
osmo_stat_item_group_desc::class_id
int class_id
The class to which this group belongs.
Definition: stat_item.h:49
osmo_stat_item_group_desc::group_description
const char * group_description
The human-readable description of the group.
Definition: stat_item.h:47
osmo_stat_item_group_alloc
struct osmo_stat_item_group * osmo_stat_item_group_alloc(void *ctx, const struct osmo_stat_item_group_desc *desc, unsigned int idx)
Allocate a new group of counters according to description.
Definition: stat_item.c:50
osmo_stat_item_desc::num_values
unsigned int num_values
number of values to store
Definition: stat_item.h:38
osmo_stat_item::values
struct osmo_stat_item_value values[0]
value fifo
Definition: stat_item.h:30
osmo_stat_item_desc::description
const char * description
description of the item
Definition: stat_item.h:36
osmo_stat_item_init
int osmo_stat_item_init(void *tall_ctx)
Initialize the stat item module.
Definition: stat_item.c:194
osmo_stat_item_desc::unit
const char * unit
unit of a value
Definition: stat_item.h:37
osmo_stat_item_group_desc::num_items
const unsigned int num_items
The number of values in this group.
Definition: stat_item.h:51
osmo_stat_item_group::idx
unsigned int idx
The index of this value group within its class.
Definition: stat_item.h:63
osmo_stat_item::last_value_index
int32_t last_value_index
the index of the freshest value
Definition: stat_item.h:26
osmo_stat_item_get_next
int osmo_stat_item_get_next(const struct osmo_stat_item *item, int32_t *idx, int32_t *value)
Retrieve the next value from the osmo_stat_item object. If a new value has been set, it is returned. The idx is used to decide which value to return. On success, *idx is updated to refer to the next unread value. If values have been missed due to FIFO overflow, *idx is incremented by (1 + num_lost). This way, the osmo_stat_item object can be kept stateless from the reader&#39;s perspective and therefore be used by several backends simultaneously.
Definition: stat_item.c:138
osmo_stat_item_get_group_by_name_idx
struct osmo_stat_item_group * osmo_stat_item_get_group_by_name_idx(const char *name, const unsigned int idx)
Search for item group based on group name and index.
Definition: stat_item.c:202
osmo_stat_item_group_desc::group_name_prefix
const char * group_name_prefix
The prefix to the name of all values in this group.
Definition: stat_item.h:45
llist_head
Definition: linuxlist.h:42
osmo_stat_item::last_offs
int16_t last_offs
offset to the freshest value in the value fifo
Definition: stat_item.h:28
osmo_stat_item_group
One instance of a counter group class.
Definition: stat_item.h:57
osmo_stat_item_get_by_name
const struct osmo_stat_item * osmo_stat_item_get_by_name(const struct osmo_stat_item_group *statg, const char *name)
Search for item group based on group name.
Definition: stat_item.c:219
osmo_stat_item_desc::name
const char * name
name of the item
Definition: stat_item.h:35
osmo_stat_item
data we keep for each actual value
Definition: stat_item.h:23
osmo_stat_item_group_desc::item_desc
const struct osmo_stat_item_desc * item_desc
Pointer to array of value names.
Definition: stat_item.h:53
osmo_stat_item_get_last
static int32_t osmo_stat_item_get_last(const struct osmo_stat_item *item)
Get the last (freshest) value.
Definition: stat_item.h:126
osmo_stat_item_value
Definition: stat_item.h:17
osmo_stat_item_for_each_item
int osmo_stat_item_for_each_item(struct osmo_stat_item_group *statg, osmo_stat_item_handler_t handle_item, void *data)
Iteate over all items.
Definition: stat_item.c:238
osmo_stat_item_group_free
void osmo_stat_item_group_free(struct osmo_stat_item_group *statg)
Free the memory for the specified group of counters.
Definition: stat_item.c:118
osmo_stat_item_desc
statistics value description
Definition: stat_item.h:34
osmo_stat_item_discard_all
int osmo_stat_item_discard_all(int32_t *idx)
Skip all values of all items and update idx accordingly.
Definition: stat_item.c:185