http://www.xbwolf.com/507
http://blog.csdn.net/kafeiflynn/article/details/6429976
安装步骤yum install systemtap
/usr/share/doc/systemtap-client-2.7/examples/
要遵循stap的写法,要求2.6.11内核以上的机器使用。
初次访问报错:
emantic error: while resolving probe point: identifier ‘kernel’ at /usr/share/systemtap/tapset/linux/vfs.stp:918:19
source: probe vfs.write = kernel.function(“vfs_write”)
semantic error: missing x86_64 kernel/module debuginfo [man warning::debuginfo] under ‘/lib/modules/2.6.32-431.23.3.el6.x86_64/build’
semantic error: while resolving probe point: identifier ‘vfs’ at inodewatch.stp:3:7
source: probe vfs.write, vfs.read
semantic error: no match
测试机器是: centos6
yum装的有kernel-devel kernel-headers gcc elfutils
通过 http://debuginfo.centos.org/6/x86_64/ 下载kernel-debug-debuginfo 以及kernel-debuginfo-common
主要要下载对应内核版本的,例如测试机器下载
kernel-debug-debuginfo-2.6.32-431.23.3.el6.x86_64.rpm 260M左右
kernel-debuginfo-common-x86_64-2.6.32-431.23.3.el6.x86_64.rpm 40m左右
rpm安装好后执行
WARNING: cannot find module nfs debuginfo: No DWARF information found [man warning::debuginfo]
WARNING: cannot find module sunrpc debuginfo: No DWARF information found [man warning::debuginfo]
说明包没下载对
stap-prep 命令查看到
Need to install the following packages:
kernel-debuginfo-2.6.32-431.23.3.el6.x86_64
发现与之前找到的包不一致。这点要仔细。。。。
通过:stap -v -e ‘probe vfs.read {printf(“read performed\n”); exit()}’ 测试是否执行成功,从pass1最后到pass5
前面是安装,下面开始说怎么用:
在/usr/share/doc/systemtap-client-2.7/examples/目录下,有很多脚本
(通过褚霸大神的命令)
stap -e ‘probe vfs.add_to_page_cache {printf(“dev=%d, devname=%s, ino=%d, index=%d, nrpages=%d\n”, dev, devname, ino, index, nrpages )}’
看到此时段应用很小
上一篇文章我们创建了test.data,此刻这个文件5G大小,我们通过另一个终端CP一个,可以看到有大量的设备写入
如:
dev=211812353, devname=xvda1, ino=1058100, index=2, nrpages=2
dev=211812353, devname=xvda1, ino=1058100, index=3, nrpages=3
dev=211812353, devname=xvda1, ino=1058100, index=4, nrpages=4
dev=211812353, devname=xvda1, ino=1058100, index=5, nrpages=5
dev=211812353, devname=xvda1, ino=1058100, index=6, nrpages=6
dev=211812353, devname=xvda1, ino=1058100, index=7, nrpages=7
dev=211812353, devname=xvda1, ino=1058100, index=8, nrpages=8
dev=211812353, devname=xvda1, ino=1058100, index=9, nrpages=9
dev=211812353, devname=xvda1, ino=1058100, index=10, nrpages=10
dev=211812353, devname=xvda1, ino=1058100, index=11, nrpages=11
同样一个文件被频繁写入,被谁写入如何查
ls -al /dev/xvda1
brw-rw—- 1 root disk 202, 1 Oct 27 09:07 /dev/xvda1
cp 一个文件。通过stat -c “%i” 文件查到inode
stap inodewatch.stg 202 1 ****
cp(2514) vfs_read 0xca00001/138740
cp(2514) vfs_read 0xca00001/138740
cp(2514) vfs_read 0xca00001/138740
查到是cp进程引起