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