Skip to content

strace

strace is on every box and needs no kernel support, but it stops the process on every syscall it traces. Run it on one host for seconds, not on the fleet. For anything hot, use BPF instead.

Tested with strace 6.8 on Ubuntu 24.04. -p takes a comma-separated list, so pgrep -d, attaches to every matching worker at once.


Which files does this service open most?

Good for finding filter candidates before you turn on verbose auditing.

sudo timeout 60s strace -f -qq -e trace=openat -p "$(pgrep -d, -f php-fpm)" 2>&1 \
  | sed -nE 's/.*openat\(.*"([^"]+)".*/\1/p' \
  | sort | uniq -c | sort -nr | head -30

Where does its time go?

# Syscall summary: count, errors and time per syscall. Prints on exit.
sudo timeout -s INT 30s strace -c -f -qq -p "$PID"

-s INT matters: strace prints the summary when interrupted, the same as pressing Ctrl-C.


Only the slow calls

# Syscalls that took longer than 100 ms, with timestamps.
sudo timeout 60s strace -f -qq -e signal=none -tt -T -p "$PID" 2>&1 \
  | awk -F'<' 'NF > 1 && $NF + 0 > 0.1'

-T appends the time spent in each call as <0.301288>; the awk keeps lines over the threshold. Expect wait4 and sleeps in the output — they are slow on purpose.


Only the calls that fail

# Every file-related syscall that returned an error.
sudo timeout 30s strace -f -qq -e signal=none -e trace=%file -e status=failed -p "$PID"

The fastest way to find a missing config file, a wrong path or a permission error that the application swallows.

© 2026 Helius ApS · CVR 46850297. All rights reserved.

Got an idea for the next post? Tell me →