Linux性能分析工具
Contents
常用的性能分析工具
mpstat
查看整个系统/cpu维度的资源占用情况
pidstat
查看进程的资源占用情况
vmstat
vmstat reports information about processes, memory, paging, block IO, traps, disks and cpu activity.
分析系统的虚拟内存使用情况,也用于分析上下文切换和中断次数。
procs -----------------------memory---------------------- ---swap-- -----io---- -system-- --------cpu--------
r b swpd free inact active si so bi bo in cs us sy id wa st
0 0 0 234176 4473348 2733180 0 0 0 34 1 1 1 1 99 0 0
0 0 0 234008 4473516 2733184 0 0 0 0 1209 1831 1 0 99 0 0
- Procs
- r: running or runnable, 就绪队列长度,正在运行或者等待CPU的进程数。
- b: blocked 处于不可中断睡眠状态的进程数
- Memory
- swpd: the amount of virtual memory used.
- free: the amount of idle memory.
- buff: the amount of memory used as buffers.
- cache: the amount of memory used as cache.
- inact: the amount of inactive memory. (-a option)
- active: the amount of active memory. (-a option)
- Swap
- si: Amount of memory swapped in from disk (/s).
- so: Amount of memory swapped to disk (/s).
- IO
- bi: Blocks received from a block device (blocks/s).
- bo: Blocks sent to a block device (blocks/s).
- System
- in: The number of interrupts per second, including the clock. interrupt 每秒中断次数。
- cs: The number of context switches per second. context switch,每秒上下文切换次数。
- CPU
- us: Time spent running non-kernel code. (user time, including nice time)
- sy: Time spent running kernel code. (system time)
- id: Time spent idle. Prior to Linux 2.5.41, this includes IO-wait time.
- wa: Time spent waiting for IO. Prior to Linux 2.5.41, included in idle.
- st: Time stolen from a virtual machine. Prior to Linux 2.6.11, unknown.
模拟压力工具stress
stress --cpu 1 timeout 600
: 模拟一个CPU使用率100%的进程
stress -i 1 --timeout 600
: 模拟IO压力,不停的执行rsync
stress -c 8 --timeout 600
: 模拟8个进程