zephyr: Fix and rename stacks_analyze function in zephyr module.
Zephyr deprecated and then removed its stack_analyze function because it was unsafe. Use the new zephyr thread analyzer instead and rename the MicroPython function to zephyr.thread_analyze() to be more consistent with the implementation. Tested on mimxrt1050_evk. The output now looks like this: >>> zephyr.thread_analyze() Thread analyze: 80004ff4 : unused 400 usage 112 / 512 (21 %) rx_workq : unused 1320 usage 180 / 1500 (12 %) tx_workq : unused 992 usage 208 / 1200 (17 %) net_mgmt : unused 656 usage 112 / 768 (14 %) sysworkq : unused 564 usage 460 / 1024 (44 %) idle : unused 256 usage 64 / 320 (20 %) main : unused 2952 usage 1784 / 4736 (37 %)
This commit is contained in:
parent
05e5d411b5
commit
38b4f1569e
@ -30,7 +30,7 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <zephyr.h>
|
||||
#include <debug/stack.h>
|
||||
#include <debug/thread_analyzer.h>
|
||||
|
||||
#include "modzephyr.h"
|
||||
#include "py/runtime.h"
|
||||
@ -45,27 +45,12 @@ 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_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) {
|
||||
k_thread_foreach(thread_stack_dump, NULL);
|
||||
#ifdef CONFIG_THREAD_ANALYZER
|
||||
STATIC mp_obj_t mod_thread_analyze(void) {
|
||||
thread_analyzer_print();
|
||||
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_thread_analyze_obj, mod_thread_analyze);
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_NET_SHELL
|
||||
@ -84,8 +69,8 @@ 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_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) },
|
||||
#ifdef CONFIG_THREAD_STACK_INFO
|
||||
{ MP_ROM_QSTR(MP_QSTR_stacks_analyze), MP_ROM_PTR(&mod_stacks_analyze_obj) },
|
||||
#ifdef CONFIG_THREAD_ANALYZER
|
||||
{ MP_ROM_QSTR(MP_QSTR_thread_analyze), MP_ROM_PTR(&mod_thread_analyze_obj) },
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_NET_SHELL
|
||||
|
@ -50,10 +50,9 @@ CONFIG_NET_DHCPV4=y
|
||||
# Diagnostics and debugging
|
||||
|
||||
# Required for zephyr.stack_analyze()
|
||||
CONFIG_INIT_STACKS=y
|
||||
CONFIG_THREAD_MONITOR=y
|
||||
CONFIG_THREAD_ANALYZER=y
|
||||
CONFIG_THREAD_ANALYZER_USE_PRINTK=y
|
||||
CONFIG_THREAD_NAME=y
|
||||
CONFIG_THREAD_STACK_INFO=y
|
||||
|
||||
# Required for usocket.pkt_get_info()
|
||||
CONFIG_NET_BUF_POOL_USAGE=y
|
||||
|
Loading…
x
Reference in New Issue
Block a user