PerformanceCounter reporting higher CPU usage than what's observed

蹲街弑〆低调 提交于 2019-11-27 04:51:44

问题


I'm currently doing this:

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

I call the function periodically to get CPU usage. When I monitor the system in TaskManager, the CPU usage reported by PerformanceCounter is consistently 15-20% higher than what TaskManager reports (30% in TaskManager = 50% from PerformanceCounter).

Maybe there's documentation that I overlooked, but does anyone have an explanation? Maybe the CPU usage at the instant it checks is higher and task manager reports an average?


回答1:


  new PerformanceCounter("Processor", ...);

You are using the wrong counter if you insist on seeing an exact match with Task Manager or Perfmon. Use "Processor Information" instead of "Processor". The reason these counters show different values is addressed pretty well in this blog post. Which counter is "right" is a question I wouldn't want to touch with a ten-foot pole :)



来源:https://stackoverflow.com/questions/23391455/performancecounter-reporting-higher-cpu-usage-than-whats-observed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!