cpustat 是一个用于监控 CPU 使用情况的工具,它是 sysstat 包的一部分。要使用 cpustat 比较不同时间点的 CPU 使用情况,你可以按照以下步骤操作:
sysstat 包。在 Debian 系统上,你可以使用以下命令安装:sudo apt-get update
sudo apt-get install sysstat
cpustat 命令收集 CPU 使用情况数据。你可以指定一个时间间隔(以秒为单位)和一个持续时间(以秒为单位)。例如,要每 2 秒收集一次数据,持续 10 秒,你可以运行:cpustat -i ALL 2 10
这将显示所有 CPU 的使用情况,每 2 秒更新一次,共收集 10 次数据。
cpustat 的输出重定向到文件中。例如:cpustat -i ALL 2 10 > cpustat_output1.txt
等待一段时间(例如 1 分钟),然后再次运行 cpustat 命令:
cpustat -i ALL 2 10 > cpustat_output2.txt
cpustat_output1.txt 和 cpustat_output2.txt,它们分别包含了两个不同时间点的 CPU 使用情况数据。你可以使用文本比较工具(如 diff)来比较这两个文件:diff cpustat_output1.txt cpustat_output2.txt
这将显示两个文件之间的差异,帮助你了解在这段时间内 CPU 使用情况的变化。
请注意,cpustat 默认显示的是自上次启动以来的平均 CPU 使用情况。如果你想查看实时 CPU 使用情况,可以使用 -c 选项:
cpustat -c ALL
这将显示所有 CPU 的实时使用情况,包括用户空间、系统空间、空闲等。