ChibiOS/RT  5.1.0
chstats.c
Go to the documentation of this file.
1 /*
2  ChibiOS - Copyright (C) 2006..2018 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; either version 3 of the License, or
9  (at your option) any later version.
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 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 /** @} */
void _stats_start_measure_crit_thd(void)
Starts the measurement of a thread critical zone.
Definition: chstats.c:95
void _stats_stop_measure_crit_thd(void)
Stops the measurement of a thread critical zone.
Definition: chstats.c:103
time_measurement_t m_crit_isr
Measurement of ISRs critical zones duration.
Definition: chstats.h:61
void _stats_ctxswc(thread_t *ntp, thread_t *otp)
Updates context switch related statistics.
Definition: chstats.c:86
ucnt_t n_irq
Number of IRQs.
Definition: chstats.h:57
ucnt_t n_ctxswc
Number of context switches.
Definition: chstats.h:58
ch_system_t ch
System data structures.
Definition: chschd.c:42
NOINLINE void chTMStartMeasurementX(time_measurement_t *tmp)
Starts a measurement.
Definition: chtm.c:114
void _stats_init(void)
Initializes the statistics module.
Definition: chstats.c:62
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:144
void _stats_increase_irq(void)
Increases the IRQ counter.
Definition: chstats.c:73
kernel_stats_t kernel_stats
Global kernel statistics.
Definition: chschd.h:438
time_measurement_t stats
Thread statistics.
Definition: chschd.h:311
void _stats_start_measure_crit_isr(void)
Starts the measurement of an ISR critical zone.
Definition: chstats.c:111
void chTMObjectInit(time_measurement_t *tmp)
Initializes a TimeMeasurement object.
Definition: chtm.c:97
time_measurement_t m_crit_thd
Measurement of threads critical zones duration.
Definition: chstats.h:59
ChibiOS/RT main include file.
NOINLINE void chTMStopMeasurementX(time_measurement_t *tmp)
Stops a measurement.
Definition: chtm.c:127
void _stats_stop_measure_crit_isr(void)
Stops the measurement of an ISR critical zone.
Definition: chstats.c:119
Structure representing a thread.
Definition: chschd.h:153