• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
17# Choosing table or semicolon-separated output mode
18if [ "$1" == "-d" ]
19then
20  TABLE="no"
21  PRINT_TEST_NAME_AWK_SCRIPT='{printf "%s;", $1}'
22  PRINT_TOTAL_AWK_SCRIPT='{printf "%d;%d;%d\n", $1, $2, $3 * 1024}'
23
24  shift
25else
26  PRINT_TEST_NAME_AWK_SCRIPT='{printf "%30s", $1}'
27  PRINT_TOTAL_AWK_SCRIPT='{printf "%25d%25d%25d\n", $1, $2, $3 * 1024}'
28  TABLE="yes"
29fi
30
31function fail_msg
32{
33  echo "$1"
34  exit 1
35}
36
37# Engine
38
39# Check if the specified build supports memory statistics options
40function is_mem_stats_build
41{
42  [ -x "$1" ] || fail_msg "Engine '$1' is not executable"
43
44  tmpfile=`mktemp`
45  "$1" --mem-stats $tmpfile 2>&1 | grep -- "Ignoring JERRY_INIT_MEM_STATS flag because of !JMEM_STATS configuration." 2>&1 > /dev/null
46  code=$?
47  rm $tmpfile
48
49  return $code
50}
51
52JERRY="$1"
53shift
54is_mem_stats_build "$JERRY" || fail_msg "First engine specified should be built without memory statistics support"
55
56JERRY_MEM_STATS="$1"
57shift
58is_mem_stats_build "$JERRY_MEM_STATS" && fail_msg "Second engine specified should be built with memory statistics support"
59
60# Benchmarks list
61BENCHMARKS=""
62
63while [ $# -ne 0 ]
64do
65  BENCHMARKS="$BENCHMARKS $1"
66  shift
67done
68
69# Running
70if [ "$TABLE" == "yes" ]
71then
72  awk 'BEGIN {printf "%30s%25s%25s%25s\n", "Test name", "Peak Heap (parser)", "Peak Heap (execution)", "Maximum RSS"}'
73  echo
74fi
75
76for bench in $BENCHMARKS
77do
78  test=`basename $bench .js`
79
80  echo "$test" | awk "$PRINT_TEST_NAME_AWK_SCRIPT"
81  MEM_STATS=$("$JERRY_MEM_STATS" --mem-stats --mem-stats-separate $bench | grep -e "Peak allocated =" | grep -o "[0-9]*")
82  RSS=$(./tools/rss-measure.sh "$JERRY" $bench | tail -n 1 | grep -o "[0-9]*")
83  echo $MEM_STATS $RSS | xargs | awk "$PRINT_TOTAL_AWK_SCRIPT"
84done
85