Mathias Rav | 92f3340 | 2018-05-22 14:26:45 +0200 | [diff] [blame] | 1 | #!/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 Wind | 1f4172c | 2018-09-06 16:29:03 +0200 | [diff] [blame] | 6 | import argparse |
Mathias Rav | 92f3340 | 2018-05-22 14:26:45 +0200 | [diff] [blame] | 7 | import os |
| 8 | import sys |
Ian Zerny | cded680 | 2018-06-15 13:30:32 +0200 | [diff] [blame] | 9 | |
Rico Wind | 1f4172c | 2018-09-06 16:29:03 +0200 | [diff] [blame] | 10 | import golem |
Ian Zerny | cded680 | 2018-06-15 13:30:32 +0200 | [diff] [blame] | 11 | import minify_tool |
| 12 | import toolhelper |
Mathias Rav | 92f3340 | 2018-05-22 14:26:45 +0200 | [diff] [blame] | 13 | import utils |
| 14 | |
Morten Krogh-Jespersen | ae64359 | 2019-10-29 16:34:37 +0100 | [diff] [blame] | 15 | MEMORY_XMX_LIMIT_BENCHMARK = 270 |
Mathias Rav | 92f3340 | 2018-05-22 14:26:45 +0200 | [diff] [blame] | 16 | |
Rico Wind | 1f4172c | 2018-09-06 16:29:03 +0200 | [diff] [blame] | 17 | def 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-Jespersen | ae64359 | 2019-10-29 16:34:37 +0100 | [diff] [blame] | 24 | parser.add_argument('--limit-memory-runtime-test', |
| 25 | help = 'Run in a specific memory limit.', |
| 26 | default = False, |
| 27 | action = 'store_true') |
Rico Wind | 1f4172c | 2018-09-06 16:29:03 +0200 | [diff] [blame] | 28 | return parser.parse_args(argv) |
| 29 | |
| 30 | |
Ian Zerny | cded680 | 2018-06-15 13:30:32 +0200 | [diff] [blame] | 31 | def 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 Rav | 92f3340 | 2018-05-22 14:26:45 +0200 | [diff] [blame] | 44 | |
| 45 | if __name__ == '__main__': |
Rico Wind | 1f4172c | 2018-09-06 16:29:03 +0200 | [diff] [blame] | 46 | options = parse_arguments(sys.argv[1:]) |
| 47 | if options.golem: |
| 48 | golem.link_third_party() |
Ian Zerny | cded680 | 2018-06-15 13:30:32 +0200 | [diff] [blame] | 49 | 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-Jespersen | ae64359 | 2019-10-29 16:34:37 +0100 | [diff] [blame] | 55 | 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 Zerny | cded680 | 2018-06-15 13:30:32 +0200 | [diff] [blame] | 62 | return_code = minify_tool.minify_tool( |
Morten Krogh-Jespersen | 38c7ca0 | 2019-02-04 10:39:57 +0100 | [diff] [blame] | 63 | input_jar=utils.PINNED_R8_JAR, |
Ian Zerny | cded680 | 2018-06-15 13:30:32 +0200 | [diff] [blame] | 64 | output_jar=r8_output, |
| 65 | debug=False, |
| 66 | build=False, |
| 67 | track_memory_file=memory_file, |
Morten Krogh-Jespersen | ae64359 | 2019-10-29 16:34:37 +0100 | [diff] [blame] | 68 | benchmark_name=benchmark_name, |
| 69 | java_args=java_args) |
| 70 | |
Ian Zerny | cded680 | 2018-06-15 13:30:32 +0200 | [diff] [blame] | 71 | if return_code != 0: |
| 72 | sys.exit(return_code) |
| 73 | |
Morten Krogh-Jespersen | ae64359 | 2019-10-29 16:34:37 +0100 | [diff] [blame] | 74 | if run_memory_test: |
| 75 | # We are not tracking code-size, so return early. |
| 76 | sys.exit(0) |
| 77 | |
Ian Zerny | cded680 | 2018-06-15 13:30:32 +0200 | [diff] [blame] | 78 | dex(r8_output, d8_r8_output) |
Morten Krogh-Jespersen | 16e925d | 2019-01-25 14:40:38 +0100 | [diff] [blame] | 79 | print "BootstrapR8(CodeSize):", utils.uncompressed_size(r8_output) |
| 80 | print "BootstrapR8Dex(CodeSize):", utils.uncompressed_size(d8_r8_output) |
Ian Zerny | cded680 | 2018-06-15 13:30:32 +0200 | [diff] [blame] | 81 | |
Morten Krogh-Jespersen | 38c7ca0 | 2019-02-04 10:39:57 +0100 | [diff] [blame] | 82 | dex(utils.PINNED_PGR8_JAR, d8_pg_output) |
| 83 | print "BootstrapR8PG(CodeSize):", utils.uncompressed_size( |
| 84 | utils.PINNED_PGR8_JAR) |
Morten Krogh-Jespersen | 16e925d | 2019-01-25 14:40:38 +0100 | [diff] [blame] | 85 | print "BootstrapR8PGDex(CodeSize):", utils.uncompressed_size(d8_pg_output) |
Ian Zerny | cded680 | 2018-06-15 13:30:32 +0200 | [diff] [blame] | 86 | |
Ian Zerny | 51ab19f | 2019-10-21 12:37:25 +0200 | [diff] [blame] | 87 | 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 Wind | 77d2ffb | 2018-06-28 14:07:50 +0200 | [diff] [blame] | 98 | sys.exit(0) |