开发者

Tracking thread execution by core

Suppose I would like to draw a graph with CPU "clicks" (or wall-clock time) on the x-axis, and thread execution on the y-axis. So, for example, if I have 4 cores, I have 4 y-axis ticks, x-axis is time, and I'd like to plot, say, in red, when a core is executing that thread: how can I progra开发者_开发技巧mmatically gather the information to do that? I would like to understand the problem fully, so I don't really need to use TBB or the thread visualization of any IDE, Intel or otherwise... I'd just like to understand a simple piece of code that does this. Language is not an issue, really, but if it is C, so much better. I don't need to "draw" the graph, I just need to know what CPU is executing what thread and for how long. Thanks!

EDIT: I just found nptl trace tool, if anything I will see what they're doing and adjust to my needs.


Doing this without involving the kernel will be hard.

The best way to make the graph would be to have the kernel log the changes as it schedules a process (it won't have to make a lot of changes as most operating systems have a soft affinity and prefer to keep a thread on the same core).

That said, some operating systems export such statistics to user-space. For example Linux has /proc/[pid]/stat and in that file there is a field called processor.

To get an idea (a vague one) of what is happening to your threads at any given moment you can monitor the files in /proc/self/task/*/stat.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜