blob: 7400541a8d9232c7d98882283db277f0e57d2505 [file] [log] [blame]
Tamas Kenez5cf51bb2017-06-27 15:40:46 +02001#!/usr/bin/env python
2# Copyright (c) 2017, the R8 project authors. Please see the AUTHORS file
3# for details. All rights reserved. Use of this source code is governed by a
4# BSD-style license that can be found in the LICENSE file.
5
Rico Wind11c74c22018-08-31 08:11:42 +02006# Run D8 or DX on 'third_party/framework/framework_<version>.jar'.
Tamas Kenez5cf51bb2017-06-27 15:40:46 +02007# Report Golem-compatible CodeSize and RunTimeRaw values:
8#
Tamas Kenez8796a772017-06-28 12:44:44 +02009# <NAME>-Total(CodeSize): <size>
10# <NAME>-Total(RunTimeRaw>: <time> ms
Tamas Kenez5cf51bb2017-06-27 15:40:46 +020011#
12# and also detailed segment sizes for each dex segment:
13#
14# <NAME>-Code(CodeSize): <size>
15# <NAME>-AnnotationSets(CodeSize): <size>
16# ...
17#
18# Uses the DexSegment Java tool (Gradle target).
19
20from __future__ import print_function
21from glob import glob
22import argparse
Rico Wind1f4172c2018-09-06 16:29:03 +020023import golem
Tamas Kenez5cf51bb2017-06-27 15:40:46 +020024import os
25import re
26import subprocess
27import sys
28import time
29
30import utils
31
32DX_JAR = os.path.join(utils.REPO_ROOT, 'tools', 'linux', 'dx', 'framework',
33 'dx.jar')
Tamas Kenez5cf51bb2017-06-27 15:40:46 +020034FRAMEWORK_JAR = os.path.join('third_party', 'framework',
Rico Wind3a30c8f2017-08-16 09:13:35 +020035 'framework_14082017_desugared.jar')
Tamas Kenez5cf51bb2017-06-27 15:40:46 +020036MIN_SDK_VERSION = '24'
37
38def parse_arguments():
39 parser = argparse.ArgumentParser(
Rico Wind11c74c22018-08-31 08:11:42 +020040 description = 'Run D8 or DX'
Tamas Kenez391fca82017-06-29 18:16:01 +020041 ' third_party/framework/framework*.jar.'
Tamas Kenez5cf51bb2017-06-27 15:40:46 +020042 ' Report Golem-compatible CodeSize and RunTimeRaw values.')
43 parser.add_argument('--tool',
Rico Wind11c74c22018-08-31 08:11:42 +020044 choices = ['dx', 'd8', 'd8-release'],
Tamas Kenez5cf51bb2017-06-27 15:40:46 +020045 required = True,
46 help = 'Compiler tool to use.')
Rico Wind1f4172c2018-09-06 16:29:03 +020047 parser.add_argument('--golem',
48 help = 'Running on golem, link in third_party resources.',
49 default = False,
50 action = 'store_true')
Tamas Kenez5cf51bb2017-06-27 15:40:46 +020051 parser.add_argument('--name',
52 required = True,
53 help = 'Results will be printed using the specified benchmark name (e.g.'
Tamas Kenez13f68cf2017-08-10 13:19:41 +020054 ' <NAME>-<segment>(CodeSize): <bytes>), the full size is reported'
55 ' with <NAME>-Total(CodeSize)')
Tamas Kenezfc34cd82017-07-13 12:43:57 +020056 parser.add_argument('--print-memoryuse',
Morten Krogh-Jespersen38c7ca02019-02-04 10:39:57 +010057 help = 'Prints the line \'<NAME>-Total(MemoryUse):'
58 ' <mem>\' at the end where <mem> is the peak'
59 ' peak resident set size (VmHWM) in bytes.',
Tamas Kenezfc34cd82017-07-13 12:43:57 +020060 default = False,
61 action = 'store_true')
Søren Gjesseef3503b2017-08-25 09:20:40 +020062 parser.add_argument('--output',
Morten Krogh-Jespersen38c7ca02019-02-04 10:39:57 +010063 help = 'Output directory to keep the generated files')
Tamas Kenez5cf51bb2017-06-27 15:40:46 +020064 return parser.parse_args()
65
Tamas Kenez5cf51bb2017-06-27 15:40:46 +020066def Main():
Tamas Kenez2cf47cf2017-07-25 10:22:52 +020067 utils.check_java_version()
Tamas Kenez5cf51bb2017-06-27 15:40:46 +020068 args = parse_arguments()
Søren Gjesseef3503b2017-08-25 09:20:40 +020069 output_dir = args.output
Rico Wind1f4172c2018-09-06 16:29:03 +020070 if args.golem:
71 golem.link_third_party()
Tamas Kenez5cf51bb2017-06-27 15:40:46 +020072 with utils.TempDir() as temp_dir:
Tamas Kenez5cf51bb2017-06-27 15:40:46 +020073
Søren Gjesseef3503b2017-08-25 09:20:40 +020074 if not output_dir:
75 output_dir = temp_dir
76
Tamas Kenezca3f2822017-08-16 16:06:01 +020077 xmx = None
Rico Wind11c74c22018-08-31 08:11:42 +020078 if args.tool == 'dx':
Tamas Kenez391fca82017-06-29 18:16:01 +020079 tool_file = DX_JAR
Rico Wind11c74c22018-08-31 08:11:42 +020080 tool_args = ['--dex', '--output=' + output_dir, '--multi-dex',
81 '--min-sdk-version=' + MIN_SDK_VERSION]
Tamas Kenezca3f2822017-08-16 16:06:01 +020082 xmx = '-Xmx1600m'
Tamas Kenez391fca82017-06-29 18:16:01 +020083 else:
Rico Windb4621c12017-08-28 12:48:53 +020084 tool_file = utils.D8_JAR
Søren Gjesseef3503b2017-08-25 09:20:40 +020085 tool_args = ['--output', output_dir, '--min-api', MIN_SDK_VERSION]
Tamas Kenez391fca82017-06-29 18:16:01 +020086 if args.tool == 'd8-release':
87 tool_args.append('--release')
Tamas Kenezca3f2822017-08-16 16:06:01 +020088 xmx = '-Xmx600m'
Tamas Kenezfc34cd82017-07-13 12:43:57 +020089
90 cmd = []
91
92 track_memory_file = None
93 if args.print_memoryuse:
Søren Gjesseef3503b2017-08-25 09:20:40 +020094 track_memory_file = os.path.join(output_dir, utils.MEMORY_USE_TMP_FILE)
Tamas Kenezfc34cd82017-07-13 12:43:57 +020095 cmd.extend(['tools/track_memory.sh', track_memory_file])
96
Tamas Kenez391fca82017-06-29 18:16:01 +020097 if tool_file.endswith('.jar'):
Tamas Kenezca3f2822017-08-16 16:06:01 +020098 assert xmx is not None
99 cmd.extend(['java', xmx, '-jar'])
Tamas Kenez391fca82017-06-29 18:16:01 +0200100
101 cmd.extend([tool_file] + tool_args + [FRAMEWORK_JAR])
Tamas Kenez5cf51bb2017-06-27 15:40:46 +0200102
103 utils.PrintCmd(cmd)
104
105 t0 = time.time()
106 subprocess.check_call(cmd)
107 dt = time.time() - t0
108
Tamas Kenezfc34cd82017-07-13 12:43:57 +0200109 if args.print_memoryuse:
Tamas Kenez13f68cf2017-08-10 13:19:41 +0200110 print('{}-Total(MemoryUse): {}'
Tamas Kenezfc34cd82017-07-13 12:43:57 +0200111 .format(args.name, utils.grep_memoryuse(track_memory_file)))
112
Søren Gjesseef3503b2017-08-25 09:20:40 +0200113 dex_files = [f for f in glob(os.path.join(output_dir, '*.dex'))]
Tamas Kenez5cf51bb2017-06-27 15:40:46 +0200114 code_size = 0
115 for dex_file in dex_files:
116 code_size += os.path.getsize(dex_file)
117
Tamas Kenez8796a772017-06-28 12:44:44 +0200118 print('{}-Total(RunTimeRaw): {} ms'
Tamas Kenez5cf51bb2017-06-27 15:40:46 +0200119 .format(args.name, 1000.0 * dt))
120
Tamas Kenez8796a772017-06-28 12:44:44 +0200121 print('{}-Total(CodeSize): {}'
Tamas Kenez5cf51bb2017-06-27 15:40:46 +0200122 .format(args.name, code_size))
123
Tamas Kenez02bff032017-07-18 12:13:58 +0200124 utils.print_dexsegments(args.name, dex_files)
Tamas Kenez5cf51bb2017-06-27 15:40:46 +0200125
126if __name__ == '__main__':
127 sys.exit(Main())