Quick Linux Tip #113:
Question: My script is slow but I don't know if it's CPU, I/O, or waiting. How do I find out?
Try: /usr/bin/time -v ./slow_script.sh 2>&1 | grep -E 'Elapsed|CPU|Maximum|context|wait'
Info: Profiles resource bottlenecks by outputting detailed timing, CPU utilization, page faults, and context switches.
Examples:
- $
/usr/bin/time -v command 2>&1 | tee runtime.log# Profile command execution and save metrics to log - $
perf stat ./script# Advanced performance profiling using CPU hardware counters - $
pidstat -u -r -d 1 $(pgrep script)# Monitor real-time CPU, memory, and I/O usage for a live process
Note: Low CPU percentage with long runtime indicates an I/O or locking bottleneck. High involuntary context switches mean the kernel is preempting your process due to heavy system load.
Leave a Reply