The FreeRADIUS server $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Loading...
Searching...
No Matches
stats.h
Go to the documentation of this file.
1#pragma once
2/*
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
16 */
17
18/**
19 * $Id: c1e479c383495da6bd4f59009d93c09298a87de0 $
20 *
21 * @file lib/util/stats.h
22 * @brief Structures and functions for statistics.
23 *
24 * @copyright 2022 Network RADIUS SAS (legal@networkradius.com)
25 */
26RCSIDH(stats_h, "$Id: c1e479c383495da6bd4f59009d93c09298a87de0 $")
27
28#include <freeradius-devel/util/pair.h>
29
30#ifdef __cplusplus
31extern "C" {
32#endif
33
34/** Link a struct entry to an autoloaded #fr_dict_attr_t
35 *
36 */
37typedef struct {
38 fr_dict_attr_t const **da_p; //!< point to the autoload definition of the DA for this field
39 fr_type_t type; //!< cached for locality and simplicity
40 size_t offset; //!< from the start of the struct
41 size_t size; //!< size of this field
43
44typedef struct {
45 char const *name; //!< name of the stats structure
46 fr_dict_attr_t const **root_p; //!< point to the autoload definition of the DA for this structure
47 char const *mib; //!< MIB root
48 size_t size; //!< overall size of the structure
49 size_t num_elements; //!< number of elements in the table. Note no "NULL" terminator
50 fr_stats_link_entry_t entry[]; //!< the field entries, in offset order
52
53/** Common header for all statistics instances
54 *
55 * def pointer to the linking definition of the structure for this instance
56 *
57 * @todo - if we need additional tracking data (rb trees, dlists, etc.), they can go here.
58 */
59#define STATS_HEADER_COMMON \
60 fr_stats_link_t const *def
61
62/** Generic statistics structure
63 *
64 */
65typedef struct {
66 STATS_HEADER_COMMON; //!< common header
67
68 uint8_t stats[]; //!< generic statistics data
70
71/** Iterator for a statistics structure.
72 *
73 * This is used internally, and there's no real need for code outside of the statistics library to use it.
74 */
75typedef struct {
77 unsigned int current;
79
80
81/** Macro to define a typedef for a particular instance of statistics
82 *
83 * Defines fr_stats_name_instance_t which contains an instance of the statistics for fr_stats_name_t, and
84 * which points to the linking structure fr_stats_link_name_t.
85 *
86 * Note that nothing needs to refer to the base statistics structure: fr_stats_name_t. All of that is
87 * wrapped in an instance definition.
88 *
89 * This is used internally, and there's no real need for code outside of the statistics library to use it.
90 */
91#define FR_STATS_TYPEDEF(_name) \
92 typedef struct { \
93 STATS_HEADER_COMMON; \
94 fr_stats_ ## _name ## _t stats; \
95 } fr_stats_ ## _name ## _instance_t
96
97/** Macro used when referencing a linking structure
98 *
99 * .def = FR_STATS_LINK_NAME(radius_auth_serv),
100 *
101 * This is used internally, and there's no real need for code outside of the statistics library to use it.
102 */
103#define FR_STATS_LINK_NAME(_name) fr_stats_link_ ## _name ## _t
104
105/** Macro used when declaring a variable which contains an instance of the statistics
106 *
107 * Defines "fr_stats_name_instance_t var", which can be used in a structure
108 *
109 * Code which needs to use some statistics can use this macro to declare a variable which contains stats for
110 * the local module / etc.
111 */
112#define FR_STATS_ENTRY_DECL(_name, _var) fr_stats_ ## _name ## _instance_t _var
113
114/** Macro used when initializing a variable which contains an instance of the statistics
115 *
116 * var = .... initializer for the stats instance ...
117 *
118 * Code which needs to use some statistics can use this macro to initialize a variable which contains stats
119 * for the local module / etc.
120 */
121#define FR_STATS_ENTRY_INIT(_name, _var, _mib) \
122 _var = (fr_stats_ ## _name ## _instance_t) { \
123 .def = fr_stats_link_ ## _name ## _t, \
124 .mib = _mib, \
125 fr_stats_ ## _name ## _t stats = {}, \
126 }
127
128
129/** Macro used to increment one field in the statistics structure
130 *
131 * Code which needs to update some statistics can use this macro to increment a variable which contains
132 * stats for the local module / etc.
133 */
134#define FR_STATS_INC(_var, _field) ((_var)->stats.(_field))++
135
136/** Macro used to reference a field in the statistics structure
137 *
138 * Code which needs to mangle a field of the statistics can use this macro to get the correct field name.
139 */
140#define FR_STATS_FIELD(_var, _field) (_var)->stats.(_field)
141
142int fr_stats_to_pairs(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_stats_instance_t const *in) CC_HINT(nonnull);
143int fr_stats_from_pairs(TALLOC_CTX *ctx, fr_stats_instance_t *out, fr_pair_list_t const *list) CC_HINT(nonnull);
146
148bool fr_stats_iter_next(fr_stats_iter_t *iter) CC_HINT(nonnull);
149int fr_stats_iter_to_value_box(TALLOC_CTX *ctx, fr_value_box_t **out, fr_stats_iter_t *iter) CC_HINT(nonnull);
150int fr_stats_index_to_value_box(TALLOC_CTX *ctx, fr_value_box_t **out,
151 fr_stats_instance_t const *in, unsigned int index) CC_HINT(nonnull);
152int fr_stats_name_to_value_box(TALLOC_CTX *ctx, fr_value_box_t **out,
153 fr_stats_instance_t const *inst, char const *name) CC_HINT(nonnull);
154
155
156#ifdef __cplusplus
157}
158#endif
#define RCSIDH(h, id)
Definition build.h:488
static fr_slen_t in
Definition dict.h:884
fr_dict_attr_t const ** root_p
point to the autoload definition of the DA for this structure
Definition stats.h:46
size_t size
size of this field
Definition stats.h:41
int fr_stats_index_to_value_box(TALLOC_CTX *ctx, fr_value_box_t **out, fr_stats_instance_t const *in, unsigned int index)
Convert the statistic at an index to a value-box.
Definition stats.c:343
size_t size
overall size of the structure
Definition stats.h:48
int fr_stats_to_pairs(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_stats_instance_t const *in)
Convert a statistics structure to fr_pair_t.
Definition stats.c:33
fr_type_t type
cached for locality and simplicity
Definition stats.h:39
size_t offset
from the start of the struct
Definition stats.h:40
STATS_HEADER_COMMON
common header
Definition stats.h:66
int fr_stats_iter_to_value_box(TALLOC_CTX *ctx, fr_value_box_t **out, fr_stats_iter_t *iter)
Convert the statistic at the current iterator to a value-box.
Definition stats.c:416
bool fr_stats_iter_next(fr_stats_iter_t *iter)
Go to the next entry in a structure.
Definition stats.c:322
char const * name
name of the stats structure
Definition stats.h:45
void fr_stats_iter_init(fr_stats_instance_t const *in, fr_stats_iter_t *iter)
Initialize an iterator over a structure.
Definition stats.c:309
size_t num_elements
number of elements in the table. Note no "NULL" terminator
Definition stats.h:49
int fr_stats_from_pairs(TALLOC_CTX *ctx, fr_stats_instance_t *out, fr_pair_list_t const *list)
Convert a statistics structure to fr_pair_t.
Definition stats.c:114
int fr_stats_merge_instance(fr_stats_instance_t *out, fr_stats_instance_t const *in)
Public API for merging two statistics structures.
Definition stats.c:241
char const * mib
MIB root.
Definition stats.h:47
unsigned int current
Definition stats.h:77
int fr_stats_merge_value_box(fr_value_box_t *dst, fr_value_box_t const *src)
Public API for merging two value-boxes based on their enums.
Definition stats.c:260
fr_dict_attr_t const ** da_p
point to the autoload definition of the DA for this field
Definition stats.h:38
int fr_stats_name_to_value_box(TALLOC_CTX *ctx, fr_value_box_t **out, fr_stats_instance_t const *inst, char const *name)
Convert the statistic of a given name to a value-box.
Definition stats.c:435
fr_stats_instance_t const * inst
Definition stats.h:76
Generic statistics structure.
Definition stats.h:65
Iterator for a statistics structure.
Definition stats.h:75
Link a struct entry to an autoloaded fr_dict_attr_t.
Definition stats.h:37
fr_type_t
unsigned char uint8_t
static char const * name
eap_aka_sim_process_conf_t * inst
int nonnull(2, 5))
static size_t char ** out
Definition value.h:1025