Notes about ftrace.

建议先阅读下使用 ftrace 来跟踪系统问题 - ftrace 介绍.

1. Introduction

ftrace is an internal tracer designed to help out developers and designers of systems to find what is going on inside the kernel. It can be used for debugging or analyzing latencies and performance issues that take place outside of user-space.

Although ftrace is typically considered the function tracer, it is really a frame work of several assorted tracing utilities. There’s latency tracing to examine what occurs between interrupts disabled and enabled, as well as for preemption and from a time a task is woken to the task is actually scheduled in.

One of the most common uses of ftrace is the event tracing. Through out the kernel is hundreds of static event points that can be enabled via the tracefs file system to see what is going on in certain parts of the kernel.

2. Tracers

2.1 function

1
2
3
4
5
6
cd /sys/kernel/debug/tracing
echo 0 > tracing_on
echo __do_fault > set_ftrace_filter
echo function > current_tracer
echo 1 > tracing_on
cat trace

2.2 function_graph

1
2
3
4
5
6
cd /sys/kernel/debug/tracing
echo 0 > tracing_on
echo __do_fault > set_graph_function
echo function_graph > current_tracer
echo 1 > tracing_on
cat trace

2.3 blk

2.4 hwlat

2.5 irqsoff

2.6 preemptoff

2.7 preemptirqsoff

2.8 wakeup

2.9 wakeup_rt

2.10 wakeup_dl

2.11 mmiotrace

2.12 branch

2.13 nop

3. Examples of using the tracer

Examples of using the tracer

4. How userspace can interact with ftrace

Debugging the kernel using Ftrace - part 2
Single thread tracing

1
2
3
sudo cat /sys/kernel/debug/tracing/available_events
sudo cat /sys/kernel/debug/tracing/available_filter_functions
sudo cat /sys/kernel/debug/tracing/available_tracers