Overview

Ftrace is an internal tracer designed to help out developers and designers of systems to find what is going on inside the kernel. It can be used for debugging or analyzing latencies and performance issues that take place outside of user-space.

Although ftrace is the function tracer, it also includes an infrastructure that allows for other types of tracing. Some of the tracers that are currently in ftrace include a tracer to trace context switches, the time it takes for a high priority task to run after it was woken up, the time interrupts are disabled, and more (ftrace allows for tracer plugins, which means that the list of tracers can always grow).

Project Information

Installation Instructions

Linaro hwpack kernels comes with ftrace configured, so there is no need to install/configure ftrace for Linaro images.

Using ftrace

Ftrace uses the debugfs file system to hold the control files as well as the files to display output. debugfs is usually mounted in /sys/kernel/debug and the ftrace files are kept in /sys/kernel/debug/tracing directory.

There are a number of tracers available with ftrace.To find out which tracers are available, simply cat the available_tracers file in the tracing directory:

# cd /sys/kernel/debug/tracing/
# cat available_tracers 
function nop

To enable, for example, the function tracer, just echo "function" into the current_tracer file.

# echo function > current_tracer
# cat current_tracer
function

Using a tracer

At this point Ftrace is ready to trace the function, to start it just echo 1 in the tracing_on file

# echo 1 > tracing_on

To stop the trace, just echo 0 in the same file:

# echo 0 > tracing_on

The trace is contained in the trace file, here is an example of the output from a function trace. The header helps to decode the various fields in the trace.

# head trace
# tracer: function
#
#           TASK-PID    CPU#    TIMESTAMP  FUNCTION
#              | |       |          |         |
       kjournald-741   [001]   866.002777: mempool_alloc_slab <-mempool_alloc
       kjournald-741   [001]   866.002777: kmem_cache_alloc <-mempool_alloc
       kjournald-741   [001]   866.002777: bio_init <-bio_alloc_bioset
       kjournald-741   [001]   866.002777: submit_bio <-submit_bh
       kjournald-741   [001]   866.002777: add_preempt_count <-submit_bio
       kjournald-741   [001]   866.002777: sub_preempt_count <-submit_bio

Pointers

  • In kernel source directory: Documentation/trace/ftrace.txt and Documentation/trace/ftrace-design.txt
  • Ken Werner's wiki page


CategoryHowTo

Platform/DevPlatform/Tools/Ftrace (last modified 2011-09-01 03:45:20)