PdhExpandWildCardPath 返回太多路径
我试图获取我的(Delphi XE)应用程序中每个(最多 200 个)线程的 CPU 利用率。为此,我向 PdhExpandWildCardPath 传递一个字符串 '\Thread(myappname/*)\% Processor Time'
。然而(在 Win7/64 上)从此函数返回的缓冲区为系统中运行的每个线程返回一个字符串,换句话说,它似乎将输入视为 '\Thread(*/*)\ %处理器时间'
。这是出乎意料的。当我随后扩展字符串以获得“ID Thread”时,也会发生同样的情况。
显然,我可以过滤应用程序名称上的结果字符串,并且仅添加我需要的计数器,但这需要数百次子字符串扫描。我是否误解了通配符的工作原理?
I am trying to obtain the CPU utilization of each of the (up to 200) threads in my (Delphi XE) application. To prepare for this I pass to PdhExpandWildCardPath a string '\Thread(myappname/*)\% Processor Time'
. However (on Win7/64) the buffer returned from this function returns a string for every thread running in the system, in other words it seems to have treated the input as if it were '\Thread(*/*)\% Processor Time'
. This was unexpected. The same happens when I subsequently expand a string to get 'ID Thread'.
Obviously I can filter the resulting strings on the application name and only add the counters I need, but this requires many hundreds of substring scans. Have I misinterpreted how the wildcards work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
晚了,但我也遇到了同样的问题,也许其他人需要它:
这里是:
'\Thread(myappname*)\% Processor Time'
对于 ProcessNameFormat 设置为 2 和 ThreadNameFormat 设置特别有用到
'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\PerfProc\Performance'
中的 2对于 ProcessNameFormat = 2 -> 链接,同样适用于 ThreadNameFormat,尽管我不能找到任何类型的文档。
Late, but I've hit the same wall, maybe someone else needs it:
Here it is:
'\Thread(myappname*)\% Processor Time'
Especially useful with ProcessNameFormat set to 2 and ThreadNameFormat set to 2 in
'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\PerfProc\Performance'
For ProcessNameFormat = 2 -> link, same applies for ThreadNameFormat, although I couldn't find any kind of documentation.