Debugging Linux Kernel using ftrace Part1 - Introduction
What is Tracing?
From Wikipedia, tracing is specialized use of logging to record information about program's execution. This logged information is used by programmers for debugging.
What is ftrace?
ftrace stands for function tracer. ftrace allows you to trace kernel function calls (entry and exit of function calls).
What can we do using ftrace?
From Wikipedia, tracing is specialized use of logging to record information about program's execution. This logged information is used by programmers for debugging.
What is ftrace?
ftrace stands for function tracer. ftrace allows you to trace kernel function calls (entry and exit of function calls).
What can we do using ftrace?
- Debugging Linux Kernel
- Analyzing Latencies in Linux Kernel
- Learn and observe the flow of Linux Kernel
- Trace context switches
- Length of the time the interrupts are disabled
What is the minimum kernel configuration required for ftrace?
- CONFIG_FTRACE --> "Tracers"
- CONFIG_FUNCTION_TRACER --> Kernel Function Tracer
- CONFIG_FUNCTION_GRAPH_TRACER --> Kernel Function Graph Tracer
- CONFIG_DYNAMIC_TRACEV --> Enable/Disable ftrace dynamically
How to check whether ftrace is already enabled or not?
Most of the Linux distributions already provide ftrace, to check verify "tracing" directory exists or not.
# ls /sys/kernel/tracing
mount the tracefs by any of the two steps:
1. Adding an entry into /etc/fstab:
tracefs /sys/kernel/tracing tracefs defaults 0 0
2. Using the mount command:
#mount -t tracefs nodev /sys/kernel/tracing
After mounting tracefs, you will have access to the control and output files of ftrace.
Important files of this directory:
- available_tracers --> Lists what all tracers have been enabled in the kernel configuration
- current_tracer --> The tracer currently is running
- trace -> Contains the tracing data in human readable format
- tracing_on -> Enable/disable writing tracing data to ring buffer ( ftrace uses a separate ring buffer to store tracing data)
You can see the "cat current_tracer" returns "nop". nop is the simplest tracer, which doesn't do anything.
Comments
Post a Comment