Ian Zerny | dcb172e | 2022-02-22 15:36:45 +0100 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Morten Krogh-Jespersen | 38c7ca0 | 2019-02-04 10:39:57 +0100 | [diff] [blame] | 2 | # Copyright (c) 2019, 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 | # Run R8 or PG on 'third_party/r8/r8.jar'. |
| 7 | # Report Golem-compatible CodeSize and RunTimeRaw values: |
| 8 | # |
| 9 | # <NAME>-Total(CodeSize): <size> |
| 10 | # <NAME>-Total(RunTimeRaw>: <time> ms |
| 11 | # |
| 12 | # and also detailed segment sizes for each classfile segment: |
| 13 | # |
| 14 | # <NAME>-Code(CodeSize): <size> |
| 15 | # <NAME>-AnnotationSets(CodeSize): <size> |
| 16 | # ... |
| 17 | # |
Morten Krogh-Jespersen | 480784d | 2019-02-05 08:10:46 +0100 | [diff] [blame] | 18 | # Uses the R8CfSegments Java tool which is downloaded as an x20 dependency. |
| 19 | # To make changes to the R8CfSegments tool one can use the gradle target - |
| 20 | # remember to update the x20 dependency afterwards if you want the numbers |
| 21 | # tracked. |
Morten Krogh-Jespersen | 38c7ca0 | 2019-02-04 10:39:57 +0100 | [diff] [blame] | 22 | |
| 23 | from __future__ import print_function |
| 24 | import argparse |
Morten Krogh-Jespersen | 38c7ca0 | 2019-02-04 10:39:57 +0100 | [diff] [blame] | 25 | import minify_tool |
| 26 | import os |
| 27 | import sys |
| 28 | import utils |
| 29 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 30 | |
Morten Krogh-Jespersen | 38c7ca0 | 2019-02-04 10:39:57 +0100 | [diff] [blame] | 31 | def parse_arguments(): |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 32 | parser = argparse.ArgumentParser( |
| 33 | description='Run R8 or PG on' |
| 34 | ' third_party/r8/r8.jar.' |
| 35 | ' Report Golem-compatible CodeSize and RunTimeRaw values.') |
| 36 | parser.add_argument('--tool', |
| 37 | choices=['pg', 'r8'], |
| 38 | required=True, |
| 39 | help='Compiler tool to use.') |
| 40 | parser.add_argument( |
| 41 | '--name', |
| 42 | required=True, |
| 43 | help='Results will be printed using the specified benchmark name (e.g.' |
| 44 | ' <NAME>-<segment>(CodeSize): <bytes>), the full size is reported' |
| 45 | ' with <NAME>-Total(CodeSize)') |
| 46 | parser.add_argument('--print-memoryuse', |
| 47 | help='Prints the line \'<NAME>-Total(MemoryUse):' |
| 48 | ' <mem>\' at the end where <mem> is the peak' |
| 49 | ' peak resident set size (VmHWM) in bytes.', |
| 50 | default=False, |
| 51 | action='store_true') |
| 52 | parser.add_argument('--output', |
| 53 | help='Output directory to keep the generated files') |
| 54 | return parser.parse_args() |
Morten Krogh-Jespersen | 38c7ca0 | 2019-02-04 10:39:57 +0100 | [diff] [blame] | 55 | |
| 56 | |
| 57 | def Main(): |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 58 | args = parse_arguments() |
| 59 | utils.check_java_version() |
| 60 | output_dir = args.output |
| 61 | with utils.TempDir() as temp_dir: |
| 62 | if not output_dir: |
| 63 | output_dir = temp_dir |
| 64 | track_memory_file = None |
| 65 | if args.print_memoryuse: |
| 66 | track_memory_file = os.path.join(output_dir, |
| 67 | utils.MEMORY_USE_TMP_FILE) |
| 68 | if args.tool == 'pg': |
| 69 | utils.print_cfsegments(args.name, [utils.PINNED_PGR8_JAR]) |
| 70 | else: |
| 71 | out_file = os.path.join(output_dir, 'out.jar') |
| 72 | return_code = minify_tool.minify_tool( |
| 73 | input_jar=utils.PINNED_R8_JAR, |
| 74 | output_jar=out_file, |
| 75 | debug=False, |
| 76 | build=False, |
| 77 | track_memory_file=track_memory_file, |
| 78 | benchmark_name=args.name + "-Total") |
| 79 | if return_code != 0: |
| 80 | sys.exit(return_code) |
Morten Krogh-Jespersen | 38c7ca0 | 2019-02-04 10:39:57 +0100 | [diff] [blame] | 81 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 82 | utils.print_cfsegments(args.name, [out_file]) |
Morten Krogh-Jespersen | 38c7ca0 | 2019-02-04 10:39:57 +0100 | [diff] [blame] | 83 | |
| 84 | |
| 85 | if __name__ == '__main__': |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 86 | sys.exit(Main()) |