blob: 99e0719ebd1caebfb20193974573a2c10f08f42f [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 or DX 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 golem
import jdk
import os
import re
import subprocess
import sys
import time
import utils
DX_JAR = os.path.join(utils.REPO_ROOT, 'tools', 'linux', 'dx', 'framework',
FRAMEWORK_JAR = os.path.join('third_party', 'framework',
def parse_arguments():
parser = argparse.ArgumentParser(
description = 'Run D8 or DX'
' third_party/framework/framework*.jar.'
' Report Golem-compatible CodeSize and RunTimeRaw values.')
choices = ['dx', 'd8', 'd8-release'],
required = True,
help = 'Compiler tool to use.')
help = 'Running on golem, link in third_party resources.',
default = False,
action = 'store_true')
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')
help = 'Output directory to keep the generated files')
return parser.parse_args()
def Main():
args = parse_arguments()
if args.golem:
output_dir = args.output
with utils.TempDir() as temp_dir:
if not output_dir:
output_dir = temp_dir
xmx = None
if args.tool == 'dx':
tool_file = DX_JAR
tool_args = ['--dex', '--output=' + output_dir, '--multi-dex',
'--min-sdk-version=' + MIN_SDK_VERSION]
xmx = '-Xmx1600m'
tool_file = utils.D8_JAR
tool_args = ['--output', output_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(output_dir, utils.MEMORY_USE_TMP_FILE)
cmd.extend(['tools/', track_memory_file])
if tool_file.endswith('.jar'):
assert xmx is not None
cmd.extend([jdk.GetJavaExecutable(), 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(output_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__':