Linux Kernel/Ftrace

From Software Engineers Wiki
Jump to: navigation, search

How to use ftrace?

Answer

ftrace is enabled by following kernel option.

CONFIG_FUNCTION_TRACER

This creates tracer directory under debugfs.

Trace buffer is mostly implemented as a ring buffer, allocated per CPU.

ftrace entry can also be added in the user space too by directly writing to trace_marker debugfs file.

# # mount | grep debugfs                 
debugfs /sys/kernel/debug debugfs rw,seclabel,relatime,mode=755 0 0
# cd /sys/kernel/debug/tracing
# echo "hello" > trace_marker
# cat trace
# tracer: nop
#
# entries-in-buffer/entries-written: 11/11   #P:6
#
#                              _-----=> irqs-off
#                             / _----=> need-resched
#                            | / _---=> hardirq/softirq
#                            || / _--=> preempt-depth
#                            ||| /     delay
#           TASK-PID   CPU#  ||||    TIMESTAMP  FUNCTION
#              | |       |   ||||       |         |
              sh-5060  [005] ...1 243437.445577: tracing_mark_write: hello

Reference

Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox