windows CPU 使用率是如何计算的?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/810370/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How is CPU usage computed?
提问by Frederick The Fool
The Windows Task Manager shows CPU usage in percentage. What's the formula behind this? Is it this:
Windows 任务管理器以百分比显示 CPU 使用率。这背后的公式是什么?是不是这个:
% CPU usage for process A = (Sum of all time slices given to A till now)/ Total time since the machine booted
进程 A 的 CPU 使用率百分比 =(到目前为止给 A 的所有时间片的总和)/自机器启动以来的总时间
Or is it something else?
或者是别的什么?
回答by Mitchel Sellers
I am not 100% sure what is uses, but I think you are a bit off on the CPU calculation.
我不是 100% 确定使用的是什么,但我认为您对 CPU 计算有点偏离。
I believe they are doing something like.
我相信他们正在做类似的事情。
Process A CPU Usage = (Cycles for A over last X seconds)/(Total cycles for last X seconds)
I believe it is tied to the "update interval" set in task manager.
我相信它与任务管理器中设置的“更新间隔”有关。
While doing a bit of research for you though I found this MSDNarticle that shows a microsoft recommended way of calculating the CPU time of a set of instructions, this might point you a bit towards their calculation as well.
在为您做一些研究时,虽然我发现了这篇 MSDN文章,该文章显示了微软推荐的计算一组指令的 CPU 时间的方法,但这也可能指向他们的计算。
回答by Jon Skeet
No, it's not "since boot time" - it's far more time-sensitive than that.
不,它不是“自启动时间”——它比那个时间敏感得多。
It's "proportion of time during which a CPU was actively running a thread in that process since the last refresh". (Where the refresh rate is typically about a second.) In task manager I believe it's then divided by the number of CPUs, so the total ends up being 100% (i.e. on a dual core machine, a single-threaded CPU hog will show as 50%). Other similar programs sometimes don't do this, giving a total of 100% * cores.
它是“自上次刷新以来 CPU 在该进程中积极运行线程的时间比例”。(刷新率通常约为一秒。)在任务管理器中,我相信它然后除以 CPU 数量,因此总数最终为 100%(即在双核机器上,单线程 CPU hog 将显示50%)。其他类似的程序有时不会这样做,总共提供 100% * 内核。
回答by Brian Rasmussen
You may also want to check this articleas the way CPU cycles are handled with regards to scheduling was changed as part of Vista. I presume that this also applies to Win7.
您可能还想查看这篇文章,因为与调度相关的 CPU 周期的处理方式已作为 Vista 的一部分进行了更改。我认为这也适用于 Win7。
回答by Brian Rasmussen
See the source code of Task Manager
查看任务管理器的源代码