PID=$(pgrep -f 'bin/app' | head -1)
[ -n "$PID" ] || { echo "not running"; return; }
echo "pid=$PID cmd=$(tr '\0' ' ' < /proc/$PID/cmdline)"
# 1. Live context switch counters — this one IS right for watch
watch -n1 "grep -E 'ctxt_switches|Threads' /proc/$PID/status"
# 2. Syscall summary — run once, not under watch
sudo timeout 60 strace -c -f -p "$PID"
# 3. Syscall trace with timings — write to a file, then read it
sudo timeout 15 strace -T -tt -f -p "$PID" -o /tmp/tr.txt
head -40 /tmp/tr.txt
perf stat -e context-switches,cpu-migrations -p $PID -- sleep 60
sudo perf sched record -- sleep 15 && sudo perf sched latency --sort max