Improve the heap limit measure tool (#2092)
Changes: * Added support for Python3 * Suppressed the build output text * Code cleanup * Fixed pylint warnings JerryScript-DCO-1.0-Signed-off-by: Peter Gal pgal.u-szeged@partner.samsung.com
This commit is contained in:
+44
-47
@@ -13,6 +13,9 @@
|
|||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
from __future__ import print_function
|
||||||
|
# force // operator to be integer division in Python 2
|
||||||
|
from __future__ import division
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import json
|
import json
|
||||||
@@ -20,75 +23,66 @@ import os
|
|||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from subprocess import Popen, PIPE, STDOUT
|
TOOLS_PATH = os.path.dirname(os.path.realpath(__file__))
|
||||||
|
BASE_PATH = os.path.join(TOOLS_PATH, '..')
|
||||||
|
|
||||||
|
|
||||||
BIN_JERRY = os.path.join(os.getcwd(), 'build/bin/jerry')
|
|
||||||
FLAG_CLEAN = '--clean'
|
FLAG_CLEAN = '--clean'
|
||||||
FLAG_DEBUG = '--debug'
|
FLAG_DEBUG = '--debug'
|
||||||
FLAG_HEAPLIMIT = '--mem-heap'
|
FLAG_HEAPLIMIT = '--mem-heap'
|
||||||
JERRY_BUILDER = os.path.join(os.getcwd(), 'tools/build.py')
|
JERRY_BUILDER = os.path.join(BASE_PATH, 'tools', 'build.py')
|
||||||
TEST_DIR = os.path.join(os.getcwd(), 'tests')
|
JERRY_BIN = os.path.join(BASE_PATH, 'build', 'bin', 'jerry')
|
||||||
|
TEST_DIR = os.path.join(BASE_PATH, 'tests')
|
||||||
|
|
||||||
|
|
||||||
def get_args():
|
def get_args():
|
||||||
""" Parse input arguments. """
|
""" Parse input arguments. """
|
||||||
parser = argparse.ArgumentParser(description='Finds the smallest possible \
|
desc = 'Finds the smallest possible JerryHeap size without failing to run the given js file'
|
||||||
size of JerryHeap without failing to run the given js file')
|
parser = argparse.ArgumentParser(description=desc)
|
||||||
parser.add_argument('testfile')
|
parser.add_argument('testfile')
|
||||||
parser.add_argument('--heapsize', type=int, default=512,
|
parser.add_argument('--heapsize', type=int, default=512,
|
||||||
help='Set the limit of the first heapsize')
|
help='set the limit of the first heapsize (default: %(default)d)')
|
||||||
|
parser.add_argument('--buildtype', choices=['release', 'debug'], default='release',
|
||||||
parser.add_argument('--buildtype', type=str,
|
help='select build type (default: %(default)s)')
|
||||||
help='debug build, default release build')
|
|
||||||
|
|
||||||
script_args = parser.parse_args()
|
script_args = parser.parse_args()
|
||||||
|
|
||||||
return script_args
|
return script_args
|
||||||
|
|
||||||
|
|
||||||
def is_exe(fpath):
|
def check_files(opts):
|
||||||
""" Check whether the file is exist. """
|
files = [JERRY_BUILDER, opts.testfile]
|
||||||
return os.path.isfile(fpath)
|
for file in files:
|
||||||
|
if not os.path.isfile(file):
|
||||||
|
sys.exit("File not found: %s" % file)
|
||||||
def init(opts):
|
|
||||||
if not is_exe(JERRY_BUILDER):
|
|
||||||
sys.exit("Builder script isn't a file!")
|
|
||||||
if not is_exe(opts.testfile):
|
|
||||||
sys.exit("Testfile isn't a file!")
|
|
||||||
|
|
||||||
|
|
||||||
def build_bin(heapsize, opts):
|
def build_bin(heapsize, opts):
|
||||||
""" Run tools/build.py script """
|
""" Run tools/build.py script """
|
||||||
hsize = str(heapsize)
|
command = [
|
||||||
|
JERRY_BUILDER,
|
||||||
|
FLAG_CLEAN,
|
||||||
|
FLAG_HEAPLIMIT,
|
||||||
|
str(heapsize)
|
||||||
|
]
|
||||||
|
|
||||||
if opts.buildtype == 'debug':
|
if opts.buildtype == 'debug':
|
||||||
subprocess.call([JERRY_BUILDER, FLAG_CLEAN, FLAG_HEAPLIMIT, \
|
command.append(FLAG_DEBUG)
|
||||||
hsize, FLAG_DEBUG])
|
|
||||||
else:
|
|
||||||
subprocess.call([JERRY_BUILDER, FLAG_CLEAN, FLAG_HEAPLIMIT, hsize])
|
|
||||||
|
|
||||||
|
print('Building JerryScript with: %s' % (' '.join(command)))
|
||||||
def get_output(cwd, cmd):
|
subprocess.check_output(command)
|
||||||
""" Run the given command and return with the output. """
|
|
||||||
process = Popen(cmd, stdout=PIPE, stderr=STDOUT, cwd=cwd)
|
|
||||||
|
|
||||||
output = process.communicate()[0]
|
|
||||||
exitcode = process.returncode
|
|
||||||
|
|
||||||
return output, exitcode
|
|
||||||
|
|
||||||
|
|
||||||
def run_test(opts):
|
def run_test(opts):
|
||||||
""" Run the testfile for output and exitcode. """
|
""" Run the testfile to get the exitcode. """
|
||||||
try:
|
try:
|
||||||
testfile = os.path.abspath(opts.testfile)
|
testfile = os.path.abspath(opts.testfile)
|
||||||
run_cmd = [BIN_JERRY, testfile]
|
run_cmd = [JERRY_BIN, testfile]
|
||||||
output, ret = get_output(TEST_DIR, run_cmd)
|
# check output will raise an error if the exit code is not 0
|
||||||
|
subprocess.check_output(run_cmd, cwd=TEST_DIR)
|
||||||
except subprocess.CalledProcessError as err:
|
except subprocess.CalledProcessError as err:
|
||||||
output = err.output
|
return err.returncode
|
||||||
ret = err.returncode
|
|
||||||
|
|
||||||
return opts.testfile, output, ret
|
return 0
|
||||||
|
|
||||||
|
|
||||||
def heap_limit(opts):
|
def heap_limit(opts):
|
||||||
@@ -99,21 +93,24 @@ def heap_limit(opts):
|
|||||||
|
|
||||||
while lowheap < hiheap:
|
while lowheap < hiheap:
|
||||||
build_bin(hiheap, opts)
|
build_bin(hiheap, opts)
|
||||||
assert is_exe(BIN_JERRY), 'Binary file not exist'
|
assert os.path.isfile(JERRY_BIN), 'Jerry binary file does not exists'
|
||||||
|
|
||||||
testfile, output, exitcode = run_test(opts)
|
exitcode = run_test(opts)
|
||||||
if exitcode != 0:
|
if exitcode != 0:
|
||||||
lowheap = hiheap
|
lowheap = hiheap
|
||||||
hiheap = (lowheap + goodheap) / 2
|
hiheap = (lowheap + goodheap) // 2
|
||||||
else:
|
else:
|
||||||
goodheap = hiheap
|
goodheap = hiheap
|
||||||
hiheap = (lowheap + hiheap) / 2
|
hiheap = (lowheap + hiheap) // 2
|
||||||
|
|
||||||
return { 'testfile': testfile, 'heaplimit to pass': goodheap }
|
return {
|
||||||
|
'testfile': opts.testfile,
|
||||||
|
'heaplimit to pass': goodheap
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def main(options):
|
def main(options):
|
||||||
init(options)
|
check_files(options)
|
||||||
result = heap_limit(options)
|
result = heap_limit(options)
|
||||||
print(json.dumps(result, indent=4))
|
print(json.dumps(result, indent=4))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user