31 #if !CH_DBG_STATISTICS
32 #error CH_DBG_STATISTICS should be defined to TRUE to use this monitoring tool
45 typedef struct _ThreadCpuInfo {
53 static void stampThreadCpuInfo(ThreadCpuInfo *ti)
55 const thread_t *tp = chRegFirstThread();
60 ti->ticks[
idx] = (float) tp->stats.cumulative;
61 ti->totalTicks += ti->ticks[
idx];
62 tp = chRegNextThread((thread_t *)tp);
65 ti->totalISRTicks = ch0.kernel_stats.m_crit_isr.cumulative;
66 ti->totalTicks += ti->totalISRTicks;
67 tp = chRegFirstThread();
70 ti->cpu[
idx] = (ti->ticks[
idx] * 100.f) / ti->totalTicks;
71 tp = chRegNextThread((thread_t *)tp);
76 static float stampThreadGetCpuPercent(
const ThreadCpuInfo *ti,
const uint32_t idx)
85 static float stampISRGetCpuPercent(
const ThreadCpuInfo *ti)
87 return ti->totalISRTicks * 100.0f / ti->totalTicks;
90 static void cmd_threads(BaseSequentialStream *lchp,
int argc,
const char *
const argv[])
92 static const char *
states[] = {CH_STATE_NAMES};
93 thread_t *tp = chRegFirstThread();
99 static ThreadCpuInfo threadCpuInfo = {
106 stampThreadCpuInfo(&threadCpuInfo);
108 chprintf(lchp,
" addr stack frestk prio refs state time \t percent name\r\n");
111 chprintf(lchp,
"%.8lx %.8lx %6lu %4lu %4lu %9s %9lu %.2f%% \t%s\r\n",
117 stampThreadGetCpuPercent(&threadCpuInfo,
idx),
118 chRegGetThreadNameX(tp));
120 totalTicks += (float)tp->stats.cumulative;
121 if (strcmp(chRegGetThreadNameX(tp),
"idle") == 0) {
122 idleTicks = (float)tp->stats.cumulative;
124 tp = chRegNextThread((thread_t *)tp);
126 }
while (tp != NULL);
128 totalTicks += ch0.kernel_stats.m_crit_isr.cumulative;
129 const float idlePercent = (idleTicks * 100.f) / totalTicks;
130 const float cpuPercent = 100.f - idlePercent;
131 chprintf(lchp,
"Interrupt Service Routine \t\t %9lu %.2f%% \tISR\r\n",
133 stampISRGetCpuPercent(&threadCpuInfo));
134 chprintf(lchp,
"\r\ncpu load = %.2f%%\r\n", cpuPercent);
137 static void cmd_rtos_mon(
shell_stream_t *sh,
int argc,
const char *
const argv[])
141 chprintf(sh,
"Usage: rtos_mon\r\n");
145 chprintf(sh,
"Data reported in the RTOS_MON message:\r\n");
154 chprintf(sh,
" thread %d load: %0.1f, free stack: %d\r\n", i,
173 size_t total_fragments, total_fragmented_free_space, largest_free_block;
175 total_fragments = chHeapStatus(NULL, &total_fragmented_free_space, &largest_free_block);
176 chCoreGetStatusX(&area);
187 float idle_counter = 0.f;
190 tp = chRegFirstThread();
203 sum += (float)(tp->stats.cumulative);
206 if (tp == chSysGetIdleThreadX()) {
207 idle_counter = (float)tp->stats.cumulative;
210 tp = chRegNextThread(tp);
215 sum += ch0.kernel_stats.m_crit_isr.cumulative;
230 extern const uint8_t __ram0_end__;
231 unsigned long long *stkAdr = (
unsigned long long *)((
uint8_t *) tp->wabase);
232 while ((stkAdr[index] == 0x5555555555555555) && (((
uint8_t *) & (stkAdr[index])) < &__ram0_end__)) {
static uint32_t thread_p_time[RTOS_MON_MAX_THREADS]
void rtos_mon_periodic_arch(void)
void rtos_mon_init_arch(void)
static uint16_t get_stack_free(const thread_t *tp)
static struct nodeState states[UWB_SERIAL_COMM_DIST_NUM_NODES]
if(GpsFixValid() &&e_identification_started)
void chprintf(BaseSequentialStream *lchp, const char *fmt,...)
Mini printf-like functionality.
struct rtos_monitoring rtos_mon
void shell_add_entry(char *cmd_name, shell_cmd_t *cmd)
Add dynamic entry.
BaseSequentialStream shell_stream_t
System monitoring for RTOS targets return cpu load, average exec time, ...
uint8_t cpu_load
global CPU/MCU load in %
char thread_names[RTOS_MON_THREAD_NAMES+1]
string of thread names / identifiers
uint32_t core_free_memory
core free memory in bytes
uint16_t thread_free_stack[RTOS_MON_MAX_THREADS]
individual thread free stack in bytes
uint32_t heap_free_memory
Total fragmented free memory in the heap.
uint16_t thread_load[RTOS_MON_MAX_THREADS]
individual thread load in centi-percent (10*%)
uint8_t thread_name_idx
length of the string in thread_names buffer
uint8_t thread_counter
number of threads
#define RTOS_MON_MAX_THREADS
uint32_t heap_fragments
Number of fragments in the heap.
#define RTOS_MON_NAME_LEN
uint32_t heap_largest
Largest free block in the heap.
Architecture independent timing functions.
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
int int32_t
Typedef defining 32 bit int type.
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.