有显示线程切换的方法吗? [英] Any approach to show threads switch?

查看:93
本文介绍了有显示线程切换的方法吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所有,是否有任何方法或工具来显示线程切换的过程,也就是说,我可以知道在任何特定时间,哪个线程占用了CPU,以及上下文切换的时间,谢谢 >

all, Is there any approach or tools to show the process of thread switch, that is, I can know at any specific time, the CPU is taken by which thread, as well as the time context switch costs, thanks

推荐答案

SystemTap对于此类事情很有用.为此,有一个罐头示例 sched_switch.stp .

SystemTap is useful for this kind of thing. There's a canned example sched_switch.stp for this.

但是,它不能测量开关的经过时间.至少出于几个原因,这似乎很棘手.首先,您必须为进入和退出确定合适的探针以测量增量,而我现在没有找到任何东西. (在相关进程中进入/退出内核可能是一个不错的近似值?尽管我现在还看不到,但可能有一些用处.)其次,如果您要知道在什么程度上避免上下文切换是值得的,如果您不认为频繁切换任务会导致额外的CPU高速缓存未命中,这些后果就不完整了.我认为获得答案的唯一好方法可能是实验性的.特别是,您可以尝试调整调度参数(请参见 cfs-tuning .pdf ),以查看更频繁的上下文切换如何影响程序的速度.

It doesn't measure the elapsed time of the switch, though. That seems tricky for at least a couple reasons. First, you'd have to decide an appropriate probe for the entry and exit to measure a delta, and I'm not finding anything right now. (Entering/exiting kernel within the relevant processes might be a decent approximation? There's probably something for that though I don't see it right now.) Second, if you're asking to know to what extent it's worth avoiding context switches, it'd be an incomplete picture if you didn't consider extra CPU cache misses from switching tasks more often, and those come afterward. I think the only good way to get an answer may be experimentally. In particular, you might try tweaking scheduling parameters (see cfs-tuning.pdf) to see how more frequent context switches affect your program's speed.

这篇关于有显示线程切换的方法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆