troubleshootinglisted
Install: claude install-skill ryukyagamilight/terminal-skills
# 性能问题排查
## 概述
性能瓶颈定位、资源争用分析技能。
## 快速诊断
### USE 方法
```bash
# Utilization, Saturation, Errors
# CPU
# 利用率
mpstat -P ALL 1
# 饱和度
vmstat 1 | awk '{print $1}' # 运行队列
# 错误
dmesg | grep -i "cpu"
# 内存
# 利用率
free -m
# 饱和度
vmstat 1 | awk '{print $7,$8}' # si/so
# 错误
dmesg | grep -i "oom"
# 磁盘
# 利用率
iostat -x 1 | awk '{print $NF}' # %util
# 饱和度
iostat -x 1 | awk '{print $10}' # avgqu-sz
# 错误
dmesg | grep -i "error"
# 网络
# 利用率
sar -n DEV 1
# 饱和度
netstat -s | grep -i "overflow"
# 错误
ip -s link
```
### 60 秒诊断
```bash
# 1. 系统负载
uptime
# 2. 内核消息
dmesg | tail
# 3. 系统统计
vmstat 1 5
# 4. CPU 统计
mpstat -P ALL 1 5
# 5. 进程 CPU
pidstat 1 5
# 6. 磁盘 IO
iostat -xz 1 5
# 7. 内存使用
free -m
# 8. 网络统计
sar -n DEV 1 5
# 9. TCP 统计
sar -n TCP,ETCP 1 5
# 10. 进程列表
top -bn1 | head -20
```
## CPU 问题排查
### 高 CPU 使用
```bash
# 找出高 CPU 进程
top -c
ps aux --sort=-%cpu | head
# 查看进程线程
top -H -p PID
ps -T -p PID
# CPU 分析
perf top -p PID
perf record -g -p PID -- sleep 30
perf report
```
### CPU 等待
```bash
# 查看 iowait
vmstat 1
iostat -x 1
# 找出 IO 进程
iotop
pidstat -d 1
```
### 上下文切换
```bash
# 系统级
vmstat 1 | awk '{print $12,$13}'
# 进程级
pidstat -w 1
pidstat -wt -p PID 1
```
## 内存问题排查
### 内存不足
```bash
# 查看内存使用
free -m
cat /proc/meminfo
# 查看进程内存
ps aux --sort=-%mem | head
smem -rs pss
# 查看缓存
slabtop
cat /proc/slabinfo
```
### 内存泄漏
```bash
# 监控进程内存
while true; do
ps -o pid,vsz,rss,comm -p PID
sleep 60
done
# 使用 valgrind
valgrind --leak-check=full ./program
```
### OOM 分析
```bash
# 查看 OOM