shell: show thread execution cycles
This adds the bits to show the thread execution cycles when doing "kernel threads" in shell. Signed-off-by: Daniel Leung <daniel.leung@intel.com>
This commit is contained in:
parent
fd7a68dbe9
commit
939d48cb02
1 changed files with 42 additions and 0 deletions
|
@ -14,6 +14,7 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <device.h>
|
#include <device.h>
|
||||||
#include <drivers/timer/system_timer.h>
|
#include <drivers/timer/system_timer.h>
|
||||||
|
#include <kernel.h>
|
||||||
|
|
||||||
static int cmd_kernel_version(const struct shell *shell,
|
static int cmd_kernel_version(const struct shell *shell,
|
||||||
size_t argc, char **argv)
|
size_t argc, char **argv)
|
||||||
|
@ -62,6 +63,11 @@ static void shell_tdata_dump(const struct k_thread *cthread, void *user_data)
|
||||||
const char *tname;
|
const char *tname;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
#ifdef CONFIG_THREAD_RUNTIME_STATS
|
||||||
|
k_thread_runtime_stats_t rt_stats_thread;
|
||||||
|
k_thread_runtime_stats_t rt_stats_all;
|
||||||
|
#endif
|
||||||
|
|
||||||
tname = k_thread_name_get(thread);
|
tname = k_thread_name_get(thread);
|
||||||
|
|
||||||
shell_print(shell, "%s%p %-10s",
|
shell_print(shell, "%s%p %-10s",
|
||||||
|
@ -74,6 +80,42 @@ static void shell_tdata_dump(const struct k_thread *cthread, void *user_data)
|
||||||
thread->base.timeout.dticks);
|
thread->base.timeout.dticks);
|
||||||
shell_print(shell, "\tstate: %s", k_thread_state_str(thread));
|
shell_print(shell, "\tstate: %s", k_thread_state_str(thread));
|
||||||
|
|
||||||
|
#ifdef CONFIG_THREAD_RUNTIME_STATS
|
||||||
|
ret = 0;
|
||||||
|
|
||||||
|
if (k_thread_runtime_stats_get(thread, &rt_stats_thread) != 0) {
|
||||||
|
ret++;
|
||||||
|
};
|
||||||
|
|
||||||
|
if (k_thread_runtime_stats_all_get(&rt_stats_all) != 0) {
|
||||||
|
ret++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ret == 0) {
|
||||||
|
pcnt = (rt_stats_thread.execution_cycles * 100U) /
|
||||||
|
rt_stats_all.execution_cycles;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* z_prf() does not support %llu by default unless
|
||||||
|
* CONFIG_MINIMAL_LIBC_LL_PRINTF=y. So do conditional
|
||||||
|
* compilation to avoid blindly enabling this kconfig
|
||||||
|
* so it won't increase RAM/ROM usage too much on 32-bit
|
||||||
|
* targets.
|
||||||
|
*/
|
||||||
|
#ifdef CONFIG_64BIT
|
||||||
|
shell_print(shell, "\tTotal execution cycles: %llu (%u %%)",
|
||||||
|
rt_stats_thread.execution_cycles,
|
||||||
|
pcnt);
|
||||||
|
#else
|
||||||
|
shell_print(shell, "\tTotal execution cycles: %lu (%u %%)",
|
||||||
|
(uint32_t)rt_stats_thread.execution_cycles,
|
||||||
|
pcnt);
|
||||||
|
#endif
|
||||||
|
} else {
|
||||||
|
shell_print(shell, "\tTotal execution cycles: ? (? %%)");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
ret = k_thread_stack_space_get(thread, &unused);
|
ret = k_thread_stack_space_get(thread, &unused);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
shell_print(shell,
|
shell_print(shell,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue