Ian Zerny | dcb172e | 2022-02-22 15:36:45 +0100 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 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 | |
Christoffer Quist Adamsen | 4d38d03 | 2021-04-20 12:31:31 +0200 | [diff] [blame] | 6 | import utils |
| 7 | |
| 8 | import optparse |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 9 | import sys |
Mathias Rav | dd6a6de | 2018-05-18 10:18:33 +0200 | [diff] [blame] | 10 | import toolhelper |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 11 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 12 | |
Christoffer Quist Adamsen | 4d38d03 | 2021-04-20 12:31:31 +0200 | [diff] [blame] | 13 | def ParseOptions(argv): |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 14 | parser = optparse.OptionParser(usage='%prog [options] -- [D8 options]') |
| 15 | parser.add_option('-c', |
| 16 | '--commit-hash', |
| 17 | '--commit_hash', |
| 18 | help='Commit hash of D8 to use.', |
| 19 | default=None) |
| 20 | parser.add_option('--print-runtimeraw', |
| 21 | '--print_runtimeraw', |
| 22 | metavar='BENCHMARKNAME', |
| 23 | help='Print the line \'<BENCHMARKNAME>(RunTimeRaw):' + |
| 24 | ' <elapsed> ms\' at the end where <elapsed> is' + |
| 25 | ' the elapsed time in milliseconds.') |
| 26 | parser.add_option('--version', help='Version of D8 to use.', default=None) |
| 27 | parser.add_option('--tag', help='Tag of D8 to use.', default=None) |
| 28 | return parser.parse_args(argv) |
| 29 | |
Christoffer Quist Adamsen | 4d38d03 | 2021-04-20 12:31:31 +0200 | [diff] [blame] | 30 | |
| 31 | def main(argv): |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 32 | (options, args) = ParseOptions(sys.argv) |
| 33 | d8_args = args[1:] |
| 34 | time_consumer = lambda duration: print_duration(duration, options) |
| 35 | return toolhelper.run('d8', |
| 36 | d8_args, |
| 37 | jar=utils.find_r8_jar_from_options(options), |
| 38 | main='com.android.tools.r8.D8', |
| 39 | time_consumer=time_consumer) |
| 40 | |
Christoffer Quist Adamsen | d7a5b72 | 2022-02-24 18:12:02 +0100 | [diff] [blame] | 41 | |
| 42 | def print_duration(duration, options): |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 43 | benchmark_name = options.print_runtimeraw |
| 44 | if benchmark_name: |
| 45 | print('%s-Total(RunTimeRaw): %s ms' % (benchmark_name, duration)) |
| 46 | |
Christoffer Quist Adamsen | 4d38d03 | 2021-04-20 12:31:31 +0200 | [diff] [blame] | 47 | |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 48 | if __name__ == '__main__': |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 49 | sys.exit(main(sys.argv[1:])) |