libosmocore 1.13.1.1-afb4 Osmocom core library

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 struct osmo_stat_item;
20
22 struct osmo_stat_item_desc {
23 const char *name;
24 const char *description;
25 const char *unit;
26 unsigned int num_values;
27 int32_t default_value;
28};
29
31 struct osmo_stat_item_group_desc {
33 const char *group_name_prefix;
35 const char *group_description;
37 int class_id;
39 const unsigned int num_items;
41 const struct osmo_stat_item_desc *item_desc;
42};
43
45 struct osmo_stat_item_group {
47 struct llist_head list;
49 const struct osmo_stat_item_group_desc *desc;
51 unsigned int idx;
53 char *name;
55 struct osmo_stat_item *items[0];
56};
57
58 struct osmo_stat_item_group *osmo_stat_item_group_alloc(
59 void *ctx,
60 const struct osmo_stat_item_group_desc *group_desc,
61 unsigned int idx);
62
63 static inline void osmo_stat_item_group_udp_idx(
64 struct osmo_stat_item_group *grp, unsigned int idx)
65{
66 grp->idx = idx;
67}
68 struct osmo_stat_item *osmo_stat_item_group_get_item(struct osmo_stat_item_group *grp, unsigned int idx);
69 void osmo_stat_item_group_set_name(struct osmo_stat_item_group *statg, const char *name);
70 void osmo_stat_item_group_free(struct osmo_stat_item_group *statg);
71
72 void osmo_stat_item_inc(struct osmo_stat_item *item, int32_t value);
73 void osmo_stat_item_dec(struct osmo_stat_item *item, int32_t value);
74 void osmo_stat_item_set(struct osmo_stat_item *item, int32_t value);
75
76 int osmo_stat_item_init(void *tall_ctx);
77
78 struct osmo_stat_item_group *osmo_stat_item_get_group_by_name_idx(
79 const char *name, const unsigned int idx);
80 struct osmo_stat_item_group *osmo_stat_item_get_group_by_name_idxname(const char *group_name, const char *idx_name);
81
82 const struct osmo_stat_item *osmo_stat_item_get_by_name(
83 const struct osmo_stat_item_group *statg, const char *name);
84
85int32_t osmo_stat_item_get_last(const struct osmo_stat_item *item);
86
87 void osmo_stat_item_flush(struct osmo_stat_item *item);
88
89 typedef int (*osmo_stat_item_handler_t)(
90 struct osmo_stat_item_group *, struct osmo_stat_item *, void *);
91
92 typedef int (*osmo_stat_item_group_handler_t)(struct osmo_stat_item_group *, void *);
93
94 int osmo_stat_item_for_each_item(struct osmo_stat_item_group *statg,
95 osmo_stat_item_handler_t handle_item, void *data);
96
97 int osmo_stat_item_for_each_group(osmo_stat_item_group_handler_t handle_group, void *data);
98
99 void osmo_stat_item_reset(struct osmo_stat_item *item);
100 void osmo_stat_item_group_reset(struct osmo_stat_item_group *statg);
101
102 const struct osmo_stat_item_desc *osmo_stat_item_get_desc(struct osmo_stat_item *item);
103
104/* DEPRECATION: up until libosmocore 1.5.1, this API also defined
105 * - struct osmo_stat_item_value
106 * - osmo_stat_item_get_next()
107 * - osmo_stat_item_discard()
108 * - osmo_stat_item_discard_all()
109 * Despite our principle of never breaking API compatibility, we have decided to remove these, because there are no
110 * known users. These items were never practically used/usable outside of libosmocore since the generic stats reporter
111 * (stats.c) was introduced.
112 * We also decided to make struct osmo_stat_item opaque to allow future changes of the struct without API breakage.
113 */
114
defs.h
General definitions that are meant to be included from header files.
name
const char * name
data
uint8_t data[0]
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:226
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:371
osmo_stat_item_get_desc
const struct osmo_stat_item_desc * osmo_stat_item_get_desc(struct osmo_stat_item *item)
Return the description for an osmo_stat_item.
Definition: stat_item.c:459
osmo_stat_item_flush
void osmo_stat_item_flush(struct osmo_stat_item *item)
Indicate that a reporting period has elapsed, and prepare the stat item for a new period of collectin...
Definition: stat_item.c:303
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:261
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:272
osmo_stat_item_get_group_by_name_idxname
struct osmo_stat_item_group * osmo_stat_item_get_group_by_name_idxname(const char *group_name, const char *idx_name)
Search for item group based on group name and index's name.
Definition: stat_item.c:351
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:395
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:331
osmo_stat_item_get_last
int32_t osmo_stat_item_get_last(const struct osmo_stat_item *item)
Get the last (freshest) value.
Definition: stat_item.c:430
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:448
osmo_stat_item_init
int osmo_stat_item_init(void *tall_ctx)
Initialize the stat item module.
Definition: stat_item.c:320
osmo_stat_item_group_alloc
struct osmo_stat_item_group * osmo_stat_item_group_alloc(void *ctx, const struct osmo_stat_item_group_desc *group_desc, unsigned int idx)
Allocate a new group of counters according to description.
Definition: stat_item.c:180
osmo_stat_item_group_handler_t
int(* osmo_stat_item_group_handler_t)(struct osmo_stat_item_group *, void *)
Definition: stat_item.h:92
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:89
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:283
osmo_stat_item_group_get_item
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:240
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:438
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:63
osmo_stat_item_group_set_name
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:250
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:415
linuxlist.h
Simple doubly linked list implementation.
llist_head
(double) linked list header structure
Definition: linuxlist.h:46
osmo_stat_item_desc
Statistics item description.
Definition: stat_item.h:22
osmo_stat_item_desc::description
const char * description
description of the item
Definition: stat_item.h:24
osmo_stat_item_desc::name
const char * name
name of the item
Definition: stat_item.h:23
osmo_stat_item_desc::default_value
int32_t default_value
default value
Definition: stat_item.h:27
osmo_stat_item_desc::num_values
unsigned int num_values
DEPRECATED, this value is ignored after libosmocore version 1.5.1.
Definition: stat_item.h:26
osmo_stat_item_desc::unit
const char * unit
unit of a value
Definition: stat_item.h:25
osmo_stat_item_group_desc
Description of a statistics item group.
Definition: stat_item.h:31
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:33
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:41
osmo_stat_item_group_desc::group_description
const char * group_description
The human-readable description of the group.
Definition: stat_item.h:35
osmo_stat_item_group_desc::class_id
int class_id
The class to which this group belongs.
Definition: stat_item.h:37
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:39
osmo_stat_item_group
One instance of a counter group class.
Definition: stat_item.h:45
osmo_stat_item_group::desc
const struct osmo_stat_item_group_desc * desc
Pointer to the counter group class.
Definition: stat_item.h:49
osmo_stat_item_group::items
struct osmo_stat_item * items[0]
Actual counter structures below.
Definition: stat_item.h:55
osmo_stat_item_group::name
char * name
Optional string-based identifier to be used instead of index at report time.
Definition: stat_item.h:53
osmo_stat_item_group::list
struct llist_head list
Linked list of all value groups in the system.
Definition: stat_item.h:47
osmo_stat_item_group::idx
unsigned int idx
The index of this value group within its class.
Definition: stat_item.h:51
osmo_stat_item
data we keep for each actual item
Definition: stat_item_internal.h:23
osmo_stat_item::value
struct osmo_stat_item_period value
Current reporting period / current value.
Definition: stat_item_internal.h:28