在 Ubuntu 上,cpustat 通常指 sysstat 工具包中的 mpstat / pidstat,也可能是指 cpustat(来自 perf 工具或第三方工具)。最常见、最容易混淆的是:
mpstat(sysstat 提供)pidstat(sysstat 提供)cpustat(如 linux-tools 中的 cpustat 或 Go 写的 cpustat)下面我按最常见情况给你讲怎么分析。
which cpustat
cpustat --help
常见情况:
mpstatmpstat 1
pidstatpidstat -u 1
cpustatcpustat 1
mpstat 为例(最常用)mpstat 1
输出示例:
Linux 6.5.0 (ubuntu) 2026-01-21 _x86_64_
13:00:01 CPU %usr %nice %sys %iowait %irq %soft %steal %guest %gnice %idle
13:00:02 all 12.3 0.0 5.6 0.2 0.0 0.1 0.0 0.0 0.0 81.8
| 字段 | 含义 | 分析重点 |
|---|---|---|
%usr |
用户态 CPU | 应用计算多不多 |
%sys |
内核态 CPU | 系统调用、驱动 |
%iowait |
IO 等待 | 磁盘/网络瓶颈信号 |
%soft |
软中断 | 网络收包多 |
%steal |
被虚拟机抢占 | 云主机常见 |
%idle |
空闲 | 越低越忙 |
看:
%usr 高 → 应用本身吃 CPU%sys 高 → 系统调用多(锁、文件系统)看:
%iowait 高 → 磁盘慢%steal 高 → 云主机被抢资源看:
%soft 高 → 中断处理多mpstat -P ALLmpstat -P ALL 1
可以看:
pidstat -u 1
或
top -H
cpustat(Go 版)示例:
cpustat 1
特点:
重点看:
CPU%Command# 看整体
mpstat 1
# 看每个核
mpstat -P ALL 1
# 看进程
pidstat -u 1
# 看线程
pidstat -t 1
如果你愿意,可以把 你的 cpustat / mpstat 输出贴出来,我可以:
你现在是遇到 CPU 高、卡顿、还是不知道怎么看输出?