bpftrace 检查 vfs_write buffer 大小的 histogram

1
bpftrace -e 'kprobe:vfs_write  {  @bytes=hist(arg2); }'

如果希望过滤某一个进程的 write 操作,加 filter:

1
bpftrace -e 'kprobe:vfs_write /pid=={进程号}/ {  @bytes=hist(arg2); }'

bpftrace 检查 vfw_write 的延迟:

1
bpftrace -e 'kprobe:vfs_write { @start[tid] = nsecs; } kretprobe:vfs_write /@start[tid]/ { @ns[comm] = hist(nsecs - @start[tid]); delete(@start[tid]); }'

结果示例:

1
2
3
4
@ns[sshd]:
[64K, 128K)            2 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@|
[128K, 256K)           1 |@@@@@@@@@@@@@@@@@@@@@@@@@@                          |
[256K, 512K)           1 |@@@@@@@@@@@@@@@@@@@@@@@@@@                          |

sshd 进程有2次写操作延迟在 128us 内,1次在 128us 到 256us。

bpftrace 检查 get_rps_cpu 返回的 cpu

1
bpftrace -e 'kretprobe:get_rps_cpu { @rps = lhist(retval, 0, 7, 1);}'