【问题标题】:PerformanceCounter reporting higher CPU usage than what's observedPerformanceCounter 报告的 CPU 使用率高于观察到的情况
【发布时间】:2014-04-30 14:55:28
【问题描述】:

我目前正在这样做:

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】:
      new PerformanceCounter("Processor", ...);
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-05
      • 2011-03-25
      • 1970-01-01
      • 2014-09-23
      • 1970-01-01
      相关资源
      最近更新 更多