My script is slow but I don't know why. How do I find the bottleneck?

Quick Linux Tip #24:

Try: strace -c -f ./slow_script.sh

Info: strace -c summarizes system calls by total time spent. -f follows child processes. The summary helps reveal which system calls are consuming the most time.

Examples:

  • $ strace -c ls -la /usr
  • $ strace -c -f -p 1234  # Profile a running PID
  • $ strace -e trace=file ./script  # Filter file syscalls

Note: High read/write activity can indicate I/O bottlenecks, while high openat activity can indicate excessive file opening. strace adds overhead, so use it for diagnostics rather than production benchmarking.

Follow @LinuxTeck for more #LinuxTips




LinuxTeck.com
linuxteck@ubuntu:~$ strace -c -f ./slow_script.sh
% time     seconds  usecs/call     calls    errors  syscall
------ ----------- ----------- --------- --------- ----------------
 78.34    2.345678        234    10023             read
 15.67    0.469012        123     3812             write
  3.45    0.103456         89     1162             openat
  1.23    0.036789         45      817       234  stat
  0.89    0.026633         67      397             close
  0.42    0.012567        234       54             mmap
------ ----------- ----------- --------- --------- ----------------
100.00    2.994136              16265       234  total

linuxteck@ubuntu:~$

PREVIOUS ARTICLE Quick Linux Tip #23: How do I rename 500 photos with a consistent naming scheme? NEXT ARTICLE Quick Linux Tip #25: How do I keep /var/www identical on two servers with minimal transfer?
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.