libosmocore  1.5.1.205-e67e
Osmocom core library
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
stat_item.h
Go to the documentation of this file.
1 #pragma once
2 
7 #include <stdint.h>
8 
9 #include <osmocom/core/defs.h>
10 #include <osmocom/core/linuxlist.h>
11 
12 struct osmo_stat_item_desc;
13 
14 #define OSMO_STAT_ITEM_NOVALUE_ID 0
15 #define OSMO_STAT_ITEM_NO_UNIT NULL
16 
19  int32_t id;
20  int32_t value;
21 };
22 
26  const struct osmo_stat_item_desc *desc;
27  /* internal use by stats API (stats.c): the id of the next value to
28  * be read from the FIFO. If accessing osmo_stat_item directly, without
29  * the stats API, store this value elsewhere. */
30  int32_t stats_next_id;
31  /* internal use by stats API: indicate if the last value sent to
32  * reporters was actually the last value in the FIFO. This may not be
33  * the case, as always a max of 1 or more values gets sent (OS#5215) */
36  int16_t last_offs;
39 };
40 
43  const char *name;
44  const char *description;
45  const char *unit;
46  unsigned int num_values;
47  int32_t default_value;
48 };
49 
53  const char *group_name_prefix;
55  const char *group_description;
57  int class_id;
59  const unsigned int num_items;
62 };
63 
67  struct llist_head list;
71  unsigned int idx;
73  char *name;
75  struct osmo_stat_item *items[0];
76 };
77 
79  void *ctx,
80  const struct osmo_stat_item_group_desc *desc,
81  unsigned int idx);
82 
83 static inline void osmo_stat_item_group_udp_idx(
84  struct osmo_stat_item_group *grp, unsigned int idx)
85 {
86  grp->idx = idx;
87 }
88 struct osmo_stat_item *osmo_stat_item_group_get_item(struct osmo_stat_item_group *grp, unsigned int idx);
89 void osmo_stat_item_group_set_name(struct osmo_stat_item_group *statg, const char *name);
91 
92 void osmo_stat_item_inc(struct osmo_stat_item *item, int32_t value);
93 void osmo_stat_item_dec(struct osmo_stat_item *item, int32_t value);
94 void osmo_stat_item_set(struct osmo_stat_item *item, int32_t value);
95 
96 int osmo_stat_item_init(void *tall_ctx);
97 
99  const char *name, const unsigned int idx);
100 
102  const struct osmo_stat_item_group *statg, const char *name);
103 
104 int osmo_stat_item_get_next(const struct osmo_stat_item *item, int32_t *next_id, int32_t *value);
105 
107 static int32_t osmo_stat_item_get_last(const struct osmo_stat_item *item);
108 
109 int osmo_stat_item_discard(const struct osmo_stat_item *item, int32_t *next_id);
110 
111 int osmo_stat_item_discard_all(int32_t *next_id)
112  OSMO_DEPRECATED("Use osmo_stat_item_discard with item-specific next_id instead");
113 
115  struct osmo_stat_item_group *, struct osmo_stat_item *, void *);
116 
117 typedef int (*osmo_stat_item_group_handler_t)(struct osmo_stat_item_group *, void *);
118 
120  osmo_stat_item_handler_t handle_item, void *data);
121 
123 
124 static inline int32_t osmo_stat_item_get_last(const struct osmo_stat_item *item)
125 {
126  return item->values[item->last_offs].value;
127 }
128 
129 void osmo_stat_item_reset(struct osmo_stat_item *item);
131 
Description of a statistics item group.
Definition: stat_item.h:51
#define OSMO_DEPRECATED(text)
Set the deprecated attribute with a message.
Definition: defs.h:41
bool stats_last_sent_was_max
Definition: stat_item.h:34
int osmo_stat_item_get_next(const struct osmo_stat_item *item, int32_t *next_id, int32_t *value)
Retrieve the next value from the osmo_stat_item object.
Definition: stat_item.c:250
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:220
const struct osmo_stat_item_group_desc * desc
Pointer to the counter group class.
Definition: stat_item.h:69
int class_id
The class to which this group belongs.
Definition: stat_item.h:57
const char * group_description
The human-readable description of the group.
Definition: stat_item.h:55
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:96
unsigned int num_values
number of values to store in FIFO
Definition: stat_item.h:46
int osmo_stat_item_discard(const struct osmo_stat_item *item, int32_t *next_id)
Skip/discard all values of this item and update next_id accordingly.
Definition: stat_item.c:292
int32_t default_value
default value
Definition: stat_item.h:47
void osmo_stat_item_group_reset(struct osmo_stat_item_group *statg)
Reset all osmo stat items in a group.
Definition: stat_item.c:418
int32_t value
actual value
Definition: stat_item.h:20
struct osmo_stat_item_value values[0]
value FIFO
Definition: stat_item.h:38
General definitions that are meant to be included from header files.
const char * description
description of the item
Definition: stat_item.h:44
char name[32]
source file name
Definition: gsmtap.h:131
int osmo_stat_item_init(void *tall_ctx)
Initialize the stat item module.
Definition: stat_item.c:309
const char * unit
unit of a value
Definition: stat_item.h:45
int osmo_stat_item_discard_all(int32_t *next_id) OSMO_DEPRECATED("Use osmo_stat_item_discard with item-specific next_id instead")
Skip all values of all items and update next_id accordingly.
Definition: stat_item.c:301
const unsigned int num_items
The number of values in this group (size of item_desc)
Definition: stat_item.h:59
unsigned int idx
The index of this value group within its class.
Definition: stat_item.h:71
int32_t id
identifier of value
Definition: stat_item.h:19
int32_t stats_next_id
Definition: stat_item.h:30
const struct osmo_stat_item_desc * desc
back-reference to the item description
Definition: stat_item.h:26
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:320
struct llist_head list
Linked list of all value groups in the system.
Definition: stat_item.h:67
const char * group_name_prefix
The prefix to the name of all values in this group.
Definition: stat_item.h:53
struct osmo_stat_item * items[0]
Actual counter structures below.
Definition: stat_item.h:75
uint8_t data[0]
Simple doubly linked list implementation.
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:384
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:208
(double) linked list header structure
Definition: linuxlist.h:46
int16_t last_offs
the index of the last value written to the FIFO
Definition: stat_item.h:36
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:196
struct osmo_stat_item * osmo_stat_item_group_get_item(struct osmo_stat_item_group *grp, unsigned int idx)
Get statistics item from group, identified by index idx.
Definition: stat_item.c:175
int(* osmo_stat_item_group_handler_t)(struct osmo_stat_item_group *, void *)
Definition: stat_item.h:117
One instance of a counter group class.
Definition: stat_item.h:65
char * name
Optional string-based identifier to be used instead of index at report time.
Definition: stat_item.h:73
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:340
const char * name
name of the item
Definition: stat_item.h:43
data we keep for each actual item
Definition: stat_item.h:24
const struct osmo_stat_item_desc * item_desc
Pointer to array of value names, length as per num_items.
Definition: stat_item.h:61
int(* osmo_stat_item_handler_t)(struct osmo_stat_item_group *, struct osmo_stat_item *, void *)
Definition: stat_item.h:114
static int32_t osmo_stat_item_get_last(const struct osmo_stat_item *item)
Get the last (freshest) value.
Definition: stat_item.h:124
Individual entry in value FIFO.
Definition: stat_item.h:18
void osmo_stat_item_group_set_name(struct osmo_stat_item_group *statg, const char *name)
Set a name for the statistics item group to be used instead of index value at report time...
Definition: stat_item.c:185
static void osmo_stat_item_group_udp_idx(struct osmo_stat_item_group *grp, unsigned int idx)
Definition: stat_item.h:83
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:364
void osmo_stat_item_reset(struct osmo_stat_item *item)
Remove all values of a stat item.
Definition: stat_item.c:402
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:164
Statistics item description.
Definition: stat_item.h:42