Vista 上的性能计数器问题

发布于 2024-07-21 09:00:05 字数 798 浏览 3 评论 0原文

我在 Vista 上的性能监控 API 中遇到了一个奇怪的问题。 我目前使用的代码在 XP/2k 上运行良好,基于 PdhGetFormattedCounterValue()。 我开始使用 PdhExpandWildCardPath 来扩展计数器(我对整体网络统计数据感兴趣),我正在查看的计数器是:

\\Network Interface(*)\\Bytes Received/sec
\\Network Interface(*)\\Bytes Sent/sec
\\Processor(_Total)\\% Processor Time

问题是在第一次调用时它们返回 PDH_INVALID_DATA,我认为这不是问题,因为如果我再次查询它,我将开始获取数据而不会出现错误。 问题是这样的 - 虽然处理器时间完全按照预期工作,但两个网络接口计数器都没有返回任何内容 - 始终只是 0。 我使用 Perfmon 验证了它们正在正常报告数据,所以我不知道可能是什么问题。 我在 MS 上发现了这个:

http:// /support.microsoft.com/?scid=kb%3Ben-us%3B287159&x=11&y=9

但我对多语言任务不感兴趣,所以我不认为这是是相关的。 我会看看我是否能想出一些基本代码来准确地显示我在做什么,但没有返回任何奇怪的东西,并且它在 XP/2k 上工作,所以我怀疑在幕后发生了一些变化。 谢谢!

I'm running into a strange issue on Vista with the Performance monitoring API. I'm currently using code that worked fine on XP/2k, based around PdhGetFormattedCounterValue(). I start out using PdhExpandWildCardPath to expand the counters (I'm interested in overall network statistics), the counters I'm looking at are:

\\Network Interface(*)\\Bytes Received/sec
\\Network Interface(*)\\Bytes Sent/sec
\\Processor(_Total)\\% Processor Time

The problem is that on their first call they return PDH_INVALID_DATA, I don't think this is a problem, since if I query it again I will start getting data without the error. The problem is this - while the processor time is worked exactly as expected, neither of the network interface counters are returning anything - just 0 all the time. I verified using Perfmon that they are reporting data normally, so I'm at a loss as to what might be the issue. I caught this at MS:

http://support.microsoft.com/?scid=kb%3Ben-us%3B287159&x=11&y=9

But I'm not interested in multi-language for my task, so I don't think this is relevant. I will see if I can come up with some basic code showing exactly what I'm doing, but nothing is returning anything strange, and it worked on XP/2k, so I suspect something changed under the hood. Thanks!

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

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

发布评论

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

评论(1

残花月 2024-07-28 09:00:05

事实证明,问题在于网络接口都是通配符,而处理器接口实际上已经通过性能监控进行了汇总。 我没有意识到的是,它 PdhExpandWildCardPath 没有返回 PdhAddCounter 可以直接使用的东西。 我的意思是,如果 ExpandWildCard 返回 3 个扩展匹配,它们会以空分隔字符串的形式返回 - 我理解这一点,但我假设 AddCounter 将有效创建一个包含所有三个匹配的计数器。 不,现实是我需要分解每个路径并从 AddCounter 单独请求它,然后在获得结果时手动汇总结果。

希望这可以帮助其他人避免我犯下的同样的错误,并减少挫败感。 ;)

It turns out the issue was that the network interfaces are both wildcards, whereas the Processor one is actually already rolled up by the performance monitoring. What I didn't realize was that it PdhExpandWildCardPath didn't return something directly usable by PdhAddCounter. By this I mean that if ExpandWildCard returns 3 expanded matches, they come back as a null separated strings - I understood this, but I had assumed that AddCounter would be effectively create a counter containing all three. Nope, reality is I needed to break up each path and request it individually from AddCounter, then roll up the results manually when I get them.

Hopefully this helps someone else to avoid the same mistake I made with less frustration. ;)

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