ftrace (Function Tracer) is a
tracing framework for the
Linux kernel
The Linux kernel is a Free and open-source software, free and open source Unix-like kernel (operating system), kernel that is used in many computer systems worldwide. The kernel was created by Linus Torvalds in 1991 and was soon adopted as the k ...
. Although its original name, Function Tracer, came from ftrace's ability to record information related to various
function call
In computer programming, a function (also procedure, method, subroutine, routine, or subprogram) is a callable unit of software logic that has a well-defined interface and behavior and can be invoked multiple times.
Callable units provide a p ...
s performed while the
kernel is running, ftrace's tracing capabilities cover a much broader range of kernel's internal operations.
Details
With its various tracer plugins, ftrace can be targeted at different static tracepoints, such as
scheduling
A schedule (, ) or a timetable, as a basic time-management tool, consists of a list of times at which possible tasks, events, or actions are intended to take place, or of a sequence of events in the chronological order in which such things ...
events,
interrupt
In digital computers, an interrupt (sometimes referred to as a trap) is a request for the processor to ''interrupt'' currently executing code (when permitted), so that the event can be processed in a timely manner. If the request is accepted ...
s,
memory-mapped I/O
Memory-mapped I/O (MMIO) and port-mapped I/O (PMIO) are two complementary methods of performing input/output (I/O) between the central processing unit (CPU) and peripheral devices in a computer (often mediating access via chipset). An altern ...
,
CPU power state transitions, and operations related to
file systems and
virtualization
In computing, virtualization (abbreviated v12n) is a series of technologies that allows dividing of physical computing resources into a series of virtual machines, operating systems, processes or containers.
Virtualization began in the 1960s wit ...
. Also, dynamic tracking of kernel function calls is available, optionally restrictable to a subset of
functions by using
globs, and with the possibility to generate
call graph
A call graph (also known as a call multigraph) is a control-flow graph, which represents calling relationships between subroutines in a computer program. Each node represents a procedure and each edge ''(f, g)'' indicates that procedure ''f'' c ...
s and provide
stack
Stack may refer to:
Places
* Stack Island, an island game reserve in Bass Strait, south-eastern Australia, in Tasmania’s Hunter Island Group
* Blue Stack Mountains, in Co. Donegal, Ireland
People
* Stack (surname) (including a list of people ...
usage reports. At the same time, ftrace can be used to measure various
latencies within the Linux kernel, such as for how long interrupts or
preemption are disabled.
An ftrace-enabled Linux kernel is built by enabling the
kernel configuration option. The entire runtime interaction with ftrace is performed through readable and writable
virtual files contained in a specifically mounted
debugfs file system; as a result, ftrace requires no specialized
userspace
A modern computer operating system usually uses virtual memory to provide separate address spaces or regions of a single address space, called user space and kernel space. This separation primarily provides memory protection and hardware prote ...
utilities to operate.
However, there are additional userspace utilities that provide more advanced features for data recording, analysis and visualization; examples of such utilities are ''trace-cmd'' and ''KernelShark''.
Internally, ftrace relies on the
gcc's
profiling mechanism to prepend
machine instruction
In computer programming, machine code is computer code consisting of machine language instructions, which are used to control a computer's central processing unit (CPU). For conventional binary computers, machine code is the binaryOn nonbi ...
s to the
compiled versions of all
source-level kernel functions, which redirect the execution of functions to the ftrace's
trampolines and tracer plugins that perform the actual tracing. These "
entry point
In computer programming, an entry point is the place in a program where the execution of a program begins, and where the program has access to command line arguments.
To start a program's execution, the loader or operating system passes co ...
" instructions created by gcc are altered by ftrace when the kernel is
booted, and varied later at runtime by ftrace between
NOPs and actual
jumps to the tracing trampolines, depending on the tracing types and options configured at runtime.
ftrace is developed primarily by Steven Rostedt, and it was merged into the
Linux kernel mainline in kernel version 2.6.27, which was released on October 9, 2008.
See also
*
DTrace
DTrace is a comprehensive dynamic tracing framework originally created by Sun Microsystems for troubleshooting kernel and application problems on production systems in real time.
Originally developed for Solaris, it has since been released un ...
a tracing framework for troubleshooting kernel and application problems, originally developed for Solaris
*
ktrace a BSD Unix and Mac OS X utility that traces kernel–program interactions
*
ltrace a Linux debugging utility, displays the calls a userland application makes to shared libraries
*
strace a debugging utility for Linux and some other Unix-like systems, monitors system calls used by a program and all received signals
*
SystemTap
In computing, SystemTap () is a scripting language and tool for dynamically instrumenting running production Linux-based operating systems. System administrators can use SystemTap to extract, filter and summarize data in order to enable diagnosi ...
a scripting language and utility used for instrumenting Linux systems
References
External links
Debugging the kernel using Ftrace part 1an
part 2 LWN.net, December 2009, by Steven Rostedt
Secrets of the Ftrace function tracer LWN.net, January 20, 2010, by Steven Rostedt
Ftrace: The hidden light switch LWN.net, August 13, 2014, by Brendan Gregg
The source of the e1000e corruption bug LWN.net, October 21, 2008, by Jonathan Corbet
{{Operating system
Debugging
Free software programmed in C
Linux kernel features
Unix programming tools