了解 Linux 最高 CPU 利用率输出

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13783726/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 18:00:24  来源:igfitidea点击:

Understanding Linux top CPU utilisation output

linuxperformance

提问by Achim

I'm using an single core small ARM processor running under Debian and have problems understanding the CPU utilisation output of top, see:

我正在使用在 Debian 下运行的单核小型 ARM 处理器,并且在理解 top 的 CPU 利用率输出时遇到问题,请参阅:

top - 15:31:54 up 30 days, 23:00,  2 users,  load average: 0.90, 0.89, 0.87
Tasks:  44 total,   1 running,  43 sleeping,   0 stopped,   0 zombie
Cpu(s): 65.0%us, 20.3%sy,  0.0%ni, 14.5%id,  0.0%wa,  0.0%hi,  0.3%si,  0.0%st
Mem:     61540k total,    40056k used,    21484k free,        0k buffers
Swap:        0k total,        0k used,        0k free,    22260k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                                                                                    
26028 root      20   0  2536 1124  912 R  1.9  1.8   0:00.30 top                                                                                        
31231 root      19  -1 45260  964  556 S  1.9  1.6   1206:15 owserver                                                                                   
    3 root      15  -5     0    0    0 S  0.3  0.0   0:08.68 ksoftirqd/0                                                                                
  694 root      20   0 28640  840  412 S  0.3  1.4 468:26.74 rsyslogd         

The column %CPU is very low over all processes, in this example it is all together 4,4% (all other process below had been on 0%) But the allover CPU on line 3 shows 65%us and 20%sy, so for both a very high value - and by the way, this is how the system feels: very slow :-( The system is almost always in this condition: very low CPU for all processes, but high user+system CPU. Can anybody explain why there is such a high inconsistence within the top tool output? And what tool can I use to better find out what causes the high user+system CPU utilization - top seems to be useless here.

%CPU 列在所有进程中都非常低,在这个例子中它总共是 4.4%(下面的所有其他进程都在 0%)但是第 3 行的所有 CPU 显示 65%us 和 20%sy,所以对于非常高的值 - 顺便说一下,这就是系统的感觉:非常慢:-(系统几乎总是处于这种状态:所有进程的 CPU 都很低,但是用户 + 系统 CPU 很高。谁能解释一下为什么top工具输出的不一致这么高?我可以使用什么工具来更好地找出导致用户+系统CPU利用率高的原因 - top在这里似乎没有用。

update: meanwhile I've found this thread here, which discusses a similiar question, but I can't verify what is written there:

更新:同时我在这里找到了这个线程,它讨论了一个类似的问题,但我无法验证那里写的是什么:

  • The command uptimeshows the average CPU utilization per 1/5/15 minutes
  • This is close to what the first line of topoutputs as sum of %us+%sy. But this is changing much more, maybe it is an average per 10s?
  • Even if looking longer time on the top output, the sum of %us+%sy is always several times higher than the summary of all %CPU
  • 命令uptime显示每 1/5/15 分钟的平均 CPU 使用率
  • 这接近于top的第一行输出为 %us+%sy 的总和。但这正在发生更多变化,也许是每 10 秒的平均值?
  • 即使在最上面的输出上看更长的时间,%us+%sy 的总和总是比所有 %CPU 的总和高几倍

Thanks Achim

谢谢阿希姆

回答by manav m-n

You should read the manpageof topto understand its output more astutely. From the manpage:

您应该阅读manpageoftop以更敏锐地理解其输出。从联机帮助页:

%CPU -- CPU usage

%CPU -- CPU 使用率

The task's share of the elapsed CPU time since the last screen update, expressed as a percentage of total CPU time. The default screen update time is 3 seconds, which can be changed with #top -d ss.tt. To measure commulative CPU usage, run top -S.

自上次屏幕更新以来,任务在 CPU 时间中所占的份额,以总 CPU 时间的百分比表示。默认屏幕更新时间为 3 秒,可通过 更改#top -d ss.tt。要测量交换 CPU 使用率,请运行top -S.

-S : Cumulative time mode toggle

-S : 累积时间模式切换

Starts top with the last remembered 'S' state reversed. When 'Cumulative mode' is On, each process is listed with the cpu time that it and its dead children have used.

从最后记住的“S”状态反转开始。当“累积模式”打开时,每个进程都列出了它及其死子进程使用的 CPU 时间。

The CPU states are shown in the Summary Area. They are always shown as a percentage and are for the time between now and the last refresh.

CPU 状态显示在摘要区域中。它们始终以百分比形式显示,适用于从现在到上次刷新之间的时间。

    us  --  User CPU time
      The time the CPU has spent running users' processes that are not niced.

    sy  --  System CPU time
      The time the CPU has spent running the kernel and its processes.

    ni  --  Nice CPU time
      The time the CPU has spent running users' proccess that have been niced.

    wa  --  iowait
      Amount of time the CPU has been waiting for I/O to complete.

    hi  --  Hardware IRQ
      The amount of time the CPU has been servicing hardware interrupts.

    si  --  Software Interrupts
      The amount of time the CPU has been servicing software interrupts.

    st  --  Steal Time
      The amount of CPU 'stolen' from this virtual machine by the hypervisor for other tasks (such as running another virtual machine).

Under normal circumstances %us+%sy should always be higher.

在正常情况下 %us+%sy 应该总是更高。