Skip to content

Commit cd3eaad

Browse files
laodzudpgeorge
authored andcommitted
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 <[email protected]> Signed-off-by: Maureen Helm <[email protected]>
1 parent cd71db0 commit cd3eaad

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

docs/library/zephyr.rst

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@ Functions
2222

2323
Returns the thread id of the current thread, which is used to reference the thread.
2424

25-
.. function:: thread_analyze()
25+
.. function:: thread_analyze(cpu)
2626

27-
Runs the Zephyr debug thread analyzer on the current thread and prints stack size statistics in the format:
27+
Runs the Zephyr debug thread analyzer on the current thread on the given cpu
28+
and prints stack size statistics in the format:
2829

2930
"``thread_name``-20s: STACK: unused ``available_stack_space`` usage ``stack_space_used``
3031
/ ``stack_size`` (``percent_stack_space_used`` %); CPU: ``cpu_utilization`` %"
@@ -35,6 +36,9 @@ Functions
3536
For more information, see documentation for Zephyr `thread analyzer
3637
<https://docs.zephyrproject.org/latest/guides/debug_tools/thread-analyzer.html#thread-analyzer>`_.
3738

39+
Note that the ``cpu`` argument is only used in Zephyr v4.0.0 and
40+
newer and ignored otherwise.
41+
3842
.. function:: shell_exec(cmd_in)
3943

4044
Executes the given command on an UART backend. This function can only be accessed if ``CONFIG_SHELL_BACKEND_SERIAL``

ports/zephyr/modzephyr.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
#include <stdio.h>
3232
#include <zephyr/kernel.h>
33+
#include <zephyr/version.h>
3334
#include <zephyr/debug/thread_analyzer.h>
3435
#include <zephyr/shell/shell.h>
3536
#include <zephyr/shell/shell_uart.h>
@@ -48,11 +49,16 @@ static mp_obj_t mod_current_tid(void) {
4849
static MP_DEFINE_CONST_FUN_OBJ_0(mod_current_tid_obj, mod_current_tid);
4950

5051
#ifdef CONFIG_THREAD_ANALYZER
51-
static mp_obj_t mod_thread_analyze(void) {
52+
static mp_obj_t mod_thread_analyze(mp_obj_t cpu_in) {
53+
#if KERNEL_VERSION_NUMBER >= ZEPHYR_VERSION(4, 0, 0)
54+
unsigned int cpu = mp_obj_get_int(cpu_in);
55+
thread_analyzer_print(cpu);
56+
#else
5257
thread_analyzer_print();
58+
#endif
5359
return mp_const_none;
5460
}
55-
static MP_DEFINE_CONST_FUN_OBJ_0(mod_thread_analyze_obj, mod_thread_analyze);
61+
static MP_DEFINE_CONST_FUN_OBJ_1(mod_thread_analyze_obj, mod_thread_analyze);
5662
#endif
5763

5864
#ifdef CONFIG_SHELL_BACKEND_SERIAL

0 commit comments

Comments
 (0)