statsnoop(8)

πŸ“¦ version 0.36.1, in centos-stream 10, centos-stream 9, fedora 43, fedora 44

✨ NAME ✨

statsnoop πŸ¦‹ is the manual page for statsnoop(8), and it traces stat() syscalls using Linux eBPF/bcc. Basically it's a spy for file lookups πŸ•΅οΈβ€β™€οΈ

🧚 SYNOPSIS 🧚

statsnoop [-h] [-t] [-x] [-p PID]

πŸ’œ DESCRIPTION πŸ’œ

okay so statsnoop traces the different stat() syscalls and shows you which processes are trying to read info about which files πŸ‘€ this is lowkey perfect for finding where config and log files live, or for figuring out why an app is failing, especially on startup 🫢

It works by tracing various kernel sys_stat() functions with dynamic tracing πŸ” bestie, that means it will need updating if those functions ever change 😭

This makes use of a Linux 4.4 feature (bpf_perf_event_output()). For kernels older than 4.4, check out the version under tools/old, which uses an older mechanism πŸ•°οΈ

Since this runs on BPF, only the root user can use this tool πŸ‘‘ no cap, no exceptions.

πŸŽ€ REQUIREMENTS πŸŽ€

You need CONFIG_BPF and bcc ✨

πŸ’… OPTIONS πŸ’…

  • -h β€” the usage message, for when you forget what you're doing πŸ™ˆ
  • -t β€” adds a timestamp column, in seconds since the first event, with decimal places ⏱️
  • -x β€” only shows the stats that failed πŸ’€
  • -p PID β€” traces only this process ID, filtered in-kernel 🎯

πŸ“ EXAMPLES πŸ“

Trace all stat() syscalls:

# statsnoop

Trace all stat() syscalls, and include timestamps:

# statsnoop -t

Trace only stat() syscalls that failed:

# statsnoop -x

Trace PID 181 only:

# statsnoop -p 181

🌈 FIELDS 🌈

  • TIME(s) β€” when the call happened, in seconds ⏰
  • PID β€” the process ID πŸͺͺ
  • COMM β€” the process name 🏷️
  • FD β€” the file descriptor if it worked, or -1 if it failed πŸ“
  • ERR β€” the error number (check the system's errno.h for the tea β˜•)
  • PATH β€” the open path πŸ›£οΈ

πŸ”₯ OVERHEAD πŸ”₯

This traces the kernel stat function and prints output for each event πŸ‘οΈ the rate is generally expected to be low (< 1000/s), so the overhead should be negligible 🫧 but if your app is calling a high rate of stat()s, then test and understand the overhead before you use it, periodt 😀

πŸ¦‹ SOURCE πŸ¦‹

This is from bcc πŸ’–

https://github.com/iovisor/bcc

Also look in the bcc distribution for a companion _examples.txt file with example usage, output, and commentary for this tool πŸ“š

πŸ–₯️ OS πŸ–₯️

Linux 🐧

πŸ§ͺ STABILITY πŸ§ͺ

Unstable - in development. 🚧

⭐ AUTHOR ⭐

Brendan Gregg πŸ‘©β€πŸ’»βœ¨

🌸 SEE ALSO 🌸

opensnoop(1) πŸ’«


Anyway, that's the whole tea on statsnoop(8) 🫢 It's from the USER COMMANDS section and dated 2016-02-08 πŸ’• Stay curious, bestie, and go trace some stats πŸ’…βœ¨

πŸ“¦ where this page comes from