zephyr/modzephyr: Revamp stacks_analyze() call.

Underlying k_call_stacks_analyze() was gone in Zephyr, reimplement using
k_thread_foreach().
This commit is contained in:
Paul Sokolovsky 2018-09-27 00:24:40 +03:00 committed by Damien George
parent 297092a76a
commit a42c1d9fd5
2 changed files with 25 additions and 1 deletions

View File

@ -27,6 +27,7 @@
#include "py/mpconfig.h" #include "py/mpconfig.h"
#if MICROPY_PY_ZEPHYR #if MICROPY_PY_ZEPHYR
#include <stdio.h>
#include <zephyr.h> #include <zephyr.h>
#include <misc/stack.h> #include <misc/stack.h>
@ -42,11 +43,29 @@ STATIC mp_obj_t mod_current_tid(void) {
} }
STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_current_tid_obj, mod_current_tid); STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_current_tid_obj, mod_current_tid);
#ifdef CONFIG_THREAD_STACK_INFO
extern k_tid_t const _main_thread;
extern k_tid_t const _idle_thread;
static void thread_stack_dump(const struct k_thread *thread, void *user_data)
{
const char *th_name = k_thread_name_get((k_tid_t)thread);
if (th_name == NULL) {
static char tid[9];
snprintf(tid, sizeof(tid), "%08x", (int)thread);
th_name = tid;
}
stack_analyze(th_name, (char*)thread->stack_info.start, thread->stack_info.size);
}
STATIC mp_obj_t mod_stacks_analyze(void) { STATIC mp_obj_t mod_stacks_analyze(void) {
k_call_stacks_analyze(); k_thread_foreach(thread_stack_dump, NULL);
return mp_const_none; return mp_const_none;
} }
STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_stacks_analyze_obj, mod_stacks_analyze); STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_stacks_analyze_obj, mod_stacks_analyze);
#endif
#ifdef CONFIG_NET_SHELL #ifdef CONFIG_NET_SHELL
@ -64,7 +83,9 @@ STATIC const mp_rom_map_elem_t mp_module_time_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_zephyr) }, { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_zephyr) },
{ MP_ROM_QSTR(MP_QSTR_is_preempt_thread), MP_ROM_PTR(&mod_is_preempt_thread_obj) }, { MP_ROM_QSTR(MP_QSTR_is_preempt_thread), MP_ROM_PTR(&mod_is_preempt_thread_obj) },
{ MP_ROM_QSTR(MP_QSTR_current_tid), MP_ROM_PTR(&mod_current_tid_obj) }, { MP_ROM_QSTR(MP_QSTR_current_tid), MP_ROM_PTR(&mod_current_tid_obj) },
#ifdef CONFIG_THREAD_STACK_INFO
{ MP_ROM_QSTR(MP_QSTR_stacks_analyze), MP_ROM_PTR(&mod_stacks_analyze_obj) }, { MP_ROM_QSTR(MP_QSTR_stacks_analyze), MP_ROM_PTR(&mod_stacks_analyze_obj) },
#endif
#ifdef CONFIG_NET_SHELL #ifdef CONFIG_NET_SHELL
{ MP_ROM_QSTR(MP_QSTR_shell_net_iface), MP_ROM_PTR(&mod_shell_net_iface_obj) }, { MP_ROM_QSTR(MP_QSTR_shell_net_iface), MP_ROM_PTR(&mod_shell_net_iface_obj) },

View File

@ -51,6 +51,9 @@ CONFIG_NET_DHCPV4=y
# Required for zephyr.stack_analyze() # Required for zephyr.stack_analyze()
CONFIG_INIT_STACKS=y CONFIG_INIT_STACKS=y
CONFIG_THREAD_MONITOR=y
CONFIG_THREAD_NAME=y
CONFIG_THREAD_STACK_INFO=y
# Required for usocket.pkt_get_info() # Required for usocket.pkt_get_info()
CONFIG_NET_BUF_POOL_USAGE=y CONFIG_NET_BUF_POOL_USAGE=y