blob: 4629d4b26b15dbb2ca24377fdd0408a8ec11071d [file] [log] [blame]
Mads Ager418d1ca2017-05-22 09:35:49 +02001#!/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
Christoffer Quist Adamsen69dbaad2018-07-05 15:37:31 +020019 exit $code
Mads Ager418d1ca2017-05-22 09:35:49 +020020}
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
Christoffer Quist Adamsen69dbaad2018-07-05 15:37:31 +020044code=$?