libosmocore  1.5.1
Osmocom core library
stat_item.h
Go to the documentation of this file.
1 #pragma once
2 
7 #include <stdint.h>
8 
10 
11 struct osmo_stat_item_desc;
12 
13 #define OSMO_STAT_ITEM_NOVALUE_ID 0
14 #define OSMO_STAT_ITEM_NO_UNIT NULL
15 
18  int32_t id;
19  int32_t value;
20 };
21 
25  const struct osmo_stat_item_desc *desc;
29  int16_t last_offs;
31  struct osmo_stat_item_value values[0];
32 };
33 
36  const char *name;
37  const char *description;
38  const char *unit;
39  unsigned int num_values;
40  int32_t default_value;
41 };
42 
46  const char *group_name_prefix;
48  const char *group_description;
50  int class_id;
52  const unsigned int num_items;
55 };
56 
60  struct llist_head list;
64  unsigned int idx;
66  struct osmo_stat_item *items[0];
67 };
68 
70  void *ctx,
71  const struct osmo_stat_item_group_desc *desc,
72  unsigned int idx);
73 
74 static inline void osmo_stat_item_group_udp_idx(
75  struct osmo_stat_item_group *grp, unsigned int idx)
76 {
77  grp->idx = idx;
78 }
79 
81 
82 void osmo_stat_item_inc(struct osmo_stat_item *item, int32_t value);
83 void osmo_stat_item_dec(struct osmo_stat_item *item, int32_t value);
84 void osmo_stat_item_set(struct osmo_stat_item *item, int32_t value);
85 
86 int osmo_stat_item_init(void *tall_ctx);
87 
89  const char *name, const unsigned int idx);
90 
92  const struct osmo_stat_item_group *statg, const char *name);
93 
94 int osmo_stat_item_get_next(const struct osmo_stat_item *item, int32_t *idx, int32_t *value);
95 
97 static int32_t osmo_stat_item_get_last(const struct osmo_stat_item *item);
98 
99 int osmo_stat_item_discard(const struct osmo_stat_item *item, int32_t *idx);
100 
101 int osmo_stat_item_discard_all(int32_t *idx);
102 
104  struct osmo_stat_item_group *, struct osmo_stat_item *, void *);
105 
106 typedef int (*osmo_stat_item_group_handler_t)(struct osmo_stat_item_group *, void *);
107 
109  osmo_stat_item_handler_t handle_item, void *data);
110 
112 
113 static inline int32_t osmo_stat_item_get_last(const struct osmo_stat_item *item)
114 {
115  return item->values[item->last_offs].value;
116 }
117 
118 void osmo_stat_item_reset(struct osmo_stat_item *item);
120 
osmo_stat_item_handler_t
int(* osmo_stat_item_handler_t)(struct osmo_stat_item_group *, struct osmo_stat_item *, void *)
Definition: stat_item.h:103
osmo_stat_item_reset
void osmo_stat_item_reset(struct osmo_stat_item *item)
Remove all values of a stat item.
Definition: stat_item.c:363
osmo_stat_item_group_desc::item_desc
const struct osmo_stat_item_desc * item_desc
Pointer to array of value names, length as per num_items.
Definition: stat_item.h:54
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 based on group + item name.
Definition: stat_item.c:301
osmo_stat_item_group
One instance of a counter group class.
Definition: stat_item.h:58
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 stat items.
Definition: stat_item.c:147
osmo_stat_item_desc::num_values
unsigned int num_values
number of values to store in FIFO
Definition: stat_item.h:39
osmo_stat_item_group::idx
unsigned int idx
The index of this value group within its class.
Definition: stat_item.h:64
osmo_stat_item_group_handler_t
int(* osmo_stat_item_group_handler_t)(struct osmo_stat_item_group *, void *)
Definition: stat_item.h:106
osmo_stat_item
data we keep for each actual item
Definition: stat_item.h:23
osmo_stat_item_desc::default_value
int32_t default_value
default value
Definition: stat_item.h:40
osmo_stat_item_group_desc::num_items
const unsigned int num_items
The number of values in this group (size of item_desc)
Definition: stat_item.h:52
osmo_stat_item_value
Individual entry in value FIFO.
Definition: stat_item.h:17
osmo_stat_item_group_reset
void osmo_stat_item_group_reset(struct osmo_stat_item_group *statg)
Reset all osmo stat items in a group.
Definition: stat_item.c:379
osmo_stat_item_inc
void osmo_stat_item_inc(struct osmo_stat_item *item, int32_t value)
Increase the stat_item to the given value.
Definition: stat_item.c:159
osmo_stat_item_group_desc
Description of a statistics item group.
Definition: stat_item.h:44
name
const char * name
osmo_stat_item_group_desc::group_description
const char * group_description
The human-readable description of the group.
Definition: stat_item.h:48
osmo_stat_item_group::list
struct llist_head list
Linked list of all value groups in the system.
Definition: stat_item.h:60
osmo_stat_item_desc::description
const char * description
description of the item
Definition: stat_item.h:37
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.
Definition: stat_item.c:213
osmo_stat_item::values
struct osmo_stat_item_value values[0]
value FIFO
Definition: stat_item.h:31
osmo_stat_item_set
void osmo_stat_item_set(struct osmo_stat_item *item, int32_t value)
Set the a given stat_item to the given value.
Definition: stat_item.c:183
data
uint8_t data[0]
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:260
osmo_stat_item::last_value_index
int32_t last_value_index
the index of the freshest value
Definition: stat_item.h:27
osmo_stat_item_discard
int osmo_stat_item_discard(const struct osmo_stat_item *item, int32_t *idx)
Skip/discard all values of this item and update idx accordingly.
Definition: stat_item.c:251
osmo_stat_item_desc::unit
const char * unit
unit of a value
Definition: stat_item.h:38
osmo_stat_item::desc
const struct osmo_stat_item_desc * desc
back-reference to the item description
Definition: stat_item.h:25
osmo_stat_item_group_udp_idx
static void osmo_stat_item_group_udp_idx(struct osmo_stat_item_group *grp, unsigned int idx)
Definition: stat_item.h:74
osmo_stat_item_for_each_group
int osmo_stat_item_for_each_group(osmo_stat_item_group_handler_t handle_group, void *data)
Iterate over all stat_item groups in system, call user-supplied function on each.
Definition: stat_item.c:345
osmo_stat_item_dec
void osmo_stat_item_dec(struct osmo_stat_item *item, int32_t value)
Descrease the stat_item to the given value.
Definition: stat_item.c:171
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:113
osmo_stat_item::last_offs
int16_t last_offs
offset to the freshest value in the value FIFO
Definition: stat_item.h:29
llist_head
(double) linked list header structure
Definition: linuxlist.h:46
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:79
osmo_stat_item_value::value
int32_t value
actual value
Definition: stat_item.h:19
osmo_stat_item_group::desc
const struct osmo_stat_item_group_desc * desc
Pointer to the counter group class.
Definition: stat_item.h:62
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:281
desc
osmo_stat_item_desc::name
const char * name
name of the item
Definition: stat_item.h:36
osmo_stat_item_value::id
int32_t id
identifier of value
Definition: stat_item.h:18
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:46
osmo_stat_item_group::items
struct osmo_stat_item * items[0]
Actual counter structures below.
Definition: stat_item.h:66
osmo_stat_item_desc
Statistics item description.
Definition: stat_item.h:35
linuxlist.h
osmo_stat_item_group_desc::class_id
int class_id
The class to which this group belongs.
Definition: stat_item.h:50
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)
Iterate over all items in group, call user-supplied function on each.
Definition: stat_item.c:325
osmo_stat_item_init
int osmo_stat_item_init(void *tall_ctx)
Initialize the stat item module.
Definition: stat_item.c:270