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