Skip to content

Instantly share code, notes, and snippets.

@qxcv
Created January 16, 2020 19:03
Show Gist options
  • Save qxcv/e61784a7ceb82eaa5b61e8711bc95f95 to your computer and use it in GitHub Desktop.
Save qxcv/e61784a7ceb82eaa5b61e8711bc95f95 to your computer and use it in GitHub Desktop.
Bash script to track peak system memory usage (mem + swap)
#!/bin/bash
max_mem=0
while [ true ]; do
# awk trick from https://stackoverflow.com/a/450821
mem="$(free --giga | sed 's/ \+/ /g' | cut -d ' ' -f 3 | tail -n +2 | awk '{s+=$1} END {print s}')"
if [ "$mem" -gt "$max_mem" ]; then
max_mem="$mem"
echo "new peak ${max_mem}GB at $(date)"
fi
sleep 0.1
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment