ChibiOS/RT  6.1.4
chstats.c
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/src/chstats.c
22  * @brief Statistics module code.
23  *
24  * @addtogroup statistics
25  * @details Statistics services.
26  * @{
27  */
28 
29 #include "ch.h"
30 
31 #if (CH_DBG_STATISTICS == TRUE) || defined(__DOXYGEN__)
32 
33 /*===========================================================================*/
34 /* Module local definitions. */
35 /*===========================================================================*/
36 
37 /*===========================================================================*/
38 /* Module exported variables. */
39 /*===========================================================================*/
40 
41 /*===========================================================================*/
42 /* Module local types. */
43 /*===========================================================================*/
44 
45 /*===========================================================================*/
46 /* Module local variables. */
47 /*===========================================================================*/
48 
49 /*===========================================================================*/
50 /* Module local functions. */
51 /*===========================================================================*/
52 
53 /*===========================================================================*/
54 /* Module exported functions. */
55 /*===========================================================================*/
56 
57 /**
58  * @brief Initializes the statistics module.
59  *
60  * @init
61  */
62 void _stats_init(void) {
63 
64  ch.kernel_stats.n_irq = (ucnt_t)0;
65  ch.kernel_stats.n_ctxswc = (ucnt_t)0;
68 }
69 
70 /**
71  * @brief Increases the IRQ counter.
72  */
73 void _stats_increase_irq(void) {
74 
75  port_lock_from_isr();
77  port_unlock_from_isr();
78 }
79 
80 /**
81  * @brief Updates context switch related statistics.
82  *
83  * @param[in] ntp the thread to be switched in
84  * @param[in] otp the thread to be switched out
85  */
86 void _stats_ctxswc(thread_t *ntp, thread_t *otp) {
87 
89  chTMChainMeasurementToX(&otp->stats, &ntp->stats);
90 }
91 
92 /**
93  * @brief Starts the measurement of a thread critical zone.
94  */
96 
98 }
99 
100 /**
101  * @brief Stops the measurement of a thread critical zone.
102  */
104 
106 }
107 
108 /**
109  * @brief Starts the measurement of an ISR critical zone.
110  */
112 
114 }
115 
116 /**
117  * @brief Stops the measurement of an ISR critical zone.
118  */
120 
122 }
123 
124 #endif /* CH_DBG_STATISTICS == TRUE */
125 
126 /** @} */
kernel_stats_t::m_crit_thd
time_measurement_t m_crit_thd
Measurement of threads critical zones duration.
Definition: chstats.h:59
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:119
kernel_stats_t::n_irq
ucnt_t n_irq
Number of IRQs.
Definition: chstats.h:57
_stats_increase_irq
void _stats_increase_irq(void)
Increases the IRQ counter.
Definition: chstats.c:73
_stats_start_measure_crit_thd
void _stats_start_measure_crit_thd(void)
Starts the measurement of a thread critical zone.
Definition: chstats.c:95
ch_thread
Structure representing a thread.
Definition: chschd.h:134
_stats_start_measure_crit_isr
void _stats_start_measure_crit_isr(void)
Starts the measurement of an ISR critical zone.
Definition: chstats.c:111
ch_system::kernel_stats
kernel_stats_t kernel_stats
Global kernel statistics.
Definition: chschd.h:441
chTMObjectInit
void chTMObjectInit(time_measurement_t *tmp)
Initializes a TimeMeasurement object.
Definition: chtm.c:109
ch
ch_system_t ch
System data structures.
Definition: chschd.c:42
ch.h
ChibiOS/RT main include file.
ch_thread::stats
time_measurement_t stats
Thread statistics.
Definition: chschd.h:296
chTMStopMeasurementX
NOINLINE void chTMStopMeasurementX(time_measurement_t *tmp)
Stops a measurement.
Definition: chtm.c:139
_stats_stop_measure_crit_thd
void _stats_stop_measure_crit_thd(void)
Stops the measurement of a thread critical zone.
Definition: chstats.c:103
_stats_ctxswc
void _stats_ctxswc(thread_t *ntp, thread_t *otp)
Updates context switch related statistics.
Definition: chstats.c:86
kernel_stats_t::n_ctxswc
ucnt_t n_ctxswc
Number of context switches.
Definition: chstats.h:58
_stats_init
void _stats_init(void)
Initializes the statistics module.
Definition: chstats.c:62
chTMChainMeasurementToX
NOINLINE void chTMChainMeasurementToX(time_measurement_t *tmp1, time_measurement_t *tmp2)
Stops a measurement and chains to the next one using the same time stamp.
Definition: chtm.c:156
chTMStartMeasurementX
NOINLINE void chTMStartMeasurementX(time_measurement_t *tmp)
Starts a measurement.
Definition: chtm.c:126