Strace -c Command: Find Slow System Calls in Linux

Quick Linux Tip #93:

Question: A command is slow. Which syscalls are eating all its time?

Try: strace -c -w ls -laR /home 2>&1 >/dev/null | tail -20

Info: strace -c summarizes system call execution time. Adding -w measures wall-clock time rather than CPU time, exposing I/O bottlenecks like heavy directory scans or file status checks.

Examples:

  • $ strace -c -f ./program  # Include child process syscalls
  • $ strace -c -e trace=network curl https://example.com  # Filter specifically for network syscalls
  • $ strace -c -p 3456  # Attach profiler to active PID

Note: The -c flag runs the process to completion before outputting the final summary table. High getdents64 time indicates directory traversal bottlenecks.




LinuxTeck.com
linuxteck:~$ strace -c -w ls -laR /home 2>&1 >/dev/null | tail -20
% time     seconds  usecs/call     calls    errors syscall
------ ------------ ------------ --------- --------- ----------------
 45.23     0.234567          234      1002           getdents64
 28.45     0.147823          147       998           newfstatat
 12.34     0.064123           64       998           openat
  8.91     0.046234           46       996           close
  3.12     0.016234           16        45        12 lstat
  1.23     0.006423            6         8            read
  0.72     0.003789            3         3            mmap
------ ------------ ------------ --------- --------- ----------------
100.00     0.519193                   4050        12 total
linuxteck:~$

PREVIOUS ARTICLE Quick Linux Tip #92: Core Dump: Analyze a Running Process with gcore NEXT ARTICLE Quick Linux Tip #94: Swap File in Linux: Add 4GB Swap Space in 4 Steps
About John Britto

John Britto Founder & Chief-Editor @LinuxTeck. A Computer Geek and Linux Intellectual having more than 20+ years of experience in Linux and Open Source technologies.

View all posts by John Britto →

Leave a Reply

Your email address will not be published.