blob: 7b21fa5516b910832fee563e67efe9523f3aced6 [file] [log] [blame]
Ian Zernydcb172e2022-02-22 15:36:45 +01001#!/usr/bin/env python3
Morten Krogh-Jespersen38c7ca02019-02-04 10:39:57 +01002# 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-Jespersen480784d2019-02-05 08:10:46 +010018# 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-Jespersen38c7ca02019-02-04 10:39:57 +010022
23from __future__ import print_function
24import argparse
Morten Krogh-Jespersen38c7ca02019-02-04 10:39:57 +010025import minify_tool
26import os
27import sys
28import utils
29
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +020030
Morten Krogh-Jespersen38c7ca02019-02-04 10:39:57 +010031def parse_arguments():
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +020032 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-Jespersen38c7ca02019-02-04 10:39:57 +010055
56
57def Main():
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +020058 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-Jespersen38c7ca02019-02-04 10:39:57 +010081
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +020082 utils.print_cfsegments(args.name, [out_file])
Morten Krogh-Jespersen38c7ca02019-02-04 10:39:57 +010083
84
85if __name__ == '__main__':
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +020086 sys.exit(Main())