一,工具简介
这通过追踪所有以“vfs_”开头的内核函数,计算了在此期间发生的VFS调用次数。默认情况下,时间为99999999秒。
二,代码示例
#!/usr/bin/env python
from __future__ import print_function
from bcc import BPF
from time import sleep
from sys import argv
def usage():
print("USAGE: %s [time]" % argv[0])
exit()
interval = 99999999
if len(argv) > 1:
try:
interval = int(argv[1])
if interval == 0:
raise
except: # also catches -h, --help
usage()
# load BPF program
b = BPF(text="""
#include <uapi/linux/ptrace.h>
struct key_t {
u64 ip;
};
BPF_HASH(counts, struct key_t, u64, 256);
int do_count(struct pt_regs *ctx) {
struct key_t key = {};
key.ip = PT_REGS_IP(ctx);
counts.atomic_increment(key);
return 0;
}
""")
b.attach_kprobe(event_re="^vfs_.*", fn_name="do_count")
# header
print("Tracing... Ctrl-C to end.&#