计算CPU使用率Windows进程? [英] Calculate CPU usage for a Windows process?

查看:225
本文介绍了计算CPU使用率Windows进程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给定一个进程ID,我怎样才能从这个过程中的CPU负载用C#?

Given a process ID, how can i get the cpu load from this process with C#?

我一直使用的PerformanceCounter在<所描述的尝试href="http://stackoverflow.com/questions/1277556/c-calculate-cpu-usage-for-a-specific-application">http://stackoverflow.com/questions/1277556/c-calculate-cpu-usage-for-a-specific-application

I have tried using PerformanceCounter as described in http://stackoverflow.com/questions/1277556/c-calculate-cpu-usage-for-a-specific-application

我也尝试手动采取的总CPU时间两个值过程中的时间框架内,并划分增量CPU时间与增量的总时间。

I have also tried to manually take two values of the total cpu time for the process within a timeframe and divide the delta-cpu-time with the delta-total-time.

这两种方法似乎很好地工作在第一,但如果我把我的应用程序旁边的Windows任务管理器我的应用程序总是显示约两倍的任务管理器。我曾尝试与不同的时间步长更新,从10毫秒到10秒,并得到相同的结果,所有的时间。

Both these methods seems to work fine at first but if i put my application next to windows task manager my application always shows about twice as much as the task manager does. I have tried to update with various timesteps from 10ms to 10sec and get same result all the time.

嗯,意识到当我写这一点,它可能是某种形式的双核心问题......

Hmm, realized when i wrote this that it might be some kind of dual core issue...

推荐答案

如果你有两个内核,任务管理器会报告1 100%的CPU使用率高达50%。这可能是你的问题就在这里。

If you have two cores, the task manager is going to report 100% usage of 1 CPU as 50%. That's probably your issue right there.

这篇关于计算CPU使用率Windows进程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆