Merge pull request #16470 from jan-mo/feat/20210512__schedstatistics_runtime_in_usec
sys/ps: enable runtime_usec output for the ps command
This commit is contained in:
commit
69368c32f8
21
sys/ps/ps.c
21
sys/ps/ps.c
@ -12,19 +12,21 @@
|
|||||||
* @file
|
* @file
|
||||||
* @brief UNIX like ps command
|
* @brief UNIX like ps command
|
||||||
* @author Kaspar Schleiser <kaspar@schleiser.de>
|
* @author Kaspar Schleiser <kaspar@schleiser.de>
|
||||||
|
*
|
||||||
|
* @note The entry 'runtime_usec' in 'MODULE_SCHEDSTATISTICS' is limited
|
||||||
|
* to 2**32 microseconds. So the entry gets reset after ~1.2 hours.
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
#include "thread.h"
|
|
||||||
#include "sched.h"
|
|
||||||
#include "thread.h"
|
#include "thread.h"
|
||||||
#include "sched.h"
|
#include "sched.h"
|
||||||
|
|
||||||
#ifdef MODULE_SCHEDSTATISTICS
|
#ifdef MODULE_SCHEDSTATISTICS
|
||||||
#include "schedstatistics.h"
|
#include "schedstatistics.h"
|
||||||
|
#include "xtimer.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef MODULE_TLSF_MALLOC
|
#ifdef MODULE_TLSF_MALLOC
|
||||||
@ -50,7 +52,7 @@ void ps(void)
|
|||||||
"| stack ( used) ( free) | base addr | current "
|
"| stack ( used) ( free) | base addr | current "
|
||||||
#endif
|
#endif
|
||||||
#ifdef MODULE_SCHEDSTATISTICS
|
#ifdef MODULE_SCHEDSTATISTICS
|
||||||
"| runtime | switches"
|
"| runtime | switches | runtime_usec "
|
||||||
#endif
|
#endif
|
||||||
"\n",
|
"\n",
|
||||||
#ifdef CONFIG_THREAD_NAMES
|
#ifdef CONFIG_THREAD_NAMES
|
||||||
@ -89,11 +91,11 @@ void ps(void)
|
|||||||
thread_t *p = thread_get(i);
|
thread_t *p = thread_get(i);
|
||||||
|
|
||||||
if (p != NULL) {
|
if (p != NULL) {
|
||||||
thread_status_t state = thread_get_status(p); /* copy state */
|
thread_status_t state = thread_get_status(p); /* copy state */
|
||||||
const char *sname = thread_state_to_string(state); /* get state name */
|
const char *sname = thread_state_to_string(state); /* get state name */
|
||||||
const char *queued = thread_is_active(p) ? "Q" : "_"; /* get queued flag */
|
const char *queued = thread_is_active(p) ? "Q" : "_"; /* get queued flag */
|
||||||
#ifdef DEVELHELP
|
#ifdef DEVELHELP
|
||||||
int stacksz = p->stack_size; /* get stack size */
|
int stacksz = p->stack_size; /* get stack size */
|
||||||
overall_stacksz += stacksz;
|
overall_stacksz += stacksz;
|
||||||
int stack_free = thread_measure_stack_free(p->stack_start);
|
int stack_free = thread_measure_stack_free(p->stack_start);
|
||||||
stacksz -= stack_free;
|
stacksz -= stack_free;
|
||||||
@ -102,6 +104,7 @@ void ps(void)
|
|||||||
#ifdef MODULE_SCHEDSTATISTICS
|
#ifdef MODULE_SCHEDSTATISTICS
|
||||||
/* multiply with 100 for percentage and to avoid floats/doubles */
|
/* multiply with 100 for percentage and to avoid floats/doubles */
|
||||||
uint64_t runtime_ticks = sched_pidlist[i].runtime_ticks * 100;
|
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_major = runtime_ticks / rt_sum;
|
||||||
unsigned runtime_minor = ((runtime_ticks % rt_sum) * 1000) / rt_sum;
|
unsigned runtime_minor = ((runtime_ticks % rt_sum) * 1000) / rt_sum;
|
||||||
unsigned switches = sched_pidlist[i].schedules;
|
unsigned switches = sched_pidlist[i].schedules;
|
||||||
@ -115,7 +118,7 @@ void ps(void)
|
|||||||
" | %6i (%5i) (%5i) | %10p | %10p "
|
" | %6i (%5i) (%5i) | %10p | %10p "
|
||||||
#endif
|
#endif
|
||||||
#ifdef MODULE_SCHEDSTATISTICS
|
#ifdef MODULE_SCHEDSTATISTICS
|
||||||
" | %2d.%03d%% | %8u"
|
" | %2d.%03d%% | %8u | %10"PRIu32" "
|
||||||
#endif
|
#endif
|
||||||
"\n",
|
"\n",
|
||||||
p->pid,
|
p->pid,
|
||||||
@ -128,7 +131,7 @@ void ps(void)
|
|||||||
(void *)p->stack_start, (void *)p->sp
|
(void *)p->stack_start, (void *)p->sp
|
||||||
#endif
|
#endif
|
||||||
#ifdef MODULE_SCHEDSTATISTICS
|
#ifdef MODULE_SCHEDSTATISTICS
|
||||||
, runtime_major, runtime_minor, switches
|
, runtime_major, runtime_minor, switches, xtimer_usec_from_ticks(xtimer_ticks)
|
||||||
#endif
|
#endif
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user