summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaureen Helm <maureen.helm@nxp.com>2020-05-02 11:21:48 -0500
committerDamien George <damien.p.george@gmail.com>2020-06-12 10:24:01 +1000
commit38b4f1569e7755f78b991352ae5d53055ad67790 (patch)
treeedb706332b9b82ea2a15c970a50fc2223adab28a
parent05e5d411b53dcba9529b6ac1e9388bab65f8c11b (diff)
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 %)
-rw-r--r--ports/zephyr/modzephyr.c29
-rw-r--r--ports/zephyr/prj.conf5
2 files changed, 9 insertions, 25 deletions
diff --git a/ports/zephyr/modzephyr.c b/ports/zephyr/modzephyr.c
index d4ee610b2..71b44d7df 100644
--- a/ports/zephyr/modzephyr.c
+++ b/ports/zephyr/modzephyr.c
@@ -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
diff --git a/ports/zephyr/prj.conf b/ports/zephyr/prj.conf
index 993dfdc26..e6ccdadcf 100644
--- a/ports/zephyr/prj.conf
+++ b/ports/zephyr/prj.conf
@@ -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