blob: 2081ee2dfcc1d10a126c0494c938b5f85be59c14 [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
30def parse_arguments():
31 parser = argparse.ArgumentParser(
32 description = 'Run R8 or PG on'
33 ' third_party/r8/r8.jar.'
34 ' Report Golem-compatible CodeSize and RunTimeRaw values.')
35 parser.add_argument('--tool',
36 choices = ['pg', 'r8'],
37 required = True,
38 help = 'Compiler tool to use.')
Morten Krogh-Jespersen38c7ca02019-02-04 10:39:57 +010039 parser.add_argument('--name',
40 required = True,
41 help = 'Results will be printed using the specified benchmark name (e.g.'
42 ' <NAME>-<segment>(CodeSize): <bytes>), the full size is reported'
43 ' with <NAME>-Total(CodeSize)')
44 parser.add_argument('--print-memoryuse',
45 help = 'Prints the line \'<NAME>-Total(MemoryUse):'
46 ' <mem>\' at the end where <mem> is the peak'
47 ' peak resident set size (VmHWM) in bytes.',
48 default = False,
49 action = 'store_true')
50 parser.add_argument('--output',
51 help = 'Output directory to keep the generated files')
52 return parser.parse_args()
53
54
55def Main():
Morten Krogh-Jespersen38c7ca02019-02-04 10:39:57 +010056 args = parse_arguments()
Morten Krogh-Jespersenc32e3132019-02-22 11:34:26 +010057 utils.check_java_version()
58 output_dir = args.output
Morten Krogh-Jespersen38c7ca02019-02-04 10:39:57 +010059 with utils.TempDir() as temp_dir:
60 if not output_dir:
61 output_dir = temp_dir
62 track_memory_file = None
63 if args.print_memoryuse:
64 track_memory_file = os.path.join(output_dir, utils.MEMORY_USE_TMP_FILE)
65 if args.tool == 'pg':
66 utils.print_cfsegments(args.name, [utils.PINNED_PGR8_JAR])
67 else:
68 out_file = os.path.join(output_dir, 'out.jar')
69 return_code = minify_tool.minify_tool(
70 input_jar=utils.PINNED_R8_JAR,
71 output_jar=out_file,
72 debug=False,
73 build=False,
74 track_memory_file=track_memory_file,
75 benchmark_name=args.name + "-Total")
76 if return_code != 0:
77 sys.exit(return_code)
78
79 utils.print_cfsegments(args.name, [out_file])
80
81
82if __name__ == '__main__':
83 sys.exit(Main())