计算 Windows 进程的 CPU 使用率?
给定一个进程 ID,我如何使用 C# 获取该进程的 cpu 负载?
我已尝试使用 PerformanceCounter,如 c# 计算特定应用程序的 CPU 使用率中所述
我还尝试手动获取一个时间范围内进程的总 cpu 时间的两个值,并将 delta-cpu-time 除以 delta-total-time。
这两种方法一开始似乎工作得很好,但如果我将应用程序放在 Windows 任务管理器旁边,我的应用程序显示的内容总是是任务管理器显示的两倍。我尝试用从 10 毫秒到 10 秒的各种时间步长进行更新,但始终得到相同的结果。
嗯,当我写这篇文章时意识到这可能是某种双核问题......
Given a process ID, how can i get the cpu load from this process with C#?
I have tried using PerformanceCounter as described in c# calculate CPU usage for a specific application
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.
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...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您有两个核心,任务管理器会将 1 个 CPU 的 100% 使用率报告为 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.