blob: bc0734724e4185426dff050ddb6d965461f09812 [file] [log] [blame]
Mathias Rav92f33402018-05-22 14:26:45 +02001#!/usr/bin/env python
2# Copyright (c) 2018, 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 Wind1f4172c2018-09-06 16:29:03 +02006import argparse
Mathias Rav92f33402018-05-22 14:26:45 +02007import os
8import sys
Ian Zernycded6802018-06-15 13:30:32 +02009
Rico Wind1f4172c2018-09-06 16:29:03 +020010import golem
Ian Zernycded6802018-06-15 13:30:32 +020011import minify_tool
12import toolhelper
Mathias Rav92f33402018-05-22 14:26:45 +020013import utils
14
Morten Krogh-Jespersenae643592019-10-29 16:34:37 +010015MEMORY_XMX_LIMIT_BENCHMARK = 270
Mathias Rav92f33402018-05-22 14:26:45 +020016
Rico Wind1f4172c2018-09-06 16:29:03 +020017def parse_arguments(argv):
18 parser = argparse.ArgumentParser(
19 description = 'Run r8 bootstrap benchmarks.')
20 parser.add_argument('--golem',
21 help = 'Link in third party dependencies.',
22 default = False,
23 action = 'store_true')
Morten Krogh-Jespersenae643592019-10-29 16:34:37 +010024 parser.add_argument('--limit-memory-runtime-test',
25 help = 'Run in a specific memory limit.',
26 default = False,
27 action = 'store_true')
Rico Wind1f4172c2018-09-06 16:29:03 +020028 return parser.parse_args(argv)
29
30
Ian Zernycded6802018-06-15 13:30:32 +020031def dex(input, output):
32 return_code = toolhelper.run(
33 'd8', [
34 input,
35 '--output', output,
36 '--lib', utils.RT_JAR,
37 '--min-api', '10000',
38 '--no-desugaring',
39 ],
40 debug=False,
41 build=False)
42 if return_code != 0:
43 sys.exit(return_code)
Mathias Rav92f33402018-05-22 14:26:45 +020044
45if __name__ == '__main__':
Rico Wind1f4172c2018-09-06 16:29:03 +020046 options = parse_arguments(sys.argv[1:])
47 if options.golem:
48 golem.link_third_party()
Ian Zernycded6802018-06-15 13:30:32 +020049 with utils.TempDir() as temp:
50 memory_file = os.path.join(temp, 'memory.dump')
51 r8_output = os.path.join(temp, 'r8.zip')
52 d8_r8_output = os.path.join(temp, 'd8r8.zip')
53 d8_pg_output = os.path.join(temp, 'd8pg.zip')
54
Morten Krogh-Jespersenae643592019-10-29 16:34:37 +010055 run_memory_test = options.limit_memory_runtime_test
56
57 java_args = (['-Xmx%sM' % MEMORY_XMX_LIMIT_BENCHMARK]
58 if run_memory_test else [])
59
60 benchmark_name = "MemoryR8Pinned" if run_memory_test else "BootstrapR8"
61
Ian Zernycded6802018-06-15 13:30:32 +020062 return_code = minify_tool.minify_tool(
Morten Krogh-Jespersen38c7ca02019-02-04 10:39:57 +010063 input_jar=utils.PINNED_R8_JAR,
Ian Zernycded6802018-06-15 13:30:32 +020064 output_jar=r8_output,
65 debug=False,
66 build=False,
67 track_memory_file=memory_file,
Morten Krogh-Jespersenae643592019-10-29 16:34:37 +010068 benchmark_name=benchmark_name,
69 java_args=java_args)
70
Ian Zernycded6802018-06-15 13:30:32 +020071 if return_code != 0:
72 sys.exit(return_code)
73
Morten Krogh-Jespersenae643592019-10-29 16:34:37 +010074 if run_memory_test:
75 # We are not tracking code-size, so return early.
76 sys.exit(0)
77
Ian Zernycded6802018-06-15 13:30:32 +020078 dex(r8_output, d8_r8_output)
Morten Krogh-Jespersen16e925d2019-01-25 14:40:38 +010079 print "BootstrapR8(CodeSize):", utils.uncompressed_size(r8_output)
80 print "BootstrapR8Dex(CodeSize):", utils.uncompressed_size(d8_r8_output)
Ian Zernycded6802018-06-15 13:30:32 +020081
Morten Krogh-Jespersen38c7ca02019-02-04 10:39:57 +010082 dex(utils.PINNED_PGR8_JAR, d8_pg_output)
83 print "BootstrapR8PG(CodeSize):", utils.uncompressed_size(
84 utils.PINNED_PGR8_JAR)
Morten Krogh-Jespersen16e925d2019-01-25 14:40:38 +010085 print "BootstrapR8PGDex(CodeSize):", utils.uncompressed_size(d8_pg_output)
Ian Zernycded6802018-06-15 13:30:32 +020086
Ian Zerny51ab19f2019-10-21 12:37:25 +020087 r8_notreeshaking_output = os.path.join(temp, 'r8-notreeshaking.zip')
88 return_code = minify_tool.minify_tool(
89 input_jar=utils.PINNED_R8_JAR,
90 output_jar=r8_notreeshaking_output,
91 debug=False,
92 build=False,
93 benchmark_name="BootstrapR8NoTreeShaking",
94 additional_args=["--no-tree-shaking"])
95 if return_code != 0:
96 sys.exit(return_code)
97
Rico Wind77d2ffb2018-06-28 14:07:50 +020098 sys.exit(0)