Subsys: Tracing¶
1 功能概述¶
Zephyr 提供了一个调试跟踪子系统(Tracing Subsystem),可以将 OS 线程调度、内核服务等信息输出至串口或专用工具中供调试分析。
本例程演示:
将 Zephyr 跟踪信息输出至 UART(对应配置
prj_uart.conf
)将 App 自定义的跟踪信息输出至 UART(对应配置
prj_user.conf
)将 Zephyr 跟踪信息通过 JLink SWD 输出至 Segger SystemView 上位机软件(对应配置
prj_sysview.conf
)
2 环境要求¶
Board: pan108xxa1_evb / pan108xxa3_evb / pan108xxb1_evb / pan108xxb5_evb
UART: 将 P00 与 TX0 引脚接在一起,P01 与 RX0 引脚接在一起,在 PC 上打开终端工具(如 SecureCRT),波特率设置为 921600
PC 上位机软件 Segger SystemView
注:本软件为收费软件,可以非商业试用,请自行从 Segger 官网下载
3 编译和烧录¶
例程位置:zephyr\samples_panchip\subsys\tracing
使用 ZAL 工具可以对其进行编译、烧录、打开 VS Code 调试等操作。关于 ZAL 工具的详细介绍请参考:Zephyr APP Launcher 工具介绍。
4 演示说明¶
4.1 将 Zephyr 跟踪信息输出至 UART¶
在 ZAL 工具的 Config 下拉菜单中选择名为
prj_uart.conf
的配置文件,然后编译并下载程序程序下载后,可以从 UART 串口上看到如下的 Log 打印信息:
Try to load HW calibration data.. DONE. - Chip Type : 0x80 - Chip CP Version : None - Chip FT Version : 5 - Chip MAC Address : D0000C029382 - Chip Flash UID : 31373237300A44594330FFFFFFFFFFFF - Chip Flash Size : 1024 KB *** Booting Zephyr OS build zephyr-v2.7.0-1633-gc485e109 *** thread_a: Hello World from pan108xxb5_evb! sys_trace_k_timer_init: 0x200002d0 sys_trace_k_timer_start: 0x200002d0, duration: 0, period: 1000 sys_trace_k_thread_create: 0x20000220 sys_trace_k_thread_start: 0x20000220 sys_trace_k_thread_sched_ready: 0x20000220 sys_trace_k_thread_name_set: 0x20000220 sys_trace_k_thread_create: 0x200000c0 sys_trace_k_thread_sched_lock sys_trace_k_thread_start: 0x200000c0 sys_trace_k_thread_sched_ready: 0x200000c0 sys_trace_k_thread_sched_unlock sys_trace_k_thread_switched_out: 0x200003b8 sys_trace_k_thread_switched_in: 0x200003b8 sys_trace_k_thread_sched_abort: 0x200003b8 sys_trace_k_thread_switched_out: 0x200003b8 sys_trace_k_thread_switched_in: 0x200000c0 sys_trace_k_thread_create: 0x20000170 sys_trace_k_thread_start: 0x20000170 sys_trace_k_thread_sched_ready: 0x20000170 sys_trace_k_thread_name_set: 0x20000170 sys_trace_k_sem_take_enter: 0x20000090, timeout: 4294967295 sys_trace_k_sem_take_exit: 0x20000090, timeout: 4294967295 sys_trace_k_thread_sleep_enter sys_trace_k_thread_sched_suspend: 0x200000c0 sys_trace_k_thread_switched_out: 0x200000c0 sys_trace_k_thread_switched_in: 0x20000170 sys_trace_k_sem_take_enter: 0x200000a0, timeout: 4294967295 sys_trace_k_sem_take_blocking: 0x200000a0, timeout: 4294967295 sys_trace_k_thread_sched_pend: 0x20000170 sys_trace_k_thread_switched_out: 0x20000170 sys_trace_k_thread_switched_in: 0x20000220 sys_trace_k_thread_switched_out: 0x20000220 sys_trace_k_timer_start: 0x200002d0, duration: 0, period: 1000 sys_trace_k_thread_switched_in: 0x20000308 sys_trace_idle sys_trace_k_sem_give_enter: 0x200000b0 sys_trace_k_thread_sched_ready: 0x20000220 sys_trace_k_thread_switched_out: 0x20000308 sys_trace_k_thread_switched_in: 0x20000220 sys_trace_k_thread_switched_out: 0x20000220 sys_trace_k_timer_start: 0x200002d0, duration: 0, period: 1000 sys_trace_k_thread_switched_in: 0x20000308 sys_trace_idle sys_trace_k_sem_give_enter: 0x200000b0 sys_trace_k_thread_sched_ready: 0x20000220 sys_trace_k_thread_switched_out: 0x20000308 sys_trace_k_thread_switched_in: 0x20000220 sys_trace_k_thread_switched_out: 0x20000220 sys_trace_k_timer_start: 0x200002d0, duration: 0, period: 1000 sys_trace_k_thread_switched_in: 0x20000308 sys_trace_idle sys_trace_k_sem_give_enter: 0x200000b0 sys_trace_k_thread_sched_ready: 0x20000220 sys_trace_k_thread_switched_out: 0x20000308 sys_trace_k_thread_switched_in: 0x20000220 sys_trace_k_thread_switched_out: 0x20000220 sys_trace_k_timer_start: 0x200002d0, duration: 0, period: 1000 sys_trace_k_thread_switched_in: 0x20000308 sys_trace_idle sys_trace_k_sem_give_enter: 0x200000b0 sys_trace_k_thread_sched_ready: 0x20000220 sys_trace_k_thread_switched_out: 0x20000308 sys_trace_k_thread_switched_in: 0x20000220 thread_b: Hello World from pan108xxb5_evb! sys_trace_k_thread_switched_out: 0x20000220 sys_trace_k_timer_start: 0x200002d0, duration: 0, period: 1000 sys_trace_k_thread_switched_in: 0x20000308 sys_trace_idle sys_trace_k_thread_sched_resume: 0x200000c0 sys_trace_k_thread_sched_ready: 0x200000c0 sys_trace_k_thread_switched_out: 0x20000308 sys_trace_k_thread_switched_in: 0x200000c0 sys_trace_k_thread_sleep_exit sys_trace_k_sem_give_enter: 0x200000a0 sys_trace_k_thread_sched_ready: 0x20000170 sys_trace_k_sem_take_enter: 0x20000090, timeout: 4294967295 sys_trace_k_sem_take_blocking: 0x20000090, timeout: 4294967295 sys_trace_k_thread_sched_pend: 0x200000c0 sys_trace_k_thread_switched_out: 0x200000c0 sys_trace_k_thread_switched_in: 0x20000170 sys_trace_k_sem_take_exit: 0x200000a0, timeout: 4294967295 sys_trace_k_thread_sleep_enter sys_trace_k_thread_sched_suspend: 0x20000170 sys_trace_k_thread_switched_out: 0x20000170 sys_trace_k_thread_switched_in: 0x20000308 sys_trace_idle sys_trace_k_sem_give_enter: 0x200000b0 sys_trace_k_thread_sched_ready: 0x20000220 sys_trace_k_thread_switched_out: 0x20000308 sys_trace_k_thread_switched_in: 0x20000220 sys_trace_k_thread_switched_out: 0x20000220 sys_trace_k_timer_start: 0x200002d0, duration: 0, period: 1000 sys_trace_k_thread_switched_in: 0x20000308 sys_trace_idle sys_trace_k_sem_give_enter: 0x200000b0 sys_trace_k_thread_sched_ready: 0x20000220 sys_trace_k_thread_switched_out: 0x20000308 sys_trace_k_thread_switched_in: 0x20000220 sys_trace_k_thread_switched_out: 0x20000220 sys_trace_k_timer_start: 0x200002d0, duration: 0, period: 1000 sys_trace_k_thread_switched_in: 0x20000308 sys_trace_idle sys_trace_k_sem_give_enter: 0x200000b0 sys_trace_k_thread_sched_ready: 0x20000220 sys_trace_k_thread_switched_out: 0x20000308 sys_trace_k_thread_switched_in: 0x20000220 sys_trace_k_thread_switched_out: 0x20000220 sys_trace_k_timer_start: 0x200002d0, duration: 0, period: 1000 sys_trace_k_thread_switched_in: 0x20000308 sys_trace_idle sys_trace_k_sem_give_enter: 0x200000b0 sys_trace_k_thread_sched_ready: 0x20000220 sys_trace_k_thread_switched_out: 0x20000308 sys_trace_k_thread_switched_in: 0x20000220 sys_trace_k_thread_switched_out: 0x20000220 sys_trace_k_timer_start: 0x200002d0, duration: 0, period: 1000 sys_trace_k_thread_switched_in: 0x20000308 sys_trace_idle sys_trace_k_sem_give_enter: 0x200000b0 sys_trace_k_thread_sched_ready: 0x20000220 sys_trace_k_thread_switched_out: 0x20000308 sys_trace_k_thread_switched_in: 0x20000220 thread_a: Hello World from pan108xxb5_evb!
4.2 将 App 自定义的跟踪信息输出至 UART¶
在 ZAL 工具的 Config 下拉菜单中选择名为
prj_user.conf
的配置文件,然后编译并下载程序程序下载后,可以从 UART 串口上看到如下的 Log 打印信息:
Try to load HW calibration data.. DONE. - Chip Type : 0x80 - Chip CP Version : None - Chip FT Version : 5 - Chip MAC Address : D0000C029382 - Chip Flash UID : 31373237300A44594330FFFFFFFFFFFF - Chip Flash Size : 1024 KB sys_trace_thread_switched_in_user: 0x200002c0 *** Booting Zephyr OS build zephyr-v2.7.0-1645-g59b7fad8 *** sys_trace_thread_switched_out_user: 0x200002c0 sys_trace_thread_switched_in_user: 0x200002c0 sys_trace_thread_switched_out_user: 0x200002c0 sys_trace_thread_switched_in_user: 0x200000b0 thread_a: Hello World from pan108xxb5_evb! sys_trace_thread_switched_out_user: 0x200000b0 sys_trace_thread_switched_in_user: 0x20000160 sys_trace_thread_switched_out_user: 0x20000160 sys_trace_thread_switched_in_user: 0x20000210 sys_trace_idle_user sys_trace_idle_user sys_trace_thread_switched_out_user: 0x20000210 sys_trace_thread_switched_in_user: 0x200000b0 sys_trace_thread_switched_out_user: 0x200000b0 sys_trace_thread_switched_in_user: 0x20000160 thread_b: Hello World from pan108xxb5_evb! sys_trace_thread_switched_out_user: 0x20000160 sys_trace_thread_switched_in_user: 0x20000210 sys_trace_idle_user sys_trace_idle_user sys_trace_thread_switched_out_user: 0x20000210 sys_trace_thread_switched_in_user: 0x20000160 sys_trace_thread_switched_out_user: 0x20000160 sys_trace_thread_switched_in_user: 0x200000b0 thread_a: Hello World from pan108xxb5_evb! sys_trace_thread_switched_out_user: 0x200000b0 sys_trace_thread_switched_in_user: 0x20000210 sys_trace_idle_user sys_trace_idle_user sys_trace_thread_switched_out_user: 0x20000210 sys_trace_thread_switched_in_user: 0x200000b0 sys_trace_thread_switched_out_user: 0x200000b0 sys_trace_thread_switched_in_user: 0x20000160 thread_b: Hello World from pan108xxb5_evb!
4.3 将 Zephyr 跟踪信息通过 JLink SWD 输出至 Segger SystemView 上位机软件¶
在 ZAL 工具的 Config 下拉菜单中选择名为
prj_sysview.conf
的配置文件,然后编译并下载程序程序下载后,发现 UART 串口上可以正常看到 App Log 打印信息,此时不要断开 JLink 与 SoC 的 SWD 连接
在编译工具链 Toolchain 目录下的 JLink-V644b 子目录中,将其中的
Devices
目录、以及JLinkARM.dll
、JLink_x64.dll
、JLinkDevices.xml
等三个文件一起拷贝至 SystemView 软件的安装目录下:完成后,点击
SystemViewer.exe
进入软件主界面:在主界面上点击菜单
Target
-Recorder Configuration
,然后在弹出的 Recorder 界面选择J-Link
:在弹出的 JLink 配置界面中,按照如下的方式进行配置:
在主界面上点击菜单
Target
-Start Recording
,或者直接点击工具栏的 Start 按钮,开始跟踪程序:
5 开发说明¶
Zephyr Tracing 机制主要用在程序的开发阶段,对系统进行跟踪调试,因此基本没有额外的代码需要编写,只需要根据需求开启对应的 Kconfig 配置即可
关于 Zephyr Tracing 机制更详细的介绍请参考 Zephyr Project 官方文档:User and Developer Guides - Tracing
6 RAM/Flash资源使用情况¶
Memory region Used Size Region Size %age Used
FLASH: 16884 B 384 KB 4.29%
SRAM: 6712 B 64 KB 10.24%