Ftrace
zhilu.zhang
zhilu.zhang
发布于 2022-11-15 / 47 阅读 / 0 评论 / 0 点赞

Ftrace

一、配置打开Ftrace功能

  1. 打开ftrace的配置宏

diff --git a/arch/arm64/configs/j5_dvb_bringup_defconfig b/arch/arm64/configs/j5_dvb_bringup_defconfig
index 5928570672f6..675469ed8079 100644
--- a/arch/arm64/configs/j5_dvb_bringup_defconfig
+++ b/arch/arm64/configs/j5_dvb_bringup_defconfig
@@ -558,3 +558,8 @@ CONFIG_MEMTEST=y
 # CONFIG_ARCH_RANDOM is not set
 # CONFIG_ARM64_AS_HAS_MTE is not set
 # CONFIG_ARM64_MTE is not set
+CONFIG_FTRACE=y
+CONFIG_FUNCTION_TRACER=y
+CONFIG_FUNCTION_GRAPH_TRACER=y
+CONFIG_STACK_TRACER=y
+CONFIG_DYNAMIC_FTRACE=y

二、Tracing文件系统介绍

内容来自:https://www.kernel.org/doc/Documentation/trace/ftrace.txt

  • current_tracer,设置和查看当前的tracer。

  • available_tracers,查看所支持的tracer。

  • tracing_on,开关trace。

  • trace,cat trace的信息。

  • trace_pipe,

  • trace_options,

  • options

    • annotate

  • set_ftrace_filter,查看和设置要跟踪的函数。

  • set_ftrace_notrace,查看和设置不跟踪的函数。

  • set_ftrace_pid,查看和设置需要跟踪的pid。

  • set_event_pid,

二、使用示例

只查看hobot_mipihost函数的调用情况

命令:

root@j5dvb:/sys/kernel/debug/tracing# echo 0 > tracing_on 
root@j5dvb:/sys/kernel/debug/tracing# cat available_tracers
function_graph function nop
root@j5dvb:/sys/kernel/debug/tracing# echo function_graph > current_tracer
root@j5dvb:/sys/kernel/debug/tracing# cat current_tracer
function_graph
root@j5dvb:/sys/kernel/debug/tracing# echo ":mod:hobot_mipihost" > set_ftrace_filter
root@j5dvb:/sys/kernel/debug/tracing# echo > trace
root@j5dvb:/sys/kernel/debug/tracing# echo 1 > tracing_on
root@j5dvb:/sys/kernel/debug/tracing# 
root@j5dvb:/sys/kernel/debug/tracing# cat trace
  • echo ":mod:hobot_mipihost" > set_ftrace_filter只跟踪hobot_mipihost module的函数

  • echo "*open*:mod:hobot_mipihost" > set_ftrace_filter只跟踪hobot_mipihost module的*open*函数

  • echo "!*open*:mod:hobot_mipihost" >> set_ftrace_filter删除对hobot_mipihost module *open*函数的跟踪

  • echo "!*:mod:hobot_mipihost" >> set_ftrace_filter禁止对hobot_mipihost module之外的函数跟踪

  • echo "!*:mod:*" >> set_ftrace_filter禁用所有模块的跟踪,但仍跟踪内核:

演示:

image (12).png跟踪mipihost和cim_dma的调用情况

命令:

root@j5dvb:/sys/kernel/debug/tracing# echo 0 > tracing_on 
root@j5dvb:/sys/kernel/debug/tracing# cat available_tracers
function_graph function nop
root@j5dvb:/sys/kernel/debug/tracing# echo function_graph > current_tracer
root@j5dvb:/sys/kernel/debug/tracing# cat current_tracer
function_graph
root@j5dvb:/sys/kernel/debug/tracing# echo ":mod:hobot_mipihost" > set_ftrace_filter
root@j5dvb:/sys/kernel/debug/tracing# echo ":mod:hobot_cim_dma" >> set_ftrace_filter
root@j5dvb:/sys/kernel/debug/tracing# echo > trace
root@j5dvb:/sys/kernel/debug/tracing# echo 1 > tracing_on
root@j5dvb:/sys/kernel/debug/tracing# 
root@j5dvb:/sys/kernel/debug/tracing# cat trace
  • echo ":mod:hobot_mipihost" > set_ftrace_filter设置hobot_mipihost module跟踪

  • echo ":mod:hobot_cim_dma" >> set_ftrace_filter追加设置hobot_cim_dma module跟踪

演示:

image (13).pngFtrace vps

trace/app/bin/vps/vpm/vio_test_case.sh cicd_sen_cimdma_ddr_isp0_pym0_4k_ar0820程序对vps相关模块函数的调用关系。

echo 0 > tracing_on 
cat available_tracers
function_graph function nop
echo function_graph > current_tracer
cat current_tracer
function_graph
echo 102400 > buffer_size_kb
echo ":mod:hobot_mipihost" > set_ftrace_filter
echo ":mod:hobot_mipidev" >> set_ftrace_filter
echo ":mod:hobot_mipidphy" >> set_ftrace_filter
echo ":mod:hobot_cim_dma" >> set_ftrace_filter
echo ":mod:hobot_cim" >> set_ftrace_filter
echo ":mod:hobot_videostitch" >> set_ftrace_filter
echo ":mod:hobot_gdc" >> set_ftrace_filter
echo ":mod:hobot_pym_jplus" >> set_ftrace_filter
echo ":mod:hobot_sensor" >> set_ftrace_filter
echo ":mod:hobot_camsys" >> set_ftrace_filter
echo ":mod:hobot_vio_common" >> set_ftrace_filter
echo > trace
echo 1 > tracing_on
/app/bin/vps/vpm/vio_test_case.sh cicd_sen_cimdma_ddr_isp0_pym0_4k_ar0820
cat trace > /userdata/trace.txt

三、trace文件分析工具

Google trace viewer

地址:https://chrome://tracing/

Google perfetto

地址:https://ui.perfetto.dev/

扩展

ftrace

trace-cmd

kernelshark