cpustat
是一个用于显示 CPU 使用情况的工具,它是 sysstat
软件包的一部分。在 Debian 系统中,你可以通过包管理器(如 apt
)安装 sysstat
。cpustat
命令提供了丰富的 CPU 性能指标,包括用户态、系统态、空闲时间等。
要使用 cpustat
,只需在终端中输入 cpustat
,后跟一些可选参数。例如:
cpustat
这将显示系统的 CPU 使用情况摘要。输出可能如下所示:
Linux 5.4.0-42-generic (hostname) 05/01/2021 _x86_64_ (4 CPU)
avg-cpu: %user %nice %system %iowait %steal %idle
12.34 0.00 2.45 0.01 0.00 85.20
这里的列分别表示:
%user
:用户态进程占用的 CPU 时间百分比。%nice
:具有 nice 值的进程占用的 CPU 时间百分比。%system
:内核态进程占用的 CPU 时间百分比。%iowait
:等待 I/O 操作完成的 CPU 时间百分比。%steal
:虚拟机管理程序从虚拟 CPU 中窃取的时间百分比(仅在虚拟化环境中可见)。%idle
:空闲 CPU 时间百分比。你可以使用 -p
参数查看每个 CPU 的详细信息:
cpustat -p
输出示例:
Linux 5.4.0-42-generic (hostname) 05/01/2021 _x86_64_ (4 CPU)
avg-cpu: %user %nice %system %iowait %steal %idle
12.34 0.00 2.45 0.01 0.00 85.20
CPU %user %nice %system %iowait %steal %idle
0 10.12 0.00 2.34 0.02 0.00 87.52
1 12.45 0.00 2.56 0.01 0.00 85.08
2 11.89 0.00 2.48 0.00 0.00 85.63
3 12.78 0.00 2.67 0.01 0.00 84.54
这里显示了每个 CPU 的详细使用情况。通过分析这些数据,你可以了解系统的性能瓶颈并进行相应的优化。