aboutsummaryrefslogtreecommitdiff
path: root/lib/chibios/os/rt/src/chstats.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/chibios/os/rt/src/chstats.c')
-rw-r--r--lib/chibios/os/rt/src/chstats.c126
1 files changed, 126 insertions, 0 deletions
diff --git a/lib/chibios/os/rt/src/chstats.c b/lib/chibios/os/rt/src/chstats.c
new file mode 100644
index 000000000..f46ca5dbd
--- /dev/null
+++ b/lib/chibios/os/rt/src/chstats.c
@@ -0,0 +1,126 @@
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 */
62void _stats_init(void) {
63
64 ch.kernel_stats.n_irq = (ucnt_t)0;
65 ch.kernel_stats.n_ctxswc = (ucnt_t)0;
66 chTMObjectInit(&ch.kernel_stats.m_crit_thd);
67 chTMObjectInit(&ch.kernel_stats.m_crit_isr);
68}
69
70/**
71 * @brief Increases the IRQ counter.
72 */
73void _stats_increase_irq(void) {
74
75 port_lock_from_isr();
76 ch.kernel_stats.n_irq++;
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 */
86void _stats_ctxswc(thread_t *ntp, thread_t *otp) {
87
88 ch.kernel_stats.n_ctxswc++;
89 chTMChainMeasurementToX(&otp->stats, &ntp->stats);
90}
91
92/**
93 * @brief Starts the measurement of a thread critical zone.
94 */
95void _stats_start_measure_crit_thd(void) {
96
97 chTMStartMeasurementX(&ch.kernel_stats.m_crit_thd);
98}
99
100/**
101 * @brief Stops the measurement of a thread critical zone.
102 */
103void _stats_stop_measure_crit_thd(void) {
104
105 chTMStopMeasurementX(&ch.kernel_stats.m_crit_thd);
106}
107
108/**
109 * @brief Starts the measurement of an ISR critical zone.
110 */
111void _stats_start_measure_crit_isr(void) {
112
113 chTMStartMeasurementX(&ch.kernel_stats.m_crit_isr);
114}
115
116/**
117 * @brief Stops the measurement of an ISR critical zone.
118 */
119void _stats_stop_measure_crit_isr(void) {
120
121 chTMStopMeasurementX(&ch.kernel_stats.m_crit_isr);
122}
123
124#endif /* CH_DBG_STATISTICS == TRUE */
125
126/** @} */