项目地址
https://github.com/brendangregg/perf-tools
安装内核3.2以上
git clone --depth 1 https://github.com/brendangregg/perf-tools
单独工具安装
wget https://raw.githubusercontent.com/brendangregg/perf-tools/master/iosnoop
目录工具集说明
[root@iZt4n697pofhuqffl6t3odZ perf-tools]# tree
.
├── bin
│ ├── bitesize -> ../disk/bitesize # 磁盘I / O大小的柱状图总结
│ ├── cachestat -> ../fs/cachestat # Linux 页面缓存的基本缓存命中/未命中统计信息
│ ├── execsnoop -> ../execsnoop # 使用命令行参数详细信息跟踪进程 exec()
│ ├── funccount -> ../kernel/funccount # 数内核函数调用,匹配带有通配符的字符串
│ ├── funcgraph -> ../kernel/funcgraph # 跟踪内核函数调用图,显示子函数和时间
│ ├── funcslower -> ../kernel/funcslower # 跟踪比阈值慢的内核函数
│ ├── functrace -> ../kernel/functrace # 跟踪内核函数调用,匹配带有通配符的字符串
│ ├── iolatency -> ../iolatency # io直方图,清晰显示IO对应片段次数
│ ├── iosnoop -> ../iosnoop # 跟踪磁盘 I/O 的详细信息,包括延迟
│ ├── killsnoop -> ../killsnoop # 跟踪显示进程和信号详细信息的 kill() 信号
│ ├── kprobe -> ../kernel/kprobe # 动态跟踪内核函数调用或其返回,带有变量
│ ├── opensnoop -> ../opensnoop # 跟踪显示文件名的 open() 系统调用
│ ├── perf-stat-hist -> ../misc/perf-stat-hist # 跟踪点变量的聚合能力
│ ├── reset-ftrace -> ../tools/reset-ftrace # 如果需要,重置 ftrace 状态
│ ├── syscount -> ../syscount # 按系统调用或进程计算系统调用
│ ├── tcpretrans -> ../net/tcpretrans # 显示 TCP 重传,以及地址和其他详细信息
│ ├── tpoint -> ../system/tpoint # 跟踪给定的跟踪点
│ └── uprobe -> ../user/uprobe
├── deprecated
│ ├── execsnoop-proc
│ ├── execsnoop-proc.8
│ ├── execsnoop-proc_example.txt
│ └── README.md
├── disk
│ └── bitesize
├── examples
│ ├── bitesize_example.txt
......................
├── execsnoop
├── fs
│ └── cachestat
├── images
│ └── perf-tools_2016.png
├── iolatency
├── iosnoop
├── kernel
│ ├── funccount
│ ├── funcgraph
│ ├── funcslower
│ ├── functrace
│ └── kprobe
├── killsnoop
├── LICENSE
├── man
........................
├── misc
│ └── perf-stat-hist
├── net
│ └── tcpretrans
├── opensnoop
├── README.md
├── syscount
├── system
│ └── tpoint
├── tools
│ └── reset-ftrace
└── user
└── uprobe
常见使用
磁盘相关
bitesize :采集指定时间内的IO直方图,如果后面不跟时间,按住ctrl+c才会结束
[root@iZt4n697pofhuqffl6t3odZ bin]# ./bitesize 10
Tracing block I/O size (bytes), for 10 seconds...
Kbytes : I/O Distribution
-> 0.9 : 12 |## |
1.0 -> 7.9 : 371 |######################################|
8.0 -> 63.9 : 126 |############# |
64.0 -> 127.9 : 11 |## |
128.0 -> : 0 | |
iolatency: 按指定时间一直采集IO直方图,默认1秒
[root@iZt4n697pofhuqffl6t3odZ bin]# ./iolatency
Tracing block I/O. Output every 1 seconds. Ctrl-C to end.
>=(ms) .. <(ms) : I/O |Distribution |
0 -> 1 : 4 |######################################|
>=(ms) .. <(ms) : I/O |Distribution |
0 -> 1 : 6 |######################################|
iosnoop:跟踪磁盘 I/O 的详细信息,包括延迟 -p跟踪指定进程
[root@iZt4n697pofhuqffl6t3odZ bin]# ./iosnoop
Tracing block I/O. Ctrl-C to end.
COMM PID TYPE DEV BLOCK BYTES LATms
kworker/3:1H 355 FWS 253,16 18446744073709551615 0 0.04
kworker/3:1H 355 FWS 253,16 18446744073709551615 0 0.02
jbd2/vdb-149 1495 WS 253,16 6937240 4096 0.42
内存相关
cachestat:内存命中相关,可以有效看到buffer cache数量
[root@iZt4n697pofhuqffl6t3odZ bin]# ./cachestat
Counting cache functions... Output every 1 seconds.
HITS MISSES DIRTIES RATIO BUFFERS_MB CACHE_MB
7343 0 256 100.0% 362 11538
8546 0 174 100.0% 362 11538
11891 0 87 100.0% 362 11538
8808 0 339 100.0% 362 11538
系统相关
execsnoop:跟踪执行的瞬时命令
[root@iZt4n697pofhuqffl6t3odZ bin]# ./execsnoop
Tracing exec()s. Ctrl-C to end.
Instrumenting sys_execve
PID PPID ARGS
4109241 4109239 cat -v trace_pipe
4109240 4109236 gawk -v o=1 -v opt_name=0 -v name= -v opt_duration=0 [...]
killsnoop: kill信号追踪
[root@iZt4n697pofhuqffl6t3odZ bin]# ./killsnoop
Tracing kill()s. Ctrl-C to end.
COMM PID TPID SIGNAL RETURN
opensnoop: 文件打开进程的追踪,如果不跟文件,则追踪整个操作系统,也可以-p指定进程
[root@iZt4n697pofhuqffl6t3odZ bin]# ./opensnoop /proc/2973/cgroup
Tracing open()s for filenames containing "/proc/2973/cgroup". Ctrl-C to end.
COMM PID FD FILE
systemd journal 0x13 /proc/2973/cgroup
systemd journal 0x13 /proc/2973/cgroup
网络
tcpretrans: tcp重传查看,快速发现重传的IP端口信息
[root@iZt4n697pofhuqffl6t3odZ bin]# ./tcpretrans
TIME PID LADDR:LPORT -- RADDR:RPORT STATE
00:18:41 0 -:- R> -:- -