ftrace

{{short description|Tracing utility for Linux kernel}}

{{Lowercase title}}

{{Use mdy dates|date=August 2014}}

{{Infobox software

| name = ftrace

| logo =

| screenshot =

| caption =

| collapsible =

| author =

| developer = Steven Rostedt and others

| released = {{Start date and age|2008|10|09}}

| latest release version =

| latest release date =

| latest preview version =

| latest preview date =

| programming language =

| operating system = Linux

| platform =

| size =

| language =

| status =

| genre = Kernel extension

| license = GNU GPL version 2{{cite web

| url = https://www.kernel.org/pub/linux/kernel/COPYING

| title = Linux kernel source: kernel/COPYING file

| date = March 13, 1994 | access-date = June 11, 2016

| website = kernel.org

}}

| website = {{URL|https://www.kernel.org/doc/html/latest/trace/index.html}}

}}

ftrace (Function Tracer) is a tracing framework for the Linux kernel. Although its original name, Function Tracer, came from ftrace's ability to record information related to various function calls performed while the kernel is running, ftrace's tracing capabilities cover a much broader range of kernel's internal operations.{{cite web

| url = https://lwn.net/Articles/322666/

| title = A look at ftrace

| date = March 13, 2009 | access-date = July 23, 2014

| author = Jake Edge | publisher = LWN.net

}}{{cite web

| url = https://www.kernel.org/doc/Documentation/trace/ftrace.txt

| title = Linux kernel documentation: Documentation/trace/ftrace.txt

| date = June 16, 2014 | access-date = July 23, 2014

| author = Steven Rostedt | publisher = kernel.org

}}

Details

With its various tracer plugins, ftrace can be targeted at different static tracepoints, such as scheduling events, interrupts, memory-mapped I/O, CPU power state transitions, and operations related to file systems and virtualization. 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 graphs and provide stack 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.{{cite web

| url = https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_MRG/2/html/Realtime_Tuning_Guide/sect-Realtime_Tuning_Guide-Realtime_Specific_Tuning-Using_the_ftrace_Utility_for_Tracing_Latencies.html

| title = Red Hat Enterprise MRG 2 documentation, Section 3.8. Using the ftrace utility for tracing latencies

| date = May 23, 2014 | access-date = July 24, 2014

| publisher = Red Hat

}}{{cite web

| url = https://events.linuxfoundation.org/slides/2010/linuxcon_japan/linuxcon_jp2010_rostedt.pdf

| title = Ftrace: Linux Kernel Tracing

| date = October 18, 2010

| access-date = July 23, 2014

| author = Steven Rostedt

| website = linuxfoundation.org

| archive-url = https://web.archive.org/web/20130308164230/http://events.linuxfoundation.org/slides/2010/linuxcon_japan/linuxcon_jp2010_rostedt.pdf

| archive-date = March 8, 2013

}}{{rp|3–11,14,18}}

An ftrace-enabled Linux kernel is built by enabling the {{Mono|CONFIG_FUNCTION_TRACER}} 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 utilities to operate.{{cite web

| url = https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Developer_Guide/ftrace.html

| title = Red Hat Enterprise Linux 6 documentation, Section 6.5. ftrace

| date = March 14, 2014 | access-date = July 23, 2014

| publisher = Red Hat

}} 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.{{rp|31–47}}{{cite web

| url = https://lwn.net/Articles/410200/

| title = trace-cmd: A front-end for Ftrace

| date = October 20, 2010 | access-date = January 19, 2015

| author = Steven Rostedt | publisher = LWN.net

}}{{cite web

| url = https://lwn.net/Articles/425583/

| title = Using KernelShark to analyze the real-time scheduler

| date = February 2, 2011 | access-date = June 11, 2016

| author = Steven Rostedt | publisher = LWN.net

}}

Internally, ftrace relies on the gcc's profiling mechanism to prepend machine instructions 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" 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.{{cite web

| url = http://www.linuxplumbersconf.org/2014/ocw/system/presentations/1773/original/ftrace-kernel-hooks-2014.pdf

| title = Ftrace Kernel Hooks: More than just tracing

| date = January 5, 2015 | access-date = June 11, 2016

| author = Steven Rostedt | website = linuxplumbersconf.org

| pages = 6–12, 24, 34, 56–58

}}{{cite web

| url = http://elinux.org/images/d/d6/Measuring-function-duration-with-ftrace.pdf

| title = Measuring Function Duration with Ftrace

| date = November 1, 2012 | access-date = June 11, 2016

| author = Tim Bird | website = elinux.org

| pages = 5–6, 12–14

}}

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.{{cite web

| url = http://kernelnewbies.org/Linux_2_6_27#head-27c23aa79ee6da975ef95b4fff381ace1667a264

| title = Linux kernel 2.6.27, Section 1.7. ftrace, sysprof support

| date = October 9, 2008 | access-date = July 23, 2014

| website = kernelnewbies.org

}}

See also

{{Portal|Computer programming|Linux}}

  • DTrace{{snd}} a tracing framework for troubleshooting kernel and application problems, originally developed for Solaris
  • ktrace{{snd}} a BSD Unix and Mac OS X utility that traces kernel–program interactions
  • ltrace{{snd}} a Linux debugging utility, displays the calls a userland application makes to shared libraries
  • strace{{snd}} a debugging utility for Linux and some other Unix-like systems, monitors system calls used by a program and all received signals
  • SystemTap{{snd}} a scripting language and utility used for instrumenting Linux systems

References

{{Reflist}}