From 435796ccaad9d9e75f3b4099cfa7d3e787ea705b Mon Sep 17 00:00:00 2001 From: Jan Mohr Date: Wed, 12 May 2021 15:27:05 +0200 Subject: [PATCH] sys/ps/ps.c: enabled runtime in usec for schedstatistics --- sys/ps/ps.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/sys/ps/ps.c b/sys/ps/ps.c index 73c0277e6d..5fe1acf050 100644 --- a/sys/ps/ps.c +++ b/sys/ps/ps.c @@ -12,19 +12,21 @@ * @file * @brief UNIX like ps command * @author Kaspar Schleiser + * + * @note The entry 'runtime_usec' in 'MODULE_SCHEDSTATISTICS' is limited + * to 2**32 microseconds. So the entry gets reset after ~1.2 hours. * @} */ #include #include -#include "thread.h" -#include "sched.h" #include "thread.h" #include "sched.h" #ifdef MODULE_SCHEDSTATISTICS #include "schedstatistics.h" +#include "xtimer.h" #endif #ifdef MODULE_TLSF_MALLOC @@ -50,7 +52,7 @@ void ps(void) "| stack ( used) ( free) | base addr | current " #endif #ifdef MODULE_SCHEDSTATISTICS - "| runtime | switches" + "| runtime | switches | runtime_usec " #endif "\n", #ifdef CONFIG_THREAD_NAMES @@ -89,11 +91,11 @@ void ps(void) thread_t *p = thread_get(i); if (p != NULL) { - thread_status_t state = thread_get_status(p); /* copy state */ - const char *sname = thread_state_to_string(state); /* get state name */ - const char *queued = thread_is_active(p) ? "Q" : "_"; /* get queued flag */ + thread_status_t state = thread_get_status(p); /* copy state */ + const char *sname = thread_state_to_string(state); /* get state name */ + const char *queued = thread_is_active(p) ? "Q" : "_"; /* get queued flag */ #ifdef DEVELHELP - int stacksz = p->stack_size; /* get stack size */ + int stacksz = p->stack_size; /* get stack size */ overall_stacksz += stacksz; int stack_free = thread_measure_stack_free(p->stack_start); stacksz -= stack_free; @@ -102,6 +104,7 @@ void ps(void) #ifdef MODULE_SCHEDSTATISTICS /* multiply with 100 for percentage and to avoid floats/doubles */ uint64_t runtime_ticks = sched_pidlist[i].runtime_ticks * 100; + xtimer_ticks32_t xtimer_ticks = {sched_pidlist[i].runtime_ticks}; unsigned runtime_major = runtime_ticks / rt_sum; unsigned runtime_minor = ((runtime_ticks % rt_sum) * 1000) / rt_sum; unsigned switches = sched_pidlist[i].schedules; @@ -115,7 +118,7 @@ void ps(void) " | %6i (%5i) (%5i) | %10p | %10p " #endif #ifdef MODULE_SCHEDSTATISTICS - " | %2d.%03d%% | %8u" + " | %2d.%03d%% | %8u | %10"PRIu32" " #endif "\n", p->pid, @@ -128,7 +131,7 @@ void ps(void) (void *)p->stack_start, (void *)p->sp #endif #ifdef MODULE_SCHEDSTATISTICS - , runtime_major, runtime_minor, switches + , runtime_major, runtime_minor, switches, xtimer_usec_from_ticks(xtimer_ticks) #endif ); }