Zephyr API Documentation 4.4.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
stats.h
Go to the documentation of this file.
1/*
2 * Copyright Runtime.io 2018. All rights reserved.
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
12
13#ifndef ZEPHYR_INCLUDE_STATS_STATS_H_
14#define ZEPHYR_INCLUDE_STATS_STATS_H_
15
16#include <stddef.h>
17#include <zephyr/types.h>
18
19#ifdef __cplusplus
20extern "C" {
21#endif
22
118
127 uint16_t snm_off;
128 const char *snm_name;
130} __attribute__((packed));
131
139struct stats_hdr {
141 const char *s_name;
142 uint8_t s_size;
143 uint16_t s_cnt;
144 uint8_t s_pad1;
145#ifdef CONFIG_STATS_NAMES
146 const struct stats_name_map *s_map;
147 int s_map_cnt;
148#endif
149 struct stats_hdr *s_next;
151};
152
157
163#define STATS_SECT_DECL(group__) \
164 struct stats_ ## group__
165
169#define STATS_SECT_END }
170
171/* The following macros depend on whether CONFIG_STATS is defined. If it is
172 * not defined, then invocations of these macros get compiled out.
173 */
174#if defined(CONFIG_STATS) || defined(__DOXYGEN__)
175
181#define STATS_SECT_START(group__) \
182 STATS_SECT_DECL(group__) { \
183 struct stats_hdr s_hdr;
184
190#define STATS_SECT_ENTRY(var__) uint32_t var__;
191
197#define STATS_SECT_ENTRY16(var__) uint16_t var__;
198
204#define STATS_SECT_ENTRY32(var__) uint32_t var__;
205
211#define STATS_SECT_ENTRY64(var__) uint64_t var__;
212
216#define STATS_SIZE_16 (sizeof(uint16_t))
220#define STATS_SIZE_32 (sizeof(uint32_t))
224#define STATS_SIZE_64 (sizeof(uint64_t))
225
227
232
243#define STATS_INCN(group__, var__, n__) \
244 ((group__).var__ += (n__))
245
255#define STATS_INC(group__, var__) \
256 STATS_INCN(group__, var__, 1)
257
268#define STATS_SET(group__, var__, n__) \
269 ((group__).var__ = (n__))
270
280#define STATS_CLEAR(group__, var__) \
281 ((group__).var__ = 0)
282
284
286#define STATS_SIZE_INIT_PARMS(group__, size__) \
287 (size__), \
288 ((sizeof(group__)) - sizeof(struct stats_hdr)) / (size__)
290
295
311#define STATS_INIT_AND_REG(group__, size__, name__) \
312 stats_init_and_reg( \
313 &(group__).s_hdr, \
314 (size__), \
315 (sizeof(group__) - sizeof(struct stats_hdr)) / (size__), \
316 STATS_NAME_INIT_PARMS(group__), \
317 (name__))
318
333void stats_init(struct stats_hdr *shdr, uint8_t size, uint16_t cnt,
334 const struct stats_name_map *map, uint16_t map_cnt);
335
349int stats_register(const char *name, struct stats_hdr *shdr);
350
376int stats_init_and_reg(struct stats_hdr *hdr, uint8_t size, uint16_t cnt,
377 const struct stats_name_map *map, uint16_t map_cnt,
378 const char *name);
379
385void stats_reset(struct stats_hdr *shdr);
386
388
393
406typedef int stats_walk_fn(struct stats_hdr *hdr, void *arg,
407 const char *name, uint16_t off);
408
419int stats_walk(struct stats_hdr *hdr, stats_walk_fn *walk_cb, void *arg);
420
430typedef int stats_group_walk_fn(struct stats_hdr *hdr, void *arg);
431
441int stats_group_walk(stats_group_walk_fn *walk_cb, void *arg);
442
452struct stats_hdr *stats_group_get_next(const struct stats_hdr *cur);
453
462struct stats_hdr *stats_group_find(const char *name);
463
465
466#else /* CONFIG_STATS */
467
468#define STATS_SECT_START(group__) \
469 STATS_SECT_DECL(group__) {
470
471#define STATS_SECT_ENTRY(var__)
472#define STATS_SECT_ENTRY16(var__)
473#define STATS_SECT_ENTRY32(var__)
474#define STATS_SECT_ENTRY64(var__)
475#define STATS_RESET(var__)
476#define STATS_SIZE_INIT_PARMS(group__, size__)
477#define STATS_INCN(group__, var__, n__)
478#define STATS_INC(group__, var__)
479#define STATS_SET(group__, var__, n__)
480#define STATS_CLEAR(group__, var__)
481#define STATS_INIT_AND_REG(group__, size__, name__) (0)
482
483#endif /* CONFIG_STATS || __DOXYGEN__ */
484
485#if defined(CONFIG_STATS_NAMES) || defined(__DOXYGEN__)
486
488#define STATS_NAME_MAP_NAME(sectname__) stats_map_ ## sectname__
490
501
510#define STATS_NAME_START(sectname__) \
511 static const struct stats_name_map STATS_NAME_MAP_NAME(sectname__)[] = {
512
519#define STATS_NAME(sectname__, entry__) \
520 { offsetof(STATS_SECT_DECL(sectname__), entry__), #entry__ },
521
527#define STATS_NAME_END(sectname__) }
528
538#define STATS_NAME_INIT_PARMS(name__) \
539 &(STATS_NAME_MAP_NAME(name__)[0]), \
540 (sizeof(STATS_NAME_MAP_NAME(name__)) / sizeof(struct stats_name_map))
541
543
544#else /* CONFIG_STATS_NAMES */
545
546#define STATS_NAME_START(name__)
547#define STATS_NAME(name__, entry__)
548#define STATS_NAME_END(name__)
549#define STATS_NAME_INIT_PARMS(name__) NULL, 0
550
551#endif /* CONFIG_STATS_NAMES */
552
556
557#ifdef __cplusplus
558}
559#endif
560
561#endif /* ZEPHYR_INCLUDE_STATS_STATS_H_ */
int stats_register(const char *name, struct stats_hdr *shdr)
Registers a statistics group to be managed.
struct stats_hdr * stats_group_get_next(const struct stats_hdr *cur)
Retrieves the next registered statistics group.
int stats_group_walk(stats_group_walk_fn *walk_cb, void *arg)
Applies a function every registered statistics group.
int stats_group_walk_fn(struct stats_hdr *hdr, void *arg)
Function that gets applied to every registered stats group.
Definition stats.h:430
void stats_init(struct stats_hdr *shdr, uint8_t size, uint16_t cnt, const struct stats_name_map *map, uint16_t map_cnt)
Initializes a statistics group.
int stats_init_and_reg(struct stats_hdr *hdr, uint8_t size, uint16_t cnt, const struct stats_name_map *map, uint16_t map_cnt, const char *name)
Initializes and registers a statistics group.
struct stats_hdr * stats_group_find(const char *name)
Retrieves the statistics group with the specified name.
int stats_walk_fn(struct stats_hdr *hdr, void *arg, const char *name, uint16_t off)
Function that gets applied to every stat entry during a walk.
Definition stats.h:406
void stats_reset(struct stats_hdr *shdr)
Zeroes the specified statistics group.
int stats_walk(struct stats_hdr *hdr, stats_walk_fn *walk_cb, void *arg)
Applies a function to every stat entry in a group.
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
__UINT16_TYPE__ uint16_t
Definition stdint.h:89
Store metadata for one statistics group.
Definition stats.h:139
Describe one generated statistic entry name.
Definition stats.h:125