Ian Zerny | 161ff74 | 2022-01-20 12:39:40 +0100 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | # Copyright (c) 2022, 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 | |
| 6 | import argparse |
| 7 | import os |
| 8 | import subprocess |
| 9 | import sys |
| 10 | |
| 11 | import gradle |
| 12 | import jdk |
| 13 | import utils |
| 14 | |
| 15 | NONLIB_BUILD_TARGET = 'R8WithRelocatedDeps' |
| 16 | NONLIB_TEST_BUILD_TARGETS = [utils.R8_TESTS_TARGET, utils.R8_TESTS_DEPS_TARGET] |
| 17 | |
| 18 | R8LIB_BUILD_TARGET = utils.R8LIB |
| 19 | R8LIB_TEST_BUILD_TARGETS = [utils.R8LIB_TESTS_TARGET, utils.R8LIB_TESTS_DEPS_TARGET] |
| 20 | |
| 21 | # The r8lib target is always the golem target. |
| 22 | GOLEM_BUILD_TARGETS = [R8LIB_BUILD_TARGET] + R8LIB_TEST_BUILD_TARGETS |
| 23 | |
Ian Zerny | d5061b3 | 2022-02-02 13:24:30 +0100 | [diff] [blame] | 24 | def get_golem_resource_path(benchmark): |
Ian Zerny | fa77642 | 2022-03-09 07:15:29 +0100 | [diff] [blame] | 25 | return os.path.join('benchmarks', benchmark) |
Ian Zerny | d5061b3 | 2022-02-02 13:24:30 +0100 | [diff] [blame] | 26 | |
Ian Zerny | 161ff74 | 2022-01-20 12:39:40 +0100 | [diff] [blame] | 27 | def get_jdk_home(options, benchmark): |
| 28 | if options.golem: |
Ian Zerny | d5061b3 | 2022-02-02 13:24:30 +0100 | [diff] [blame] | 29 | return os.path.join(get_golem_resource_path(benchmark), 'linux') |
Ian Zerny | 161ff74 | 2022-01-20 12:39:40 +0100 | [diff] [blame] | 30 | return None |
| 31 | |
| 32 | def parse_options(argv): |
| 33 | result = argparse.ArgumentParser(description = 'Run test-based benchmarks.') |
| 34 | result.add_argument('--golem', |
| 35 | help='Indicate this as a run on golem', |
| 36 | default=False, |
| 37 | action='store_true') |
| 38 | result.add_argument('--benchmark', |
| 39 | help='The test benchmark to run', |
| 40 | required=True) |
| 41 | result.add_argument('--target', |
| 42 | help='The test target to run', |
| 43 | required=True, |
Ian Zerny | 221a99b | 2022-03-09 15:08:26 +0100 | [diff] [blame^] | 44 | # These should 1:1 with benchmarks/BenchmarkTarget.java |
| 45 | choices=['d8', 'r8-full', 'r8-force', 'r8-compat']) |
Ian Zerny | 161ff74 | 2022-01-20 12:39:40 +0100 | [diff] [blame] | 46 | result.add_argument('--nolib', '--no-lib', '--no-r8lib', |
| 47 | help='Run the non-lib R8 build (default false)', |
| 48 | default=False, |
| 49 | action='store_true') |
| 50 | result.add_argument('--no-build', '--no_build', |
| 51 | help='Run without building first (default false)', |
| 52 | default=False, |
| 53 | action='store_true') |
| 54 | result.add_argument('--enable-assertions', '--enable_assertions', '-ea', |
| 55 | help='Enable assertions when running', |
| 56 | default=False, |
| 57 | action='store_true') |
| 58 | result.add_argument('--print-times', |
| 59 | help='Print timing information from r8', |
| 60 | default=False, |
| 61 | action='store_true') |
| 62 | result.add_argument('--temp', |
| 63 | help='A directory to use for temporaries and outputs.', |
| 64 | default=None) |
| 65 | return result.parse_known_args(argv) |
| 66 | |
| 67 | def main(argv): |
| 68 | (options, args) = parse_options(argv) |
| 69 | |
| 70 | if options.golem: |
| 71 | options.no_build = True |
| 72 | if options.nolib: |
| 73 | print("Error: golem should always run r8lib") |
| 74 | return 1 |
| 75 | |
| 76 | if options.nolib: |
| 77 | buildTargets = [NONLIB_BUILD_TARGET] + NONLIB_TEST_BUILD_TARGETS |
| 78 | r8jar = utils.R8_WITH_RELOCATED_DEPS_JAR |
| 79 | testjars = [utils.R8_TESTS_DEPS_JAR, utils.R8_TESTS_JAR] |
| 80 | else: |
| 81 | buildTargets = GOLEM_BUILD_TARGETS |
| 82 | r8jar = utils.R8LIB_JAR |
| 83 | testjars = [utils.R8LIB_TESTS_DEPS_JAR, utils.R8LIB_TESTS_JAR] |
| 84 | |
| 85 | if not options.no_build: |
| 86 | gradle.RunGradle(buildTargets + ['-Pno_internal']) |
| 87 | |
| 88 | return run(options, r8jar, testjars) |
| 89 | |
| 90 | def run(options, r8jar, testjars): |
| 91 | jdkhome = get_jdk_home(options, options.benchmark) |
| 92 | cmd = [jdk.GetJavaExecutable(jdkhome)] |
| 93 | if options.enable_assertions: |
| 94 | cmd.append('-ea') |
| 95 | if options.print_times: |
| 96 | cmd.append('-Dcom.android.tools.r8.printtimes=1') |
| 97 | cmd.extend(['-cp', ':'.join([r8jar] + testjars)]) |
| 98 | cmd.extend([ |
| 99 | 'com.android.tools.r8.benchmarks.BenchmarkMainEntryRunner', |
| 100 | options.benchmark, |
| 101 | options.target, |
Ian Zerny | 14f956b | 2022-02-24 13:57:55 +0100 | [diff] [blame] | 102 | 'golem' if options.golem else 'local', |
Ian Zerny | 161ff74 | 2022-01-20 12:39:40 +0100 | [diff] [blame] | 103 | ]) |
| 104 | return subprocess.check_call(cmd) |
| 105 | |
| 106 | if __name__ == '__main__': |
| 107 | sys.exit(main(sys.argv[1:])) |