Zephyr API Documentation  2.7.0-rc2
A Scalable Open Source RTOS
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
167#define STATS_CLEAR(group__, var__) \
168 ((group__).var__ = 0)
169
170#define STATS_SIZE_16 (sizeof(uint16_t))
171#define STATS_SIZE_32 (sizeof(uint32_t))
172#define STATS_SIZE_64 (sizeof(uint64_t))
173
174#define STATS_SIZE_INIT_PARMS(group__, size__) \
175 (size__), \
176 ((sizeof(group__)) - sizeof(struct stats_hdr)) / (size__)
177
192#define STATS_INIT_AND_REG(group__, size__, name__) \
193 stats_init_and_reg( \
194 &(group__).s_hdr, \
195 (size__), \
196 (sizeof(group__) - sizeof(struct stats_hdr)) / (size__), \
197 STATS_NAME_INIT_PARMS(group__), \
198 (name__))
199
217void stats_init(struct stats_hdr *shdr, uint8_t size, uint16_t cnt,
218 const struct stats_name_map *map, uint16_t map_cnt);
219
232int stats_register(const char *name, struct stats_hdr *shdr);
233
258int stats_init_and_reg(struct stats_hdr *hdr, uint8_t size, uint16_t cnt,
259 const struct stats_name_map *map, uint16_t map_cnt,
260 const char *name);
261
267void stats_reset(struct stats_hdr *shdr);
268
281typedef int stats_walk_fn(struct stats_hdr *hdr, void *arg,
282 const char *name, uint16_t off);
283
294int stats_walk(struct stats_hdr *hdr, stats_walk_fn *walk_cb, void *arg);
295
305typedef int stats_group_walk_fn(struct stats_hdr *hdr, void *arg);
306
316int stats_group_walk(stats_group_walk_fn *walk_cb, void *arg);
317
327struct stats_hdr *stats_group_get_next(const struct stats_hdr *cur);
328
337struct stats_hdr *stats_group_find(const char *name);
338
339#else /* CONFIG_STATS */
340
341#define STATS_SECT_START(group__) \
342 STATS_SECT_DECL(group__) {
343
344#define STATS_SECT_ENTRY(var__)
345#define STATS_SECT_ENTRY16(var__)
346#define STATS_SECT_ENTRY32(var__)
347#define STATS_SECT_ENTRY64(var__)
348#define STATS_RESET(var__)
349#define STATS_SIZE_INIT_PARMS(group__, size__)
350#define STATS_INCN(group__, var__, n__)
351#define STATS_INC(group__, var__)
352#define STATS_CLEAR(group__, var__)
353#define STATS_INIT_AND_REG(group__, size__, name__) (0)
354
355#endif /* !CONFIG_STATS */
356
357#ifdef CONFIG_STATS_NAMES
358
359#define STATS_NAME_MAP_NAME(sectname__) stats_map_ ## sectname__
360
361#define STATS_NAME_START(sectname__) \
362 const struct stats_name_map STATS_NAME_MAP_NAME(sectname__)[] = {
363
364#define STATS_NAME(sectname__, entry__) \
365 { offsetof(STATS_SECT_DECL(sectname__), entry__), #entry__ },
366
367#define STATS_NAME_END(sectname__) }
368
369#define STATS_NAME_INIT_PARMS(name__) \
370 &(STATS_NAME_MAP_NAME(name__)[0]), \
371 (sizeof(STATS_NAME_MAP_NAME(name__)) / sizeof(struct stats_name_map))
372
373#else /* CONFIG_STATS_NAMES */
374
375#define STATS_NAME_START(name__)
376#define STATS_NAME(name__, entry__)
377#define STATS_NAME_END(name__)
378#define STATS_NAME_INIT_PARMS(name__) NULL, 0
379
380#endif /* CONFIG_STATS_NAMES */
381
382#ifdef __cplusplus
383}
384#endif
385
386#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:58
__UINT16_TYPE__ uint16_t
Definition: stdint.h:59
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
static int cur
Definition: timeout_order.c:16