ChibiOS  21.6.0
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  */
56 typedef 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
74 extern "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  */
99 static inline void __stats_object_init(kernel_stats_t *ksp) {
100 
101  ksp->n_irq = (ucnt_t)0;
102  ksp->n_ctxswc = (ucnt_t)0;
103  chTMObjectInit(&ksp->m_crit_thd);
104  chTMObjectInit(&ksp->m_crit_isr);
105 }
106 
107 #else /* CH_DBG_STATISTICS == FALSE */
108 
109 /* Stub functions for when the statistics module is disabled. */
110 #define __stats_increase_irq()
111 #define __stats_ctxswc(old, new)
112 #define __stats_start_measure_crit_thd()
113 #define __stats_stop_measure_crit_thd()
114 #define __stats_start_measure_crit_isr()
115 #define __stats_stop_measure_crit_isr()
116 
117 #endif /* CH_DBG_STATISTICS == FALSE */
118 
119 #endif /* CHSTATS_H */
120 
121 /** @} */
kernel_stats_t::m_crit_thd
time_measurement_t m_crit_thd
Measurement of threads critical zones duration.
Definition: chstats.h:59
__stats_ctxswc
void __stats_ctxswc(thread_t *ntp, thread_t *otp)
Updates context switch related statistics.
Definition: chstats.c:73
kernel_stats_t::m_crit_isr
time_measurement_t m_crit_isr
Measurement of ISRs critical zones duration.
Definition: chstats.h:61
__stats_stop_measure_crit_isr
void __stats_stop_measure_crit_isr(void)
Stops the measurement of an ISR critical zone.
Definition: chstats.c:106
ucnt_t
uint32_t ucnt_t
Definition: chearly.h:93
kernel_stats_t::n_irq
ucnt_t n_irq
Number of IRQs.
Definition: chstats.h:57
ch_thread
Structure representing a thread.
Definition: chobjects.h:156
time_measurement_t
Type of a Time Measurement object.
Definition: chtm.h:79
__stats_stop_measure_crit_thd
void __stats_stop_measure_crit_thd(void)
Stops the measurement of a thread critical zone.
Definition: chstats.c:90
chTMObjectInit
void chTMObjectInit(time_measurement_t *tmp)
Initializes a TimeMeasurement object.
Definition: chtm.c:79
kernel_stats_t
Type of a kernel statistics structure.
Definition: chstats.h:56
__stats_object_init
static void __stats_object_init(kernel_stats_t *ksp)
Statistics initialization.
Definition: chstats.h:99
__stats_start_measure_crit_thd
void __stats_start_measure_crit_thd(void)
Starts the measurement of a thread critical zone.
Definition: chstats.c:82
kernel_stats_t::n_ctxswc
ucnt_t n_ctxswc
Number of context switches.
Definition: chstats.h:58
__stats_start_measure_crit_isr
void __stats_start_measure_crit_isr(void)
Starts the measurement of an ISR critical zone.
Definition: chstats.c:98
__stats_increase_irq
void __stats_increase_irq(void)
Increases the IRQ counter.
Definition: chstats.c:60