forked from iovisor/bcc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vfsstat.bpf.c
48 lines (40 loc) · 826 Bytes
/
vfsstat.bpf.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// SPDX-License-Identifier: GPL-2.0
// Copyright (c) 2020 Anton Protopopov
//
// Based on vfsstat(8) from BCC by Brendan Gregg
#include "vmlinux.h"
#include <bpf/bpf_helpers.h>
#include <bpf/bpf_tracing.h>
#include "vfsstat.h"
__u64 stats[S_MAXSTAT] = {};
static __always_inline int inc_stats(int key)
{
__atomic_add_fetch(&stats[key], 1, __ATOMIC_RELAXED);
return 0;
}
SEC("kprobe/vfs_read")
int BPF_KPROBE(vfs_read)
{
return inc_stats(S_READ);
}
SEC("kprobe/vfs_write")
int BPF_KPROBE(vfs_write)
{
return inc_stats(S_WRITE);
}
SEC("kprobe/vfs_fsync")
int BPF_KPROBE(vfs_fsync)
{
return inc_stats(S_FSYNC);
}
SEC("kprobe/vfs_open")
int BPF_KPROBE(vfs_open)
{
return inc_stats(S_OPEN);
}
SEC("kprobe/vfs_create")
int BPF_KPROBE(vfs_create)
{
return inc_stats(S_CREATE);
}
char LICENSE[] SEC("license") = "GPL";