oveRTOS C API
Embedded RTOS framework — build system, configuration, and portable C API
Loading...
Searching...
No Matches
thread_state_stats.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2026 Kamil Lulko <kamil.lulko@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-3.0-or-later
5 *
6 * This file is part of oveRTOS.
7 */
8
21#ifndef OVE_THREAD_STATE_STATS_H
22#define OVE_THREAD_STATE_STATS_H
23
24#include <stdint.h>
25
26#ifdef __cplusplus
27extern "C" {
28#endif
29
30#ifdef CONFIG_OVE_THREAD_STATE_STATS
31
32#define OVE_STATE_COUNT 5
33
41 uint64_t cumul_us[OVE_STATE_COUNT];
42 uint64_t last_ts_us;
44};
45
48
49static inline void ove_state_track_init(struct ove_state_tracker *st, int initial_state)
50{
51 for (int i = 0; i < OVE_STATE_COUNT; i++)
52 st->cumul_us[i] = 0;
54 st->cur_state = initial_state;
55}
56
57static inline void ove_state_track_transition(struct ove_state_tracker *st, int new_state)
58{
59 uint64_t now = ove_state_stats_now_us();
60 int idx = st->cur_state;
61 if (idx >= 0 && idx < OVE_STATE_COUNT)
62 st->cumul_us[idx] += now - st->last_ts_us;
63 st->last_ts_us = now;
64 st->cur_state = new_state;
65}
66
67#else /* !CONFIG_OVE_THREAD_STATE_STATS */
68
69struct ove_state_tracker {
70 char _dummy;
71};
72#define ove_state_track_init(st, s) ((void)0)
73#define ove_state_track_transition(st, s) ((void)0)
74
75#endif /* CONFIG_OVE_THREAD_STATE_STATS */
76
77#ifdef __cplusplus
78}
79#endif
80
81#endif /* OVE_THREAD_STATE_STATS_H */
Per-thread state-occupancy tracker.
Definition thread_state_stats.h:40
uint64_t last_ts_us
Definition thread_state_stats.h:42
uint64_t cumul_us[OVE_STATE_COUNT]
Definition thread_state_stats.h:41
int cur_state
Definition thread_state_stats.h:43
uint64_t ove_state_stats_now_us(void)