1#!/bin/bash 2 3# Copyright JS Foundation and other contributors, http://js.foundation 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16 17JERRY=$1 18TEST=$2 19SLEEP=0.1 20OS=`uname -s | tr [:upper:] [:lower:]` 21 22Rss_OUT="" 23 24function collect_entry() 25{ 26 OUT_NAME="$1_OUT"; 27 OUT=$OUT_NAME; 28 29 if [ "$OS" == "darwin" ] 30 then 31 SUM=`ps -o rss $PID | grep [0-9]` 32 else 33 SUM=$(grep -o -e "^[0-9a-f][0-9a-f]*.*" -e "^Rss.*" /proc/$PID/smaps 2>/dev/null | grep -A 1 -- "r[w-]-p " | grep "^Rss"|awk '{s += $2;} END {print s;}') 34 fi; 35 36 if [ "$SUM" != "" ]; 37 then 38 eval "$OUT=\"\$$OUT $SUM\\n\""; 39 fi; 40} 41 42function print_entry() 43{ 44 OUT_NAME="$1_OUT"; 45 OUT=$OUT_NAME; 46 47 eval "echo -e \"\$$OUT\"" | awk -v entry="$1" '{ if ($1 != "") { n += 1; if ($1 > max) { max = $1; } } } END { if (n == 0) { exit; }; printf "%d\n", max; }'; 48} 49 50function run_test() 51{ 52 $JERRY $TEST & 53 PID=$! 54 55 while kill -0 "$PID" > /dev/null 2>&1; 56 do 57 collect_entry Rss 58 59 sleep $SLEEP 60 done 61 62 wait "$PID" || exit 1 63} 64 65run_test 66 67print_entry Rss 68