Kernel thread tracking

Suppose I would like to draw a graph with the CPU “clicks” (or wall clock time) along the x axis and running the threads along the y axis. So, for example, if I have 4 cores, I have 4 y-axis, the x-axis is the time, and I would like to build, say, in red when the kernel executes this thread: how can I programmatically collect information for this? I would like to fully understand this problem, so I don’t need to use TBB or stream visualization of any IDE, Intel or otherwise ... I just would like to understand the simple part of the code that does this. Language is not a problem, in fact, but if it is C, then much better. I don’t need to draw a graph, I just need to know which processor is running which thread and for how long. Thank!

EDIT : I found the nptl trace tool , if anything I see what they do, and customize to my needs.

+3
source share
1 answer

Doing this without a kernel will be difficult .

The best way to make a schedule would be for the kernel to register changes when it planned the process (it will not need to make many changes, since most operating systems have soft affinity and prefer to keep the thread on the same core).

However, some operating systems export such statistics to user space. For example, Linux has /proc/[pid]/statand in this file there is a field called processor.

() , , /proc/self/task/*/stat.

+2

All Articles