opensnoop-bpfcc: Trace open() syscalls
opensnoop-bpfcc [-h] [-T] [-U] [-x] [-p PID] [-t TID] [--cgroupmap CGROUPMAP] [--mntnsmap MNTNSMAP] [-u UID] [-d DURATION] [-n NAME] [-e] [-f FLAG_FILTER] [-F] [-b BUFFER_PAGES]
What it does
Trace open() syscalls. Part of the bcc tools (bpfcc-tools 0.35.0 on Ubuntu, installed as /usr/sbin/opensnoop-bpfcc; upstream and other distributions call it opensnoop). It loads an eBPF program, so it needs root.
Options you will use
-T, --timestamp- include timestamp on output
-U, --print-uid- print UID column
-x, --failed- only show failed opens
-p, --pid PID- trace this PID only
-t, --tid TID- trace this TID only
--cgroupmap CGROUPMAP- trace cgroups in this BPF map only
--mntnsmap MNTNSMAP- trace mount namespaces in this BPF map only
-u, --uid UID- trace this UID only
-d, --duration DURATION- total duration of trace in seconds
-n, --name NAME- only print process names containing this name
-e, --extended_fields- show extended fields
-f, --flag_filter FLAG_FILTER- filter on flags argument (e.g., O_WRONLY)
-F, --full-path- show full path for an open file with relative path
-b, --buffer-pages BUFFER_PAGES- size of the perf ring buffer (must be a power of two number of pages and defaults to 64)
Examples
$ sudo opensnoop-bpfcctrace all open() syscalls
$ sudo opensnoop-bpfcc -Tinclude timestamps
$ sudo opensnoop-bpfcc -Uinclude UID
$ sudo opensnoop-bpfcc -xonly show failed opens
$ sudo opensnoop-bpfcc -p 181only trace PID 181
$ sudo opensnoop-bpfcc -t 123only trace TID 123
$ sudo opensnoop-bpfcc -u 1000only trace UID 1000
$ sudo opensnoop-bpfcc -d 10trace for 10 seconds only
Gotchas
- -x shows only failed opens; ERR 2 = ENOENT (no such file), 13 = EACCES.
- As a normal user it fails with "could not open bpf map: ..., error: Operation not permitted" (unprivileged BPF is off on Ubuntu).
On the blog
Try opensnoop-bpfcc in a real terminal Free, in your browser - a real Ubuntu terminal to try it in, with missions that check your work.