blob: 483fc5c8e39e7b892a3f487ca7704badf5ac5bee [file] [log] [blame]
#!/usr/bin/env python
# Copyright (c) 2017, the R8 project authors. Please see the AUTHORS file
# for details. All rights reserved. Use of this source code is governed by a
# BSD-style license that can be found in the LICENSE file.
# Run D8, DX or Goyt on 'third_party/framework/framework_<version>.jar'.
# Report Golem-compatible CodeSize and RunTimeRaw values:
# <NAME>-Total(CodeSize): <size>
# <NAME>-Total(RunTimeRaw>: <time> ms
# and also detailed segment sizes for each dex segment:
# <NAME>-Code(CodeSize): <size>
# <NAME>-AnnotationSets(CodeSize): <size>
# ...
# Uses the DexSegment Java tool (Gradle target).
from __future__ import print_function
from glob import glob
import argparse
import os
import re
import subprocess
import sys
import time
import utils
DX_JAR = os.path.join(utils.REPO_ROOT, 'tools', 'linux', 'dx', 'framework',
GOYT_EXE = os.path.join('third_party', 'goyt',
FRAMEWORK_JAR = os.path.join('third_party', 'framework',
def parse_arguments():
parser = argparse.ArgumentParser(
description = 'Run D8, DX or Goyt on'
' third_party/framework/framework*.jar.'
' Report Golem-compatible CodeSize and RunTimeRaw values.')
choices = ['dx', 'd8', 'd8-release', 'goyt', 'goyt-release'],
required = True,
help = 'Compiler tool to use.')
required = True,
help = 'Results will be printed using the specified benchmark name (e.g.'
' <NAME>-<segment>(CodeSize): <bytes>), the full size is reported'
' with <NAME>-Total(CodeSize)')
help = 'Prints the line \'<NAME>-Total(MemoryUse):' +
' <mem>\' at the end where <mem> is the peak' +
' peak resident set size (VmHWM) in bytes.',
default = False,
action = 'store_true')
return parser.parse_args()
def Main():
args = parse_arguments()
with utils.TempDir() as temp_dir:
if args.tool in ['dx', 'goyt', 'goyt-release']:
tool_args = ['--dex', '--output=' + temp_dir, '--multi-dex',
'--min-sdk-version=' + MIN_SDK_VERSION]
xmx = None
if args.tool.startswith('goyt'):
tool_file = GOYT_EXE
tool_args = ['--num-threads=8'] + tool_args
if args.tool == 'goyt-release':
elif args.tool == 'dx':
tool_file = DX_JAR
xmx = '-Xmx1600m'
tool_file = utils.D8_JAR
tool_args = ['--output', temp_dir, '--min-api', MIN_SDK_VERSION]
if args.tool == 'd8-release':
xmx = '-Xmx600m'
cmd = []
track_memory_file = None
if args.print_memoryuse:
track_memory_file = os.path.join(temp_dir, utils.MEMORY_USE_TMP_FILE)
cmd.extend(['tools/', track_memory_file])
if tool_file.endswith('.jar'):
assert xmx is not None
cmd.extend(['java', xmx, '-jar'])
cmd.extend([tool_file] + tool_args + [FRAMEWORK_JAR])
t0 = time.time()
dt = time.time() - t0
if args.print_memoryuse:
print('{}-Total(MemoryUse): {}'
.format(, utils.grep_memoryuse(track_memory_file)))
dex_files = [f for f in glob(os.path.join(temp_dir, '*.dex'))]
code_size = 0
for dex_file in dex_files:
code_size += os.path.getsize(dex_file)
print('{}-Total(RunTimeRaw): {} ms'
.format(, 1000.0 * dt))
print('{}-Total(CodeSize): {}'
.format(, code_size))
utils.print_dexsegments(, dex_files)
if __name__ == '__main__':