opensnoop(8)

๐Ÿ“ฆ version 1.0.1~20200130+git49b8cdf, in debian bookworm, debian trixie, ubuntu jammy, ubuntu noble, ubuntu resolute, ubuntu stonking

๐Ÿฆ‹ opensnoop โ€” like, the manual page but make it cute ๐Ÿฆ‹

okay bestie so this is opensnoop from the System Manager's Manual (section 8, we love a section 8 moment ๐Ÿ’…). She traces open() syscalls with all the file details, and she runs on Linux ftrace. Periodt.


โœจ NAME โœจ

opensnoop โ€” trace open() syscalls with file details. Uses Linux ftrace. no cap, that's literally her whole job ๐Ÿซถ


โœจ SYNOPSIS โœจ

opensnoop [-htx] [-d secs] [-p pid] [-L tid] [-n name] [filename]

โœจ DESCRIPTION โœจ

So what she does is trace open() syscalls, and she shows you the file name (the pathname, bestie) and the returned file descriptor number โ€” or -1 if it errored out ๐Ÿ˜ญ.

This implementation is specifically built to work on older kernel versions, and to work without kernel debuginfo. Iconic of her honestly. The way she does it: dynamic tracing of the return value of getname() as a string, and then associating it with the following open() syscall return. ๐Ÿ’ซ

โš ๏ธ real talk: this approach is kernel version specific, and it may not work on your version. It's a workaround, and a proof of concept for ftrace, until more kernel tracing functionality is available. She's doing her best, okay?

And since this uses ftrace, only the root user can use this tool. root energy only ๐Ÿ‘‘


โœจ REQUIREMENTS โœจ

  • FTRACE and KPROBE CONFIG
  • the syscalls:sys_exit_open tracepoint
  • the getname() kernel function
  • and awk (yes girl, awk is carrying this whole operation, we stan)

You may already have these enabled and available on recent Linux kernels. ๐Ÿ’–


โœจ OPTIONS โœจ

  • -d secs โ€” set the duration of tracing, in seconds. Trace output will be buffered and printed at the end. This also reduces overheads by buffering in-kernel, instead of printing events as they occur. lowkey efficient of her โœจ
The ftrace buffer has a fixed size per-CPU (see /sys/kernel/debug/tracing/buffer_size_kb). If you think events are missing, try increasing that size. ๐Ÿ‘€
  • -h โ€” print usage message. the little "help me help you" moment ๐ŸŽ€
  • -n name โ€” only show processes matching this process name. Partial strings and regular expressions are allowed. This is post-filtered using awk.
  • -p PID โ€” only trace this process ID. This is filtered in-kernel. ๐Ÿ”ฅ
  • -L TID โ€” only trace this thread ID. This is filtered in-kernel. ๐Ÿ”ฅ
  • -t โ€” include timestamps, in seconds. โฐ
  • -x โ€” only print failed open()s. the flop detector ๐Ÿ’€
  • filename โ€” only show open()s which match this filename. Partial strings and regular expressions are allowed. This is post-filtered using awk.

โœจ EXAMPLES โœจ

Trace all open() syscalls with details:

# opensnoop

Only trace open()s for PID 81:

# opensnoop -p 81

Trace failed open() syscalls:

# opensnoop -x

Trace open() syscalls for filenames containing "conf":

# opensnoop conf

Trace open() syscalls for filenames ending in "log":

# opensnoop 'log$'

โœจ FIELDS โœจ

  • TIMEs โ€” time of open() completion, in units of seconds. โฑ๏ธ
  • COMM โ€” process name (if known).
  • PID โ€” process ID.
  • FD โ€” file descriptor. If this is a successful open, the file descriptor number is shown. If this is unsuccessful, -1 is shown. Numbers beginning with 0x are hexadecimal. ๐Ÿงฎ
  • FILE โ€” filename (pathname) used by the open() syscall.

โœจ OVERHEAD โœจ

She reads open() syscalls and getname() kernel functions as they occur. For high rates of opens (> 500/s), the overhead may begin to be measurable. Test yourself, bestie, don't just take my word for it. You can use the -d mode to buffer output, reducing overheads. ๐Ÿซถ


โœจ SOURCE โœจ

This is from the perf-tools collection.

https://github.com/brendangregg/perf-tools

Also look under the examples directory for a text file containing example usage, output, and commentary for this tool. ๐Ÿ’–


โœจ OS โœจ

Linux ๐Ÿง


โœจ STABILITY โœจ

Unstable - in development. she's a work in progress and that's her journey ๐ŸŒฑ


โœจ AUTHOR โœจ

Brendan Gregg ๐Ÿ‘‘


โœจ SEE ALSO โœจ

execsnoop(8), strace(1)


and that's the whole vibe check, bestie ๐Ÿ’… this page came straight out of the USER COMMANDS section, dated 2014-07-20 โ€” yes she's vintage, yes she still eats. go trace something, ily ๐Ÿฆ‹๐Ÿ’–