问题描述
目前,我正在做这样的:
的PerformanceCounter cpuUsage =新的PerformanceCounter(处理器,%处理器时间,_Total);
cpuUsage.NextValue();
System.Threading.Thread.Sleep(1000);
RV = cpuUsage.NextValue();
我定期调用函数来获取CPU使用率。当我监视任务管理系统,通过的PerformanceCounter报告的CPU使用率比任务管理报告。
(在任务管理器= 50%,从30的PerformanceCounter%)高持续15-20%也许有文件,我忽略了,但没有任何人有一个解释?也许它会检查即时CPU使用率更高,任务管理器报告的平均?
新的PerformanceCounter(处理器,...);
如果你坚持用看任务管理器或性能监视器完全匹配您使用了错误的计数器。使用处理器信息,而不是处理器。这些计数器显示不同的值,原因是在<一个处理pretty好href=\"http://blogs.technet.com/b/winserverperformance/archive/2009/08/06/inter$p$pting-cpu-utilization-for-performance-analysis.aspx\"相对=nofollow>这个博客帖子。这计数器是正确的,是一个问题,我不希望用10英尺极触摸:)
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?
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 :)
这篇关于报告的PerformanceCounter更高的CPU使用率比的观察到的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!