1. ftrace是什么
ftrace是内核的跟踪器。可追踪插件追踪内核事件。
ftrace的用户界面是在debugfs文件系统上生成的。多数情况下挂载到/sys/kernel/debug目录下
对应挂载命令“mount -t debugfs debugfs /sys/kernel/debug”。 ftrace目录为/sys/kernel/debug/tracing,下面有ftrace控制相关的文件。

2. 使用ftrace
使用举例如下:
a. 追踪函数调用

上面看出,进程调用程序是从几个不同的函数调用的。
b. 使用通配符追踪多个函数

上面结果记录了以irq开头的函数。
c. 追踪指定模块中的函数

d. 获取函数的调用关系

上图中使用缩进和大括号清晰的显示调用关系。
e. 函数回溯

上图中对象函数的追踪入口后面出现了,它的后面显示的是回溯的结果。
f. 进行函数概要分析

上图中,Time表示累计值,Avg表示平均值,S^2表示平均方差。其中值包含函数内休眠时间,和函数内调用其它函数的处理时间。
这此时间可以分别用options/sleep-time和options/graph-time来修正。
修正睡眠时间

修正调用其它函数的时间

g. 查找占用内核栈最大的位置

上图Depth表示该函数内最大的栈消耗量, Size表示仅该函数内的栈消耗量
h. 测量中断延迟
echo irqsoff > current_tracer
echo 1 > tracing_on
echo 0 > tracing_on
cat trace
当前环境不支持
i. 记录内核事件

上图看出,不同任务处理时发生中断
j. 查看特定中断
删除过滤如下

k. 查看可追踪事件
/sys/kernel/debug/tracing/available_events文件中的内容为可追踪事件
/sys/kernel/debug/tracing/events目录下为各追踪事件组名和事件名。如下:
阅读(1632) | 评论(0) | 转发(0) |