线程的上下文切换(C ++ Windows) [英] Context switches of thread (C++ windows)
问题描述
如果我知道线程的HANDLE,如何知道c ++中的上下文切换"计数?
How can I know "Context Switches" count with c++, if I know HANDLE of thread?
http://i.stack.imgur.com/MYDa2.jpg
推荐答案
-
通过使用以下一种API查询名为
Thread(<process-name>/<thread-number>)/Context Switches/sec
的性能计数器在C ++中访问性能数据.有关此内容的更多信息:如何以编程方式计算上下文切换?
By querying perofrmance counters named
Thread(<process-name>/<thread-number>)/Context Switches/sec
using one of the APIs, e.g. Accessing Performance Data in C++. More on this: how programmatically count context switches?
使用Windows内部以编程方式获取线程上下文开关的数量 /代码段.
Using Windows internal NtQuerySystemInformation
API, see Obtaining number of thread context switches programmatically for details/code snippet.
特别是在谈论Process Explorer时,我猜是它正在从NtQuerySystemInformation
中获取数据.
Talking about Process Explorer in particular, my guess would be it's taking data from NtQuerySystemInformation
.
这篇关于线程的上下文切换(C ++ Windows)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!