- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我有一个在 ARM
上运行的 Embedded Linux(Kernel 2.6.37)
。 busybox 1.13.2
有一个默认的top
。我通过交叉编译构建了一个 procps-ng 3.3.11
以在这个 Linux
上运行。我发现 busybox
和 procps-ng
通过 top
输出的进程的 %cpu
是不同的。
比如一个进程的%cpu
,procps-ng top
显示30%左右,而busybox top
只显示10左右%。 procps-ng top
和 busybox top
的总 %cpu
相同。
然后看了busybox
和procps-ng
的计算源码。我发现他们对一个进程的%cpu
确实有不同的计算公式。
- busybox top:
CPU% = s->pcpu/sum(s->pcpu) * busy_cpu_ticks/total_cpu_ticks
(pcpu is delta of sys+user time between samples)
- procps-ng top:
CPU% = s->pcpu/total_cpu_ticks
为什么两个项目选择不同的计算公式?他们是为不同的应用案例设计的吗?谢谢!
最佳答案
已经和procps-ng团队讨论过这个问题,这里是重点:
On 12/28/2016 03:12 PM, Craig Small wrote:
There is probably a different ways to look at this. The first thing I would say is that busybox is supposed to be emulating or mimicking what the main programs are supposed to do, so if there is a difference between busybox and the real program, I would say that busybox is wrong. It would be like the busybox ls printing files differently to the real ls.Let's look at this formula again:
busybox top:
CPU% = s->pcpu/sum(s->pcpu) * busy_cpu_ticks/total_cpu_ticks
(pcpu is delta of sys+user time between samples)procps-ng top:
CPU% = s->pcpu/total_cpu_ticks
Now let's re-arrange it:
- busybox top:
CPU% = s->pcpu/total_cpu_ticks * busy_cpu_ticks/sum(s->pcpu)
CPU% = top_CPU% * busy_cpu_ticks/sum(s->pcpu)
(pcpu is delta of sys+user time between samples)This is the difference. busybox adds a ratio of
busy_cpu_ticks/sum(s->pcpu)
to what top worked out. This ratio could be written as:
RATIO = Sum(Usr + Nice + System + Irq + sirq + steal) / Sum(Usr + System)
You can sort of see this in
read_cpu_jiffy
in the busybox source. I don't understand what this ratio is trying to do or why it is required. Especially when the program you are trying to emulate doesn't have it.procps top says out of the total available jiffies in this cycle, X% were used by this program. busybox puts some odd scaling in there. So if a process uses 10% of the CPU in its system and user parts, top shows 10%. If for that cycle The process is in User and System for 50% of the time, busybox would show 20% (10% x 100/50).
I don't know why they did that.
更多详情请引用讨论链接:
discussion: different process's %cpu output via top from busybox and procps-ng
关于linux - 不同进程的 %cpu 通过 busybox 和 procps-ng 的 top 输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41134205/
我一直在编写一个程序,试图使用 procps 库来找到自己。但由于某种原因它会破坏堆栈。这是我的代码: int main(){ PROCTAB *ptp; proc_t task;
出于取证的原因,我想在 Centos 上编译一些基本工具,如 cat、grep、vi、find、md5sum、dir 等。在取证时检查进程列表非常重要。所以我尝试编译 ps (procps) stat
有谁知道如何使用 procps-3.2.8 来列出 ubuntu/linux 的所有运行进程?以及如何使用 procps-3.2.8 杀死它们? 请提供分步过程并提供有关procps 的有用链接。 最
它是关于 procps 包,用于 linux 的实用程序 ps。 能否打印每个进程(线程)最后使用的CPU数量? 更新:不是 CPU 时间(10 秒),而是 CPU 编号(CPU0、CPU5、CPU1
我有一个在 ARM 上运行的 Embedded Linux(Kernel 2.6.37)。 busybox 1.13.2 有一个默认的top。我通过交叉编译构建了一个 procps-ng 3.3.11
我是一名优秀的程序员,十分优秀!