Ftrace Linux Kernel Tracing: Steven Rostedt
Ftrace Linux Kernel Tracing: Steven Rostedt
Steven Rostedt
[email protected]
[email protected]
http://people.redhat.com/srostedt/
trace-tokyo-2010.odp
Who am I?
What is Ftrace?
What is Ftrace?
● Traces the internal operations of the kernel
What is Ftrace?
● Traces the internal operations of the kernel
– Static tracepoints within the kernel (event tracing)
What is Ftrace?
● Traces the internal operations of the kernel
– Static tracepoints within the kernel (event tracing)
● scheduling
● interrupts
● file systems
● virtual guest connections with host
What is Ftrace?
● Traces the internal operations of the kernel
– Dynamic kernel function tracing
What is Ftrace?
● Traces the internal operations of the kernel
– Dynamic kernel function tracing
● trace all functions within the kernel
● pick and choose what functions to trace
– less functions == less overhead
● call graphs
● stack usage
What is Ftrace?
● Traces the internal operations of the kernel
– Latency tracers
What is Ftrace?
● Traces the internal operations of the kernel
– Latency tracers
● how long interrupts are disabled
● how long preemption is disabled
● how long interrupts and/or preemption is disabled
What is Ftrace?
● Traces the internal operations of the kernel
– Latency tracers
● how long interrupts are disabled
● how long preemption is disabled
● how long interrupts and/or preemption is disabled
– Wake up latency
● how long it takes a process to run after it is woken
– All tasks
– Just RT tasks
The Debugfs
● Officially mounted at
– /sys/kernel/debug
● I prefer
– mkdir /debug
– mount -t debugfs nodev /debug
– This presentation will use /debug
● Do what you want
The Tracing Directory
# ls /debug/tracing
available_events printk_formats trace
available_filter_functions README trace_clock
available_tracers saved_cmdlines trace_marker
buffer_size_kb set_event trace_options
current_tracer set_ftrace_filter trace_pipe
dyn_ftrace_total_info set_ftrace_notrace trace_stat
events set_ftrace_pid
tracing_cpumask failures
set_graph_function tracing_enabled
function_profile_enabled stack_max_size
tracing_max_latency options stack_trace
tracing_on per_cpu
tracing_thresh
Tracer Plugins
● Found in available_tracers
– function
– function_graph
– wakeup and wakeup_rt
– irqsoff, preemptoff, preemtirqsoff
– mmiotrace
– sched_switch
– nop
The Function Tracer
git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/trace-cmd.git
trace-cmd
● binary tool to read Ftrace's buffers
– Records into a trace.dat file for later reads
– Reads the trace.dat file
● Can record on big endian, read in little, and vice versa
– Reads the raw buffers using splice
– Will automatically mount debugfs if it is not
mounted
● Must have root access (sudo)
trace-cmd record
● Default, writes to “trace.dat”
[root@frodo ~]# trace-cmd record -e sched ls -ltr /usr > /dev/null
disable all
enable sched
offset=2f2000
offset=2f4000
[root@frodo ~]# trace-cmd record -o func.dat -p function ls -ltr /usr > /dev/null
plugin function
disable all
offset=2f2000
offset=412000
[root@frodo ~]# trace-cmd record -o fgraph.dat -p function_graph ls -ltr /usr \
> /dev/null
plugin function_graph
disable all
offset=2f2000
offset=460000
[root@frodo ~]# trace-cmd record -o fgraph-events.dat -e sched -p function_graph \
ls -ltr /usr > /dev/null
plugin function_graph
disable all
enable sched
offset=2f2000
offset=461000
Filters, and Options
[root@frodo ~]# trace-cmd record -e sched_switch -f 'prev_prio < 100'
● -f : filter
● -O : option
● -g : same as echoing into set_graph_function
● -l : same as echoing into set_ftrace_filter
● -n : same as echoing into set_ftrace_notrace
trace-cmd report
● Default, reads from “trace.dat”
[root@frodo ~]# trace-cmd report | head -15
version = 6
cpus=2
trace-cmd-6157 [000] 83.713584: sched_stat_runtime: task: trace-cmd:61
trace-cmd-6157 [000] 83.713591: sched_switch: 6157:120:S ==> 0:1
<idle>-0 [000] 83.713646: sched_stat_wait: task: trace-cmd:61
<idle>-0 [000] 83.713648: sched_switch: 0:120:R ==> 6158:1
ls-6158 [001] 83.713934: sched_wakeup: 6158:?:? + 5900:
ls-6158 [001] 83.713935: sched_stat_runtime: task: trace-cmd:61
ls-6158 [001] 83.713937: sched_stat_runtime: task: trace-cmd:61
ls-6158 [001] 83.713938: sched_switch: 6158:120:R ==> 590
migration/1-5900 [001] 83.713941: sched_stat_wait: task: trace-cmd:61
migration/1-5900 [001] 83.713942: sched_migrate_task: task trace-cmd:615
migration/1-5900 [001] 83.713947: sched_switch: 5900:0:S ==> 0:120
ls-6158 [000] 83.714067: sched_stat_runtime: task: ls:6158 runt
ls-6158 [000] 83.714636: sched_stat_runtime: task: ls:6158 runt
trace-cmd report (continued)
Demo!
Questions?
Questions?