cpustat 是一个用于实时监控 CPU 使用情况的工具,它是 sysstat 包的一部分。要使用 cpustat 实时监控 CPU 性能,请按照以下步骤操作:
sysstat 包。在 Debian 系统上,可以使用以下命令安装:sudo apt-get update
sudo apt-get install sysstat
cpustat 命令来查看 CPU 的实时使用情况。默认情况下,cpustat 会显示每个 CPU 核心的使用率、上下文切换次数、中断次数等信息。例如:$ cpustat
Linux 5.4.0-42-generic (hostname) 07/01/2021 _x86_64_ (4 CPU)
avg-cpu: %user %nice %system %iowait %steal %idle
12.34 0.01 5.67 0.12 0.00 81.86
-w 或 --width 选项指定输出宽度,以便在屏幕上查看更多信息。例如:$ cpustat -w 200
这将使 cpustat 每隔 200 毫秒刷新一次输出。
-C 或 --cpu 选项指定核心编号。例如,要监控 CPU 核心 0 和 1,请运行:$ cpustat -C 0,1
-t 或 --times 选项指定时间间隔(以秒为单位)。例如,要每 5 秒监控一次 CPU 使用情况,请运行:$ cpustat -t 5
-e 或 --extended 选项显示每个 CPU 核心的详细统计信息。例如:$ cpustat -e
>)将输出重定向到文件。例如,要将实时监控的输出保存到名为 cpustat_output.txt 的文件中,请运行:$ cpustat -w 200 > cpustat_output.txt
这些技巧可以帮助您更好地使用 cpustat 实时监控 Debian 系统上的 CPU 使用情况。