OnCallReadyStart learning

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-bpfcc

trace all open() syscalls

$ sudo opensnoop-bpfcc -T

include timestamps

$ sudo opensnoop-bpfcc -U

include UID

$ sudo opensnoop-bpfcc -x

only show failed opens

$ sudo opensnoop-bpfcc -p 181

only trace PID 181

$ sudo opensnoop-bpfcc -t 123

only trace TID 123

$ sudo opensnoop-bpfcc -u 1000

only trace UID 1000

$ sudo opensnoop-bpfcc -d 10

trace for 10 seconds only

Gotchas

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.