1#!/bin/bash 2# Copyright (c) 2017, the R8 project authors. Please see the AUTHORS file 3# for details. All rights reserved. Use of this source code is governed by a 4# BSD-style license that can be found in the LICENSE file. 5# 6# Tracks the peak resident memory being used by running the supplied command. 7# The output is written to the first argument of the script every second. 8 9function Logger() { 10 output="$1" 11 while sleep 1 12 do 13 grep "VmHWM\|Threads" /proc/$pid/status >> $output 14 done 15} 16 17function Exit { 18 kill $lid 19 exit 0 20} 21 22function Kill { 23 kill $lid 24 kill -9 $pid 25 exit -1 26} 27 28if [ $# -lt 2 ]; then 29 echo "Takes at least two arguments" 30 exit 1 31fi 32OUTPUT_FILE=$1 33shift 1 34 35$* & 36pid=$! 37 38Logger $OUTPUT_FILE & 39lid=$! 40 41trap "Exit" EXIT 42trap "Kill" SIGINT 43wait $pid 44