pt-ioprofile是Percona公司Percona-Toolkit工具集中的一员,他可以帮助我们查看某进程的具体I/O情况。
运行pt-ioprofile工具后,程序默认执行30秒,执行完成程序正常退出,没有I/O输出内容。
这究竟是怎么回事呢?你有没有遇到?看完本文就能解决这个问题了。
问题描述
运行工具后,程序未报错,但是也没有结果输出。
[root@localhost ~]# pt-ioprofile
2021年 12月 09日 星期四 15:49:31 CST
Tracing process ID 13110
total filename
只显示“total filename”这行内容后,之后没有其他结果了,我想要的是接下来的I/O具体输出内容,怎么就没有后续的内容了呢?这不是我想要的!!!
问题分析
程序能正常运行,说明pt-ioprofile工具安装是没有问题的,pt-ioprofile工具其实是一个脚本文件,那这个脚本内容和官网源码一致吗?pt-ioprofile工具调用的是操作系统的strace工具,那strace命令是否能正常运行呢?
带着上述疑问我们走上问题排查之旅!
- 确认操作系统
[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.7.1908 (Core)
- 确认工具版本
[root@localhost ~]# pt-ioprofile --version
pt-ioprofile 3.3.1
[root@localhost ~]# strace -V
strace -- version 4.12
- 分析问题
第一步:查看linux7.7的strace工具的输出内容
[root@localhost ~]# strace -f -s 0 -T -p 15312 2>&1 | head -1
strace: Process 15312 attached with 31 threads
第二步:查看pt-ioprofile脚本内容
首先我们看一下pt-ioprofile工具的官方源码
然后我们看一下我们已经安装好的pt-ioprofile工具脚本内容
[root@localhost ~]# vim /usr/bin/pt-ioprofile
在仔细阅读源码内容后,有如下发现(看红框部分)
发现了问题:
操作系统的strace命令输出内容是以strace开头的,而pt-ioprofile脚本中定义的是查找以Process开头的内容,这就导致无法找到所需要的strace结果了。
第三步:那这是pt-ioprofile脚本问题?还是操作系统兼容问题呢?
我们找一台linux6操作系统,看一下strace工具的输出内容
[root@localhost ~]# strace -f -s 0 -T -p 23582 2>&1 | head -1
Process 23582 attached with 31 threads
果然,linux6操作系统中strace命令输出内容是以Process开头的,这和pt-ioprofile脚本中默认的内容是一致的。
第四步:查找官方说法
毕竟发现了问题,但是我们还是需要官方的说法支持。经资料搜集,找到了官方的解释👇🏻
pt-ioprofile doesn’t work in CentOS 7.5 box
pt-ioprofile doesn’t work in CentOS 7.5 box.
Because of strace’s output format has been changed between CentOS 6.x and CentOS 7.x
pt-ioprofile expects/^Process:/
but new-strace prints that as "strace: Process xxx
See https://github.com/percona/percona-toolkit/blob/3.0.12/bin/pt-ioprofile#L574
解决方法
修改pt-ioprofile脚本内容,第574行做如下修改
[root@localhost ~]# vim /usr/bin/pt-ioprofile
# 将原内容
/^Process/ { mode = "strace"; }
# 替换为如下内容
/^(strace: )?Process/ { mode = "strace"; }
再次运行pt-ioprofile工具,I/O结果输出正常。