PerformanceCounter报告的CPU使用率高于观察到的CPU使用率

问题描述 投票:3回答:1

我现在正在这样做:

PerformanceCounter cpuUsage = new PerformanceCounter("Processor", "% Processor Time", "_Total");
cpuUsage.NextValue();
System.Threading.Thread.Sleep(1000);
RV = cpuUsage.NextValue();

我定期调用该函数以获得CPU使用率。当我在TaskManager中监视系统时,PerformanceCounter报告的CPU使用率始终比TaskManager报告的高出15-20%(TaskManager中的30%=来自PerformanceCounter的50%)。

也许有我忽略的文档,但有没有人有解释?也许它检查的瞬间CPU使用率更高,任务管理器报告平均值?

c# cpu-usage performancecounter
1个回答
5
投票
  new PerformanceCounter("Processor", ...);

如果您坚持看到与任务管理器或Perfmon完全匹配,则使用错误的计数器。使用“处理器信息”而不是“处理器”。这些计数器显示不同值的原因在this blog post中得到了很好的解决。哪个计数器是“正确的”是一个我不想用10英尺杆接触的问题:)

© www.soinside.com 2019 - 2024. All rights reserved.