summaryrefslogtreecommitdiff
path: root/2019/rust/mem-measure_most.sh
blob: b7dd4a2b7d2ecf458df3aa4b847c4bfd6dedfedc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/bin/zsh -e

for DIR in day*
do
  cd "${DIR}"
  cargo build --release

  if [ -e part_one.sh ]; then
    PARTS="part_one.sh part_two.sh"
  else
    PARTS="both_parts.sh"
  fi

  # https://stackoverflow.com/q/774556/peak-memory-usage-of-a--process
  for PART in `echo ${PARTS}`
  do
    OUT="${PART%*.sh}"
    OUT="${OUT#*_}.txt"
    VG="valgrind --tool=massif --pages-as-heap=yes \
            --massif-out-file=massif.out" \
        ./${PART}; grep mem_heap_B massif.out | \
        sed -e 's/mem_heap_B=\(.*\)/\1/' | sort -g | tail -n 1 \
        > "memmax-${OUT}"
    MEM=`cat "memmax-${OUT}"`
    echo ${DIR} MEM: ${MEM} $[ MEM / 1024. ]k $[ MEM /1024./1024 ]M
  done
  cd ..
done