diff options
| author | Detlev Zundel <dzu@member.fsf.org> | 2025-02-06 16:45:25 +0100 |
|---|---|---|
| committer | Damien George <damien@micropython.org> | 2025-04-29 23:00:37 +1000 |
| commit | cd3eaad05cf94cd86e9762c854c68a4d4b5c2fab (patch) | |
| tree | 27d8222d19a1c732c1d19d5f7fe50f47db822243 | |
| parent | cd71db0172c9f0905fd3d3438b1f2cf70da11dfa (diff) | |
zephyr: Fix call to thread_analyzer_print for v4.0.
Commit 1b6e0f64796dfd6f86a8679ea6d24e1fca1e63a8 for Zephyr v4.0.0
changed the function "thread_analyzer_print" to require a cpu argument
and allow thread analysis on each cpu separately. The argument is
ignored when THREAD_ANALYZER_AUTO_SEPARATE_CORES=n which is the
default on single core machines.
Promote this change to the MicroPython zephyr module.
Signed-off-by: Detlev Zundel <dzu@member.fsf.org>
Signed-off-by: Maureen Helm <maureen.helm@analog.com>
| -rw-r--r-- | docs/library/zephyr.rst | 8 | ||||
| -rw-r--r-- | ports/zephyr/modzephyr.c | 10 |
2 files changed, 14 insertions, 4 deletions
diff --git a/docs/library/zephyr.rst b/docs/library/zephyr.rst index 10676d908..1a106d50e 100644 --- a/docs/library/zephyr.rst +++ b/docs/library/zephyr.rst @@ -22,9 +22,10 @@ Functions Returns the thread id of the current thread, which is used to reference the thread. -.. function:: thread_analyze() +.. function:: thread_analyze(cpu) - Runs the Zephyr debug thread analyzer on the current thread and prints stack size statistics in the format: + Runs the Zephyr debug thread analyzer on the current thread on the given cpu + and prints stack size statistics in the format: "``thread_name``-20s: STACK: unused ``available_stack_space`` usage ``stack_space_used`` / ``stack_size`` (``percent_stack_space_used`` %); CPU: ``cpu_utilization`` %" @@ -35,6 +36,9 @@ Functions For more information, see documentation for Zephyr `thread analyzer <https://docs.zephyrproject.org/latest/guides/debug_tools/thread-analyzer.html#thread-analyzer>`_. + Note that the ``cpu`` argument is only used in Zephyr v4.0.0 and + newer and ignored otherwise. + .. function:: shell_exec(cmd_in) Executes the given command on an UART backend. This function can only be accessed if ``CONFIG_SHELL_BACKEND_SERIAL`` diff --git a/ports/zephyr/modzephyr.c b/ports/zephyr/modzephyr.c index c059c7e39..08fdf5c5a 100644 --- a/ports/zephyr/modzephyr.c +++ b/ports/zephyr/modzephyr.c @@ -30,6 +30,7 @@ #include <stdio.h> #include <zephyr/kernel.h> +#include <zephyr/version.h> #include <zephyr/debug/thread_analyzer.h> #include <zephyr/shell/shell.h> #include <zephyr/shell/shell_uart.h> @@ -48,11 +49,16 @@ static mp_obj_t mod_current_tid(void) { static MP_DEFINE_CONST_FUN_OBJ_0(mod_current_tid_obj, mod_current_tid); #ifdef CONFIG_THREAD_ANALYZER -static mp_obj_t mod_thread_analyze(void) { +static mp_obj_t mod_thread_analyze(mp_obj_t cpu_in) { + #if KERNEL_VERSION_NUMBER >= ZEPHYR_VERSION(4, 0, 0) + unsigned int cpu = mp_obj_get_int(cpu_in); + thread_analyzer_print(cpu); + #else thread_analyzer_print(); + #endif return mp_const_none; } -static MP_DEFINE_CONST_FUN_OBJ_0(mod_thread_analyze_obj, mod_thread_analyze); +static MP_DEFINE_CONST_FUN_OBJ_1(mod_thread_analyze_obj, mod_thread_analyze); #endif #ifdef CONFIG_SHELL_BACKEND_SERIAL |
