Visualizing thread context switch and schedule timeline in Linux

Recently I needed to see when my threads were executing and in which processor, and

it took me a couple of days to get this done. Here is the best solution I’ve found.
First of all, we need the kernel to be compiled with some debug features enabled

http://www.mjmwired.net/kernel/Documentation/trace/ftrace.txt
https://www.kernel.org/doc/Documentation/trace/ftrace.txt

We’ll need to mount the debugfs

mount -t debugfs nodev /sys/kernel/debug

There is a front-end to the ftrace which is the trace-cmd command. It will enable the debugging features, start the tracing, and disable afterwards, and it can be really simple to use:

# trace-cmd start -e "sched:sched_switch" ./program_to_trace

After that you can use the KernelShark app to read the trace.dat file. Or you can convert it to VCD using:

# trace-cmd report > trace.txt
# sched_switch2vcd trace.txt trace.vcd

The sched_switch2vcd app is available here:  https://github.com/rsvargas/sched_switch2vcd . I like to use gtkwave to visualize the data.

Update in 2015/07/08:

 

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.