Performance Metrics for Scripts Using Command Line
To quickly collect performance metrics for a script via command line:
- Start running the script. Make note of the process name that the script is running as (e.g. ruby)
- Create a script called
profiler.sh
with this content:ps aux | grep $1 | head -1 | awk '{print "CPU="$3 ", MEM="$4 ", RSS="$6}'
- Make the profiler executable:
chmod +x profiler.sh
- Execute the profiler in a watch session every minute:
watch -n 60 --no-title "./profiler.sh SCRIPT_IDENTIFIER | tee -a logfile"
. Where the script identifier is any text that we can use to grep for the process in theps aux
output. - After your script is done running or you have enough data points, observe the output in
logfile
.
NOTE: RSS is resident set size
Written on November 8, 2016 by shahriyarnasir