Skip to content

Instantly share code, notes, and snippets.

@jamesdbowman
Created March 20, 2013 06:01
Show Gist options
  • Save jamesdbowman/5202634 to your computer and use it in GitHub Desktop.
Save jamesdbowman/5202634 to your computer and use it in GitHub Desktop.
Bash script to run valgrind a number of times and collect the peak memory usages.
#!/bin/bash
echo "Size, Max Heap"
for i in {1..10}
do
SIZE=$(echo "2^"$i | bc)
RES=$(valgrind --tool=massif --time-unit=B ./a.out 0 $SIZE &> /dev/null)
MEM=$(grep -B 2 "heap_tree=peak" massif.out.* | awk -F '\n' 'ln ~ /^$/ { ln = "matched"; print $1 } $1 ~ /^--$/ { ln = "" }')
MEMARR=(${MEM//=/ })
echo $SIZE", "${MEMARR[1]}
rm massif.out.*
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment