Monitor and optimize stack sizes using the Thread Analyzer:
Add to prj.conf:
CONFIG_THREAD_ANALYZER=y
CONFIG_THREAD_ANALYZER_USE_LOG=y
CONFIG_THREAD_ANALYZER_AUTO=y
CONFIG_THREAD_ANALYZER_AUTO_INTERVAL=30
CONFIG_THREAD_ANALYZER_AUTO_STACK_SIZE=1024
CONFIG_THREAD_NAME=y
The listed configurations configure the thread analyzer to print thread information every 30 seconds:
[00:00:30.725,463] <inf> thread_analyzer: location_api_workq : STACK: unused 376 usage 3720 / 4096 (90 %); CPU: 0 %
[00:00:30.725,494] <inf> thread_analyzer: : Total CPU cycles used: 242
[00:00:30.725,738] <inf> thread_analyzer: downloader : STACK: unused 1480 usage 184 / 1664 (11 %); CPU: 0 %
[00:00:30.725,769] <inf> thread_analyzer: : Total CPU cycles used: 0
[00:00:30.725,891] <inf> thread_analyzer: thread_analyzer : STACK: unused 480 usage 544 / 1024 (53 %); CPU: 0 %
[00:00:30.725,921] <inf> thread_analyzer: : Total CPU cycles used: 148
[00:00:30.725,982] <inf> thread_analyzer: power_task_id : STACK: unused 168 usage 1176 / 1344 (87 %); CPU: 0 %
[00:00:30.726,013] <inf> thread_analyzer: : Total CPU cycles used: 85
[00:00:30.726,104] <inf> thread_analyzer: network_module_thread_id: STACK: unused 160 usage 1504 / 1664 (90 %); CPU: 0 %
[00:00:30.726,165] <inf> thread_analyzer: : Total CPU cycles used: 2011
[00:00:30.726,257] <inf> thread_analyzer: location_module_thread_id: STACK: unused 216 usage 1000 / 1216 (82 %); CPU: 0 %
[00:00:30.726,287] <inf> thread_analyzer: : Total CPU cycles used: 185
[00:00:30.726,440] <inf> thread_analyzer: fota_task_id : STACK: unused 968 usage 1536 / 2504 (61 %); CPU: 0 %
[00:00:30.726,470] <inf> thread_analyzer: : Total CPU cycles used: 187
[00:00:30.726,562] <inf> thread_analyzer: environmental_task_id: STACK: unused 168 usage 856 / 1024 (83 %); CPU: 0 %
[00:00:30.726,593] <inf> thread_analyzer: : Total CPU cycles used: 37
[00:00:30.726,715] <inf> thread_analyzer: coap_client_recv_thread: STACK: unused 592 usage 688 / 1280 (53 %); CPU: 0 %
[00:00:30.726,745] <inf> thread_analyzer: : Total CPU cycles used: 273
[00:00:30.726,867] <inf> thread_analyzer: cloud_thread_id: STACK: unused 328 usage 3000 / 3328 (90 %); CPU: 0 %
[00:00:30.726,898] <inf> thread_analyzer: : Total CPU cycles used: 1081
[00:00:30.726,959] <inf> thread_analyzer: date_time_work_q : STACK: unused 80 usage 368 / 448 (82 %); CPU: 0 %
[00:00:30.726,989] <inf> thread_analyzer: : Total CPU cycles used: 11
[00:00:30.727,050] <inf> thread_analyzer: conn_mgr_monitor : STACK: unused 72 usage 312 / 384 (81 %); CPU: 0 %
[00:00:30.727,081] <inf> thread_analyzer: : Total CPU cycles used: 13
[00:00:30.727,203] <inf> thread_analyzer: work_q : STACK: unused 576 usage 192 / 768 (25 %); CPU: 0 %
[00:00:30.727,233] <inf> thread_analyzer: : Total CPU cycles used: 3
[00:00:30.727,294] <inf> thread_analyzer: rx_q[0] : STACK: unused 24 usage 168 / 192 (87 %); CPU: 0 %
[00:00:30.727,325] <inf> thread_analyzer: : Total CPU cycles used: 1
[00:00:30.727,386] <inf> thread_analyzer: tx_q[0] : STACK: unused 24 usage 168 / 192 (87 %); CPU: 0 %
[00:00:30.727,416] <inf> thread_analyzer: : Total CPU cycles used: 1
[00:00:30.727,539] <inf> thread_analyzer: net_mgmt : STACK: unused 504 usage 776 / 1280 (60 %); CPU: 0 %
[00:00:30.727,569] <inf> thread_analyzer: : Total CPU cycles used: 124
[00:00:30.727,783] <inf> thread_analyzer: shell_uart : STACK: unused 1312 usage 736 / 2048 (35 %); CPU: 0 %
[00:00:30.727,813] <inf> thread_analyzer: : Total CPU cycles used: 3971
[00:00:30.727,905] <inf> thread_analyzer: sysworkq : STACK: unused 400 usage 880 / 1280 (68 %); CPU: 0 %
[00:00:30.727,935] <inf> thread_analyzer: : Total CPU cycles used: 278
[00:00:30.728,027] <inf> thread_analyzer: nrf70_intr_wq : STACK: unused 120 usage 712 / 832 (85 %); CPU: 0 %
[00:00:30.728,057] <inf> thread_analyzer: : Total CPU cycles used: 806
[00:00:30.728,118] <inf> thread_analyzer: nrf70_bh_wq : STACK: unused 112 usage 656 / 768 (85 %); CPU: 0 %
[00:00:30.728,149] <inf> thread_analyzer: : Total CPU cycles used: 102
[00:00:30.728,271] <inf> thread_analyzer: logging : STACK: unused 448 usage 320 / 768 (41 %); CPU: 0 %
[00:00:30.728,302] <inf> thread_analyzer: : Total CPU cycles used: 224
[00:00:30.728,363] <inf> thread_analyzer: idle : STACK: unused 256 usage 64 / 320 (20 %); CPU: 98 %
[00:00:30.728,393] <inf> thread_analyzer: : Total CPU cycles used: 985191
[00:00:30.728,485] <inf> thread_analyzer: main : STACK: unused 208 usage 1648 / 1856 (88 %); CPU: 0 %
[00:00:30.728,515] <inf> thread_analyzer: : Total CPU cycles used: 2055
[00:00:30.728,759] <inf> thread_analyzer: ISR0 : STACK: unused 1736 usage 312 / 2048 (15 %)
For more information, see Zephyr Thread Analyzer.