Zephyr API Documentation  3.6.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
51#ifndef ZEPHYR_INCLUDE_STATS_STATS_H_
52#define ZEPHYR_INCLUDE_STATS_STATS_H_
53
54#include <stddef.h>
55#include <zephyr/types.h>
56
57#ifdef __cplusplus
58extern "C" {
59#endif
60
63 const char *snm_name;
64} __attribute__((packed));
65
66struct stats_hdr {
67 const char *s_name;
71#ifdef CONFIG_STATS_NAMES
72 const struct stats_name_map *s_map;
73 int s_map_cnt;
74#endif
76};
77
83#define STATS_SECT_DECL(group__) \
84 struct stats_ ## group__
85
89#define STATS_SECT_END }
90
91/* The following macros depend on whether CONFIG_STATS is defined. If it is
92 * not defined, then invocations of these macros get compiled out.
93 */
94#ifdef CONFIG_STATS
95
101#define STATS_SECT_START(group__) \
102 STATS_SECT_DECL(group__) { \
103 struct stats_hdr s_hdr;
104
110#define STATS_SECT_ENTRY(var__) uint32_t var__;
111
117#define STATS_SECT_ENTRY16(var__) uint16_t var__;
118
124#define STATS_SECT_ENTRY32(var__) uint32_t var__;
125
131#define STATS_SECT_ENTRY64(var__) uint64_t var__;
132
143#define STATS_INCN(group__, var__, n__) \
144 ((group__).var__ += (n__))
145
155#define STATS_INC(group__, var__) \
156 STATS_INCN(group__, var__, 1)
157
168#define STATS_SET(group__, var__, n__) \
169 ((group__).var__ = (n__))
170
180#define STATS_CLEAR(group__, var__) \
181 ((group__).var__ = 0)
182
183#define STATS_SIZE_16 (sizeof(uint16_t))
184#define STATS_SIZE_32 (sizeof(uint32_t))
185#define STATS_SIZE_64 (sizeof(uint64_t))
186
187#define STATS_SIZE_INIT_PARMS(group__, size__) \
188 (size__), \
189 ((sizeof(group__)) - sizeof(struct stats_hdr)) / (size__)
190
205#define STATS_INIT_AND_REG(group__, size__, name__) \
206 stats_init_and_reg( \
207 &(group__).s_hdr, \
208 (size__), \
209 (sizeof(group__) - sizeof(struct stats_hdr)) / (size__), \
210 STATS_NAME_INIT_PARMS(group__), \
211 (name__))
212
230void stats_init(struct stats_hdr *shdr, uint8_t size, uint16_t cnt,
231 const struct stats_name_map *map, uint16_t map_cnt);
232
245int stats_register(const char *name, struct stats_hdr *shdr);
246
271int stats_init_and_reg(struct stats_hdr *hdr, uint8_t size, uint16_t cnt,
272 const struct stats_name_map *map, uint16_t map_cnt,
273 const char *name);
274
280void stats_reset(struct stats_hdr *shdr);
281
294typedef int stats_walk_fn(struct stats_hdr *hdr, void *arg,
295 const char *name, uint16_t off);
296
307int stats_walk(struct stats_hdr *hdr, stats_walk_fn *walk_cb, void *arg);
308
318typedef int stats_group_walk_fn(struct stats_hdr *hdr, void *arg);
319
329int stats_group_walk(stats_group_walk_fn *walk_cb, void *arg);
330
340struct stats_hdr *stats_group_get_next(const struct stats_hdr *cur);
341
350struct stats_hdr *stats_group_find(const char *name);
351
352#else /* CONFIG_STATS */
353
354#define STATS_SECT_START(group__) \
355 STATS_SECT_DECL(group__) {
356
357#define STATS_SECT_ENTRY(var__)
358#define STATS_SECT_ENTRY16(var__)
359#define STATS_SECT_ENTRY32(var__)
360#define STATS_SECT_ENTRY64(var__)
361#define STATS_RESET(var__)
362#define STATS_SIZE_INIT_PARMS(group__, size__)
363#define STATS_INCN(group__, var__, n__)
364#define STATS_INC(group__, var__)
365#define STATS_SET(group__, var__)
366#define STATS_CLEAR(group__, var__)
367#define STATS_INIT_AND_REG(group__, size__, name__) (0)
368
369#endif /* !CONFIG_STATS */
370
371#ifdef CONFIG_STATS_NAMES
372
373#define STATS_NAME_MAP_NAME(sectname__) stats_map_ ## sectname__
374
375#define STATS_NAME_START(sectname__) \
376 static const struct stats_name_map STATS_NAME_MAP_NAME(sectname__)[] = {
377
378#define STATS_NAME(sectname__, entry__) \
379 { offsetof(STATS_SECT_DECL(sectname__), entry__), #entry__ },
380
381#define STATS_NAME_END(sectname__) }
382
383#define STATS_NAME_INIT_PARMS(name__) \
384 &(STATS_NAME_MAP_NAME(name__)[0]), \
385 (sizeof(STATS_NAME_MAP_NAME(name__)) / sizeof(struct stats_name_map))
386
387#else /* CONFIG_STATS_NAMES */
388
389#define STATS_NAME_START(name__)
390#define STATS_NAME(name__, entry__)
391#define STATS_NAME_END(name__)
392#define STATS_NAME_INIT_PARMS(name__) NULL, 0
393
394#endif /* CONFIG_STATS_NAMES */
395
396#ifdef __cplusplus
397}
398#endif
399
400#endif /* ZEPHYR_INCLUDE_STATS_STATS_H_ */
irp nz macro MOVR cc s mov cc s endm endr irp aw macro LDR aa off
Definition: asm-macro-32-bit-gnu.h:17
__UINT8_TYPE__ uint8_t
Definition: stdint.h:88
__UINT16_TYPE__ uint16_t
Definition: stdint.h:89
Definition: stats.h:66
uint8_t s_size
Definition: stats.h:68
uint16_t s_cnt
Definition: stats.h:69
const char * s_name
Definition: stats.h:67
uint8_t s_pad1
Definition: stats.h:70
struct stats_hdr * s_next
Definition: stats.h:75
Definition: stats.h:61
const char * snm_name
Definition: stats.h:63
uint16_t snm_off
Definition: stats.h:62