还有一个关于here的类似线程,我试图自己实现它。即尝试使用C++库获取在服务器中运行的线程数。计算Windows服务器上的线程数量;计数器路径
我可以确切知道COUNTER_PATH是什么吗? (例如给定的link中的“\ Process(* _)\ Thread Count”)?用这个字符串和pid编号是什么意思?
以下是我迄今写了没有真正理解什么:
#include <windows.h>
#include <pdh.h> //and suppose there're other libraries as necessary...
CONST PWSTR COUNTER_PATH = L"\Process(*)\Thread Count";
int returnNumThreads()
{
HQUERY hQuery = NULL;
HCOUNTER hCounter;
DWORD counterType;
PDH_FMT_COUNTERVALUE counterValue;
PWSTR Paths = NULL;
PDH_STATUS pdhStatus = PdhOpenQuery(NULL, 0, &hQuery);
pdhStatus = PdhAddCounter(hQuery, COUNTER_PATH, 0, &hCounter);
pdhStatus = PdhCollectQueryData(hQuery);
pdhStatus = PdhGetFormattedCounterValue(hCounter,
PDH_FMT_LONG,
&counterType,
&counterValue);
return counterValue.longValue;
}
// **Here, I removed all the error checking codes such as
// "if (pdhStatus != ERROR_SUCCESS){...}" for better readability
**此外,在链接中给出的解决方案上面说要扩大通配符路径,但是,当我检查了PdhAddCounter page,它说:“如果计数器路径包含通配符,则所有匹配通配符的计数器名称都会添加到查询中,”所以我不确定扩展是否真的需要。
我一直在寻找variousexamples,但我不确定是否正确创建查询或仍然是什么COUNTER_PATH是。有人可以给我一个解释吗?
你可能想要'PdhAddEnglishCounter'。Ì当他们梦想着'PdhAddCounter'时不知道他们在吸烟什么。 ''\ Proces(opera)\ Piekwaarde德文字节“'意思?? – MSalters