ChibiOS 21.11.5
chstats.h
Go to the documentation of this file.
1/*
2 ChibiOS - Copyright (C) 2006-2026 Giovanni Di Sirio.
3
4 This file is part of ChibiOS.
5
6 ChibiOS is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation version 3 of the License.
9
10 ChibiOS is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17*/
18
19/**
20 * @file rt/include/chstats.h
21 * @brief Statistics module macros and structures.
22 *
23 * @addtogroup statistics
24 * @{
25 */
26
27#ifndef CHSTATS_H
28#define CHSTATS_H
29
30#if (CH_DBG_STATISTICS == TRUE) || defined(__DOXYGEN__)
31
32/*===========================================================================*/
33/* Module constants. */
34/*===========================================================================*/
35
36/*===========================================================================*/
37/* Module pre-compile time settings. */
38/*===========================================================================*/
39
40#if CH_CFG_USE_TM == FALSE
41#error "CH_DBG_STATISTICS requires CH_CFG_USE_TM"
42#endif
43
44/*===========================================================================*/
45/* Derived constants and error checks. */
46/*===========================================================================*/
47
48/*===========================================================================*/
49/* Module data structures and types. */
50/*===========================================================================*/
51
52/**
53 * @brief Type of a kernel statistics structure.
54 */
55typedef struct {
56 ucnt_t n_irq; /**< @brief Number of IRQs. */
57 ucnt_t n_ctxswc; /**< @brief Number of context switches. */
58 time_measurement_t m_crit_thd; /**< @brief Measurement of threads
59 critical zones duration. */
60 time_measurement_t m_crit_isr; /**< @brief Measurement of ISRs critical
61 zones duration. */
63
64/*===========================================================================*/
65/* Module macros. */
66/*===========================================================================*/
67
68/*===========================================================================*/
69/* External declarations. */
70/*===========================================================================*/
71
72#ifdef __cplusplus
73extern "C" {
74#endif
75 void __stats_init(void);
76 void __stats_increase_irq(void);
77 void __stats_ctxswc(thread_t *ntp, thread_t *otp);
82#ifdef __cplusplus
83}
84#endif
85
86/*===========================================================================*/
87/* Module inline functions. */
88/*===========================================================================*/
89
90/**
91 * @brief Statistics initialization.
92 * @note Internal use only.
93 *
94 * @param[out] ksp pointer to the @p kernel__stats_t structure
95 *
96 * @notapi
97 */
98static inline void __stats_object_init(kernel_stats_t *ksp) {
99
100 ksp->n_irq = (ucnt_t)0;
101 ksp->n_ctxswc = (ucnt_t)0;
104
105 /* The initialization code will stop the measurement on the final call
106 to chSysUnlock().*/
108}
109
110#else /* CH_DBG_STATISTICS == FALSE */
111
112/* Stub functions for when the statistics module is disabled. */
113#define __stats_increase_irq()
114#define __stats_ctxswc(old, new)
115#define __stats_start_measure_crit_thd()
116#define __stats_stop_measure_crit_thd()
117#define __stats_start_measure_crit_isr()
118#define __stats_stop_measure_crit_isr()
119
120#endif /* CH_DBG_STATISTICS == FALSE */
121
122#endif /* CHSTATS_H */
123
124/** @} */
uint32_t ucnt_t
Definition chearly.h:92
struct ch_thread thread_t
Type of a thread structure.
Definition chearly.h:132
void __stats_stop_measure_crit_isr(void)
Stops the measurement of an ISR critical zone.
Definition chstats.c:105
void __stats_init(void)
void __stats_ctxswc(thread_t *ntp, thread_t *otp)
Updates context switch related statistics.
Definition chstats.c:72
void __stats_start_measure_crit_isr(void)
Starts the measurement of an ISR critical zone.
Definition chstats.c:97
static void __stats_object_init(kernel_stats_t *ksp)
Statistics initialization.
Definition chstats.h:98
void __stats_increase_irq(void)
Increases the IRQ counter.
Definition chstats.c:59
void __stats_stop_measure_crit_thd(void)
Stops the measurement of a thread critical zone.
Definition chstats.c:89
void __stats_start_measure_crit_thd(void)
Starts the measurement of a thread critical zone.
Definition chstats.c:81
void chTMObjectInit(time_measurement_t *tmp)
Initializes a TimeMeasurement object.
Definition chtm.c:78
NOINLINE void chTMStartMeasurementX(time_measurement_t *tmp)
Starts a measurement.
Definition chtm.c:95
Type of a kernel statistics structure.
Definition chstats.h:55
time_measurement_t m_crit_thd
Measurement of threads critical zones duration.
Definition chstats.h:58
ucnt_t n_irq
Number of IRQs.
Definition chstats.h:56
time_measurement_t m_crit_isr
Measurement of ISRs critical zones duration.
Definition chstats.h:60
ucnt_t n_ctxswc
Number of context switches.
Definition chstats.h:57
Type of a Time Measurement object.
Definition chtm.h:78