Focused strace with -e trace Filters
Focused strace with -e trace Filters
Thesis
strace is only useful when the noise is gone. -e trace= (and friends) cut the stream to the syscalls you care about — file opens, network, signals — so a short reproduction stays readable.
Mental model
strace -e trace=openat,close # only those syscalls
strace -e trace=%file # class: file ops
strace -e trace=%network # class: socket ops
strace -f # follow children
strace -o out.txt # don't mix with program stdout
Classes (%file, %network, %process, %signal, …) are listed in man strace.
Worked example
strace is not installed on this writing box (policy: no package installs). The patterns below are from the strace man page and everyday ops practice; run them on a lab host that has strace.
# What files does `ls /tmp` touch?
strace -e trace=openat,close -o /tmp/ls.strace ls /tmp >/dev/null
head /tmp/ls.strace
# Network-only view of a curl
strace -f -e trace=%network -o /tmp/curl.strace curl -s -o /dev/null https://example.com
# Failed opens only (path bugs)
strace -e trace=openat -e fault=openat:error=ENOENT:when=1 # advanced; see man
strace -e trace=openat -Y true # decode paths; version-dependentTypical openat lines look like:
openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/tmp", O_RDONLY|O_NONBLOCK|O_CLOEXEC|O_DIRECTORY) = 3
Trap
strace -f on a production service under load. Every syscall traps into the tracer; latency explodes. Prefer a short reproduction, perf, or eBPF for live systems. Also: tracing secrets-handling processes can spill passwords into the log — redirect to a protected file.
Boring rule
Start with -e trace= for one class or a short syscall list, always -o a file, add -f only when children matter, and stop as soon as you have the failing path or errno.
Try this
- Compare
-e trace=%filevs listingopenat,stat,statxexplicitly. - Use
-e write=all -e read=allcarefully to dump buffer contents for a small repro only. - When
straceis unavailable, read/proc/<pid>/fdand/proc/<pid>/stackas a lighter first pass.