理解Linux top命令的CPU利用率输出

9

我正在使用一款在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         

列%CPU在所有进程中非常低,在本例中,它们加起来只有4.4%(下面的所有其他进程都为0%)但是第3行中的总CPU显示为65%us和20%sy,说明用户和系统均具有非常高的值,而且顺便说一句,这就是系统感觉非常缓慢的原因:-(系统几乎总处于这种状态:所有进程的CPU都很低,但用户和系统CPU却很高。有人能解释为什么top工具输出中存在如此高的不一致性吗?我可以使用哪个工具更好地找出导致高用户和系统CPU利用率的原因-top似乎在这里毫无用处。

更新:与此同时,我已经发现了这个主题here,它讨论了一个类似的问题,但我无法验证那里所写的内容:

  • 命令uptime显示每1/5/15分钟的平均CPU利用率。
  • 这与top的第一行输出的%us+%sy之和非常接近。但是这个值变化很大,也许是每10秒的平均值?
  • 即使在查看top输出的更长时间时,%us+%sy之和始终比所有%CPU的总和高几倍。

谢谢 Achim

1个回答

7
你应该阅读 topmanpage 以更准确地理解其输出。来自 manpage 的内容如下:

%CPU -- CPU 使用率

该进程在上次屏幕更新以来所占用的已流逝 CPU 时间的份额,表示为总 CPU 时间的百分比。默认的屏幕更新时间为 3 秒,可以使用 #top -d ss.tt 进行更改。要测量累积 CPU 使用率,请运行 top -S

-S:切换累积时间模式

使用上次记忆的 'S' 状态启动 top,并将 '累积模式' 打开。在 '累积模式' 中,每个进程都会列出它和其终止的子进程所使用的 CPU 时间。
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).

在正常情况下,%us+%sy应该始终更高。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接