forked from DavadDi/bpf_study
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#!/usr/bin/python | ||
from bcc import BPF | ||
from bcc import DEBUG_PREPROCESSOR | ||
|
||
prog = """ | ||
#include <uapi/linux/limits.h> // for NAME_MAX | ||
struct event_data_t { | ||
u32 pid; | ||
char fname[NAME_MAX]; // max of filename | ||
}; | ||
BPF_PERF_OUTPUT(open_events); | ||
TRACEPOINT_PROBE(syscalls,sys_enter_open){ | ||
u32 pid = bpf_get_current_pid_tgid() >> 32; | ||
struct event_data_t evt = {}; | ||
evt.pid = pid; | ||
bpf_probe_read(&evt.fname, sizeof(evt.fname), (void *)args->filename); | ||
open_events.perf_submit((struct pt_regs *)args, &evt, sizeof(evt)); | ||
return 0; | ||
} | ||
""" | ||
|
||
b = BPF(text=prog, debug=DEBUG_PREPROCESSOR) | ||
|
||
# process event | ||
def print_event(cpu, data, size): | ||
event = b["open_events"].event(data) | ||
print("Rcv Event %d, %s"%(event.pid, event.fname)) | ||
|
||
# loop with callback to print_event | ||
b["open_events"].open_perf_buffer(print_event) | ||
while True: | ||
try: | ||
b.perf_buffer_poll() | ||
except KeyboardInterrupt: | ||
exit() |