Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 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 | |
| 9 | function Logger() { |
| 10 | output="$1" |
| 11 | while sleep 1 |
| 12 | do |
| 13 | grep "VmHWM\|Threads" /proc/$pid/status >> $output |
| 14 | done |
| 15 | } |
| 16 | |
| 17 | function Exit { |
| 18 | kill $lid |
Christoffer Quist Adamsen | 69dbaad | 2018-07-05 15:37:31 +0200 | [diff] [blame] | 19 | exit $code |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 20 | } |
| 21 | |
| 22 | function Kill { |
| 23 | kill $lid |
| 24 | kill -9 $pid |
| 25 | exit -1 |
| 26 | } |
| 27 | |
| 28 | if [ $# -lt 2 ]; then |
| 29 | echo "Takes at least two arguments" |
| 30 | exit 1 |
| 31 | fi |
| 32 | OUTPUT_FILE=$1 |
| 33 | shift 1 |
| 34 | |
| 35 | $* & |
| 36 | pid=$! |
| 37 | |
| 38 | Logger $OUTPUT_FILE & |
| 39 | lid=$! |
| 40 | |
| 41 | trap "Exit" EXIT |
| 42 | trap "Kill" SIGINT |
| 43 | wait $pid |
Christoffer Quist Adamsen | 69dbaad | 2018-07-05 15:37:31 +0200 | [diff] [blame] | 44 | code=$? |