按核心跟踪线程执行情况

发布于 2024-11-14 22:09:27 字数 404 浏览 4 评论 0原文

假设我想绘制一个图表,其中 x 轴为 CPU“点击”(或挂钟时间),y 轴为线程执行情况。因此,举例来说,如果我有 4 个核心,我有 4 个 y 轴刻度,x 轴是时间,我想用红色绘制核心何时执行该线程:我如何以编程方式绘制收集信息来做到这一点?我想完全理解这个问题,所以我真的不需要使用 TBB 或任何 IDE、Intel 或其他的线程可视化...我只想理解执行此操作的一段简单代码。语言确实不是问题,但如果是 C,那就更好了。我不需要“绘制”图表,我只需要知道哪个CPU正在执行哪个线程以及执行多长时间。谢谢!

编辑:我刚刚找到nptl跟踪工具,如果有的话我会看到它们是什么'正在做并根据我的需要进行调整。

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

執念 2024-11-21 22:09:27

在不涉及内核的情况下执行此操作将很困难

制作图表的最佳方法是让内核在调度进程时记录更改(它不必进行大量更改,因为大多数操作系统具有软亲和性并且更喜欢将线程保留在同一核心上)。

也就是说,某些操作系统将此类统计信息导出到用户空间。例如,Linux 有 /proc/[pid]/stat在该文件中有一个名为processor的字段。

要了解(模糊的)线程在任何给定时刻发生的情况,您可以监视 /proc/self/task/*/stat 中的文件。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文