ftrace
also: function tracer, tracefs
ftrace is a kernel tracer that dynamically instruments Linux kernel functions to capture real-time execution traces for performance analysis and debugging without recompiling the kernel.
ftrace (function tracer) is a powerful tracing framework built into the Linux kernel that allows you to monitor function calls, trace execution flow, and measure timing information at runtime. It works by inserting lightweight instrumentation points into kernel functions, making it ideal for diagnosing performance bottlenecks and understanding kernel behavior.
ftrace provides several tracers including function (traces all kernel functions), function_graph (shows call graphs with timing), and events (traces kernel events). You interact with ftrace through the tracefs filesystem, typically mounted at /sys/kernel/debug/tracing.
Example: To trace all function calls for 5 seconds, you might enable the tracer, wait, then read the trace buffer:
echo function > /sys/kernel/debug/tracing/current_tracer
sleep 5
cat /sys/kernel/debug/tracing/traceTools like trace-cmd and kernelshark provide user-friendly interfaces to ftrace, while perf offers complementary profiling capabilities.