{"id":36,"date":"2013-07-23T13:18:43","date_gmt":"2013-07-23T16:18:43","guid":{"rendered":"http:\/\/vargolino.com\/wp\/?p=36"},"modified":"2015-07-08T18:26:08","modified_gmt":"2015-07-08T21:26:08","slug":"visualizing-thread-context-switch-and-schedule-timeline-in-linux","status":"publish","type":"post","link":"https:\/\/vargolino.com\/wp\/?p=36","title":{"rendered":"Visualizing thread context switch and schedule timeline in Linux"},"content":{"rendered":"<p>Recently I needed to see when my threads were executing and in which processor, and<\/p>\n<p>it took me a couple of days to get this done. Here is the best solution I&#8217;ve found.<br \/>\nFirst of all, we need the kernel to be compiled with some debug features enabled<\/p>\n<p><a href=\"http:\/\/www.mjmwired.net\/kernel\/Documentation\/trace\/ftrace.txt\">http:\/\/www.mjmwired.net\/kernel\/Documentation\/trace\/ftrace.txt<\/a><br \/>\n<a href=\"https:\/\/www.kernel.org\/doc\/Documentation\/trace\/ftrace.txt\">https:\/\/www.kernel.org\/doc\/Documentation\/trace\/ftrace.txt<\/a><\/p>\n<p>We&#8217;ll need to mount the debugfs<\/p>\n<pre>mount -t debugfs nodev \/sys\/kernel\/debug<\/pre>\n<p>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:<\/p>\n<pre># trace-cmd start -e \"sched:sched_switch\" .\/program_to_trace<\/pre>\n<p>After that you can use the <a href=\"http:\/\/people.redhat.com\/srostedt\/kernelshark\/HTML\/\">KernelShark<\/a> app to read the trace.dat file. Or you can convert it to VCD using:<\/p>\n<pre># trace-cmd report &gt; trace.txt\r\n#\u00a0sched_switch2vcd trace.txt trace.vcd<\/pre>\n<p>The\u00a0sched_switch2vcd app is available here: \u00a0<a href=\"https:\/\/github.com\/rsvargas\/sched_switch2vcd\" target=\"_blank\">https:\/\/github.com\/rsvargas\/sched_switch2vcd<\/a> . I like to use gtkwave to visualize the data.<\/p>\n<p>Update in 2015\/07\/08:<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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&#8217;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&#8217;ll need to mount the &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/vargolino.com\/wp\/?p=36\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Visualizing thread context switch and schedule timeline in Linux&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[14,7,9],"class_list":["post-36","post","type-post","status-publish","format-standard","hentry","category-solution","tag-debug","tag-howto","tag-linux","entry"],"_links":{"self":[{"href":"https:\/\/vargolino.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/36","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/vargolino.com\/wp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/vargolino.com\/wp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/vargolino.com\/wp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/vargolino.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=36"}],"version-history":[{"count":9,"href":"https:\/\/vargolino.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/36\/revisions"}],"predecessor-version":[{"id":101,"href":"https:\/\/vargolino.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/36\/revisions\/101"}],"wp:attachment":[{"href":"https:\/\/vargolino.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=36"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vargolino.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=36"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vargolino.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=36"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}