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

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: . 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.