Skip to content

Commit ad937c4

Browse files
committed
zephyr/modzephyr: Add current_tid() and stacks_analyze() functions.
current_tid() returns current thread ID. stacks_analyze() calls k_call_stacks_analyze() which, with CONFIG_INIT_STACKS enabled, will print stack usage for some well-known threads in the system.
1 parent d5191ed commit ad937c4

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

zephyr/modzephyr.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#if MICROPY_PY_ZEPHYR
2929

3030
#include <zephyr.h>
31+
#include <misc/stack.h>
3132

3233
#include "py/runtime.h"
3334

@@ -36,9 +37,22 @@ STATIC mp_obj_t mod_is_preempt_thread(void) {
3637
}
3738
STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_is_preempt_thread_obj, mod_is_preempt_thread);
3839

40+
STATIC mp_obj_t mod_current_tid(void) {
41+
return MP_OBJ_NEW_SMALL_INT(k_current_get());
42+
}
43+
STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_current_tid_obj, mod_current_tid);
44+
45+
STATIC mp_obj_t mod_stacks_analyze(void) {
46+
k_call_stacks_analyze();
47+
return mp_const_none;
48+
}
49+
STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_stacks_analyze_obj, mod_stacks_analyze);
50+
3951
STATIC const mp_rom_map_elem_t mp_module_time_globals_table[] = {
4052
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_zephyr) },
4153
{ MP_ROM_QSTR(MP_QSTR_is_preempt_thread), MP_ROM_PTR(&mod_is_preempt_thread_obj) },
54+
{ MP_ROM_QSTR(MP_QSTR_current_tid), MP_ROM_PTR(&mod_current_tid_obj) },
55+
{ MP_ROM_QSTR(MP_QSTR_stacks_analyze), MP_ROM_PTR(&mod_stacks_analyze_obj) },
4256
};
4357

4458
STATIC MP_DEFINE_CONST_DICT(mp_module_time_globals, mp_module_time_globals_table);

0 commit comments

Comments
 (0)