diff --git a/libbpf-tools/vfsstat.bpf.c b/libbpf-tools/vfsstat.bpf.c index 268f7d181676..28fac35cf6e0 100644 --- a/libbpf-tools/vfsstat.bpf.c +++ b/libbpf-tools/vfsstat.bpf.c @@ -45,6 +45,24 @@ int BPF_KPROBE(kprobe_vfs_create) return inc_stats(S_CREATE); } +SEC("kprobe/vfs_unlink") +int BPF_KPROBE(kprobe_vfs_unlink) +{ + return inc_stats(S_UNLINK); +} + +SEC("kprobe/vfs_mkdir") +int BPF_KPROBE(kprobe_vfs_mkdir) +{ + return inc_stats(S_MKDIR); +} + +SEC("kprobe/vfs_rmdir") +int BPF_KPROBE(kprobe_vfs_rmdir) +{ + return inc_stats(S_RMDIR); +} + SEC("fentry/vfs_read") int BPF_PROG(fentry_vfs_read) { @@ -75,4 +93,22 @@ int BPF_PROG(fentry_vfs_create) return inc_stats(S_CREATE); } +SEC("fentry/vfs_unlink") +int BPF_PROG(fentry_vfs_unlink) +{ + return inc_stats(S_UNLINK); +} + +SEC("fentry/vfs_mkdir") +int BPF_PROG(fentry_vfs_mkdir) +{ + return inc_stats(S_MKDIR); +} + +SEC("fentry/vfs_rmdir") +int BPF_PROG(fentry_vfs_rmdir) +{ + return inc_stats(S_RMDIR); +} + char LICENSE[] SEC("license") = "GPL"; diff --git a/libbpf-tools/vfsstat.c b/libbpf-tools/vfsstat.c index 40699ecb7b58..ecc1bddb962f 100644 --- a/libbpf-tools/vfsstat.c +++ b/libbpf-tools/vfsstat.c @@ -110,6 +110,9 @@ static const char *stat_types_names[] = { [S_FSYNC] = "FSYNC", [S_OPEN] = "OPEN", [S_CREATE] = "CREATE", + [S_UNLINK] = "UNLINK", + [S_MKDIR] = "MKDIR", + [S_RMDIR] = "RMDIR", }; static void print_header(void) @@ -174,12 +177,18 @@ int main(int argc, char **argv) bpf_program__set_autoload(skel->progs.kprobe_vfs_fsync, false); bpf_program__set_autoload(skel->progs.kprobe_vfs_open, false); bpf_program__set_autoload(skel->progs.kprobe_vfs_create, false); + bpf_program__set_autoload(skel->progs.kprobe_vfs_unlink, false); + bpf_program__set_autoload(skel->progs.kprobe_vfs_mkdir, false); + bpf_program__set_autoload(skel->progs.kprobe_vfs_rmdir, false); } else { bpf_program__set_autoload(skel->progs.fentry_vfs_read, false); bpf_program__set_autoload(skel->progs.fentry_vfs_write, false); bpf_program__set_autoload(skel->progs.fentry_vfs_fsync, false); bpf_program__set_autoload(skel->progs.fentry_vfs_open, false); bpf_program__set_autoload(skel->progs.fentry_vfs_create, false); + bpf_program__set_autoload(skel->progs.fentry_vfs_unlink, false); + bpf_program__set_autoload(skel->progs.fentry_vfs_mkdir, false); + bpf_program__set_autoload(skel->progs.fentry_vfs_rmdir, false); } err = vfsstat_bpf__load(skel); diff --git a/libbpf-tools/vfsstat.h b/libbpf-tools/vfsstat.h index e5a3c16ebf63..07ae8973c6f7 100644 --- a/libbpf-tools/vfsstat.h +++ b/libbpf-tools/vfsstat.h @@ -9,6 +9,9 @@ enum stat_types { S_FSYNC, S_OPEN, S_CREATE, + S_UNLINK, + S_MKDIR, + S_RMDIR, S_MAXSTAT, }; diff --git a/tools/vfsstat.py b/tools/vfsstat.py index c6fd3b911623..168551b137f6 100755 --- a/tools/vfsstat.py +++ b/tools/vfsstat.py @@ -13,6 +13,7 @@ # # 14-Aug-2015 Brendan Gregg Created this. # 12-Oct-2022 Rocky Xing Added PID filter support. +# 09-May-2024 Rong Tao Add unlink,mkdir,rmdir stat. from __future__ import print_function from bcc import BPF @@ -54,6 +55,9 @@ S_FSYNC, S_OPEN, S_CREATE, + S_UNLINK, + S_MKDIR, + S_RMDIR, S_MAXSTAT }; @@ -71,6 +75,9 @@ void do_fsync(struct pt_regs *ctx) { stats_try_increment(S_FSYNC); } void do_open(struct pt_regs *ctx) { stats_try_increment(S_OPEN); } void do_create(struct pt_regs *ctx) { stats_try_increment(S_CREATE); } +void do_unlink(struct pt_regs *ctx) { stats_try_increment(S_UNLINK); } +void do_mkdir(struct pt_regs *ctx) { stats_try_increment(S_MKDIR); } +void do_rmdir(struct pt_regs *ctx) { stats_try_increment(S_RMDIR); } """ bpf_text_kfunc = """ @@ -79,6 +86,9 @@ KFUNC_PROBE(vfs_fsync_range) { stats_try_increment(S_FSYNC); return 0; } KFUNC_PROBE(vfs_open) { stats_try_increment(S_OPEN); return 0; } KFUNC_PROBE(vfs_create) { stats_try_increment(S_CREATE); return 0; } +KFUNC_PROBE(vfs_unlink) { stats_try_increment(S_UNLINK); return 0; } +KFUNC_PROBE(vfs_mkdir) { stats_try_increment(S_MKDIR); return 0; } +KFUNC_PROBE(vfs_rmdir) { stats_try_increment(S_RMDIR); return 0; } """ is_support_kfunc = BPF.support_kfunc() @@ -109,6 +119,9 @@ b.attach_kprobe(event="vfs_fsync_range", fn_name="do_fsync") b.attach_kprobe(event="vfs_open", fn_name="do_open") b.attach_kprobe(event="vfs_create", fn_name="do_create") + b.attach_kprobe(event="vfs_unlink", fn_name="do_unlink") + b.attach_kprobe(event="vfs_mkdir", fn_name="do_mkdir") + b.attach_kprobe(event="vfs_rmdir", fn_name="do_rmdir") # stat column labels and indexes stat_types = { @@ -116,7 +129,10 @@ "WRITE": 2, "FSYNC": 3, "OPEN": 4, - "CREATE": 5 + "CREATE": 5, + "UNLINK": 6, + "MKDIR": 7, + "RMDIR": 8, } # header diff --git a/tools/vfsstat_example.txt b/tools/vfsstat_example.txt index 22cac769a4e2..aa1ed67b01b8 100644 --- a/tools/vfsstat_example.txt +++ b/tools/vfsstat_example.txt @@ -5,18 +5,25 @@ This traces some common VFS calls and prints per-second summaries. By default, the output interval is one second: # ./vfsstat -TIME READ/s WRITE/s CREATE/s OPEN/s FSYNC/s -18:35:32: 231 12 4 98 0 -18:35:33: 274 13 4 106 0 -18:35:34: 586 86 4 251 0 -18:35:35: 241 15 4 99 0 -18:35:36: 232 10 4 98 0 -18:35:37: 244 10 4 107 0 -18:35:38: 235 13 4 97 0 -18:35:39: 6749 2633 4 1446 0 -18:35:40: 277 31 4 115 0 -18:35:41: 238 16 6 102 0 -18:35:42: 284 50 8 114 0 +TIME READ/s WRITE/s FSYNC/s OPEN/s CREATE/s UNLINK/s MKDIR/s RMDIR/s +10:42:35: 5172 454 0 111 0 0 0 0 +10:42:36: 478 701 0 1 0 0 0 0 +10:42:37: 873 267 0 861 0 72 0 0 +10:42:38: 1599 146 0 1989 0 177 0 0 +10:42:39: 1876 135 0 2379 0 212 0 0 +10:42:40: 2566 201 0 3207 0 287 0 0 +10:42:41: 772 508 0 563 0 49 0 0 +10:42:42: 189 141 0 48 0 0 0 0 +10:42:43: 468 558 0 48 0 0 0 0 +10:42:44: 1144 841 0 624 0 0 0 0 +10:42:45: 4094 2554 0 2715 0 0 0 0 +10:42:46: 397 585 0 12 0 0 0 0 +10:42:47: 684 859 0 56 0 0 0 0 +10:42:48: 432 471 0 63 0 1 0 0 +10:42:49: 1890 259 0 1997 0 0 162 162 +10:42:50: 1990 143 0 2213 0 0 181 180 +10:42:51: 2256 197 0 2472 0 0 205 206 +10:42:52: 1674 351 0 1609 0 0 129 129 ^C @@ -24,10 +31,10 @@ Here we are using an output interval of five seconds, and printing three output lines: # ./vfsstat 5 3 -TIME READ/s WRITE/s CREATE/s OPEN/s FSYNC/s -18:35:55: 238 8 3 101 0 -18:36:00: 962 233 4 247 0 -18:36:05: 241 8 3 100 0 +TIME READ/s WRITE/s FSYNC/s OPEN/s CREATE/s UNLINK/s MKDIR/s RMDIR/s +10:43:46: 2141 273 0 1240 0 0 99 99 +10:43:51: 2673 141 0 3039 0 0 250 249 +10:43:56: 1939 433 0 1895 0 0 154 154 Full usage: