blob: a480214bed0f8cf9dd5ef7392733c8fcb9aeeb3f [file] [log] [blame]
Mads Ager418d1ca2017-05-22 09:35:49 +02001#!/usr/bin/env python
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
Tamas Kenezfc34cd82017-07-13 12:43:57 +02006from __future__ import print_function
Tamas Kenez02bff032017-07-18 12:13:58 +02007from glob import glob
Rico Windb57bbc12018-09-20 19:23:32 +02008import copy
Mads Ager418d1ca2017-05-22 09:35:49 +02009import optparse
10import os
Mads Ager418d1ca2017-05-22 09:35:49 +020011import sys
Tamas Kenezf2ee2a32017-06-21 10:30:20 +020012import time
Mads Ager418d1ca2017-05-22 09:35:49 +020013
Søren Gjesse5ecb04a2017-06-13 09:44:32 +020014import gmail_data
Ian Zerny877c1862017-07-06 11:12:26 +020015import gmscore_data
Rico Wind1f4172c2018-09-06 16:29:03 +020016import golem
Christoffer Quist Adamsena2a58772018-10-03 09:47:46 +020017import nest_data
Mathias Ravdd6a6de2018-05-18 10:18:33 +020018import toolhelper
Ian Zerny877c1862017-07-06 11:12:26 +020019import utils
20import youtube_data
Rico Wind86bfc832018-09-18 07:48:21 +020021import chrome_data
Mads Ager418d1ca2017-05-22 09:35:49 +020022
23TYPES = ['dex', 'deploy', 'proguarded']
Christoffer Quist Adamsena2a58772018-10-03 09:47:46 +020024APPS = ['gmscore', 'nest', 'youtube', 'gmail', 'chrome']
Tamas Kenez63a51d02019-01-07 15:53:02 +010025COMPILERS = ['d8', 'r8']
26COMPILER_BUILDS = ['full', 'lib']
27
Rico Wind5fdec152018-12-17 09:16:14 +010028# We use this magic exit code to signal that the program OOM'ed
29OOM_EXIT_CODE = 42
Jinseong Jeon158a3f12019-02-08 01:40:59 -080030# According to Popen.returncode doc:
31# A negative value -N indicates that the child was terminated by signal N.
32TIMEOUT_KILL_CODE = -9
Mads Ager418d1ca2017-05-22 09:35:49 +020033
Tamas Kenez5b1c5852017-07-21 13:38:33 +020034def ParseOptions(argv):
Mads Ager418d1ca2017-05-22 09:35:49 +020035 result = optparse.OptionParser()
Søren Gjesse932881f2017-06-13 10:43:36 +020036 result.add_option('--compiler',
Rico Windb57bbc12018-09-20 19:23:32 +020037 help='The compiler to use',
Tamas Kenez5b1c5852017-07-21 13:38:33 +020038 choices=COMPILERS)
Tamas Kenez63a51d02019-01-07 15:53:02 +010039 result.add_option('--compiler-build',
40 help='Compiler build to use',
41 choices=COMPILER_BUILDS,
42 default='lib')
Mads Ager418d1ca2017-05-22 09:35:49 +020043 result.add_option('--app',
Rico Windb57bbc12018-09-20 19:23:32 +020044 help='What app to run on',
Mads Ager418d1ca2017-05-22 09:35:49 +020045 choices=APPS)
Rico Windb57bbc12018-09-20 19:23:32 +020046 result.add_option('--run-all',
47 help='Compile all possible combinations',
48 default=False,
49 action='store_true')
Mads Ager418d1ca2017-05-22 09:35:49 +020050 result.add_option('--type',
Tamas Kenez3fdaabd2017-06-15 13:05:12 +020051 help='Default for R8: deploy, for D8: proguarded',
Mads Ager418d1ca2017-05-22 09:35:49 +020052 choices=TYPES)
53 result.add_option('--out',
Rico Windb57bbc12018-09-20 19:23:32 +020054 help='Where to place the output',
Rico Winde9485ba2018-10-01 07:04:16 +020055 default=utils.BUILD)
Mads Ager418d1ca2017-05-22 09:35:49 +020056 result.add_option('--no-build',
Rico Windb57bbc12018-09-20 19:23:32 +020057 help='Run without building first',
Mads Ager418d1ca2017-05-22 09:35:49 +020058 default=False,
59 action='store_true')
Rico Wind5fdec152018-12-17 09:16:14 +010060 result.add_option('--find-min-xmx',
61 help='Find the minimum amount of memory we can run in',
62 default=False,
63 action='store_true')
Jinseong Jeon158a3f12019-02-08 01:40:59 -080064 result.add_option('--timeout',
65 type=int,
66 default=0,
67 help='Set timeout instead of waiting for OOM.')
Rico Wind1f4172c2018-09-06 16:29:03 +020068 result.add_option('--golem',
Rico Windb57bbc12018-09-20 19:23:32 +020069 help='Running on golem, do not build or download',
Rico Wind1f4172c2018-09-06 16:29:03 +020070 default=False,
71 action='store_true')
Rico Wind139eece2018-09-25 09:42:09 +020072 result.add_option('--ignore-java-version',
73 help='Do not check java version',
74 default=False,
75 action='store_true')
Mads Ager418d1ca2017-05-22 09:35:49 +020076 result.add_option('--no-libraries',
Rico Windb57bbc12018-09-20 19:23:32 +020077 help='Do not pass in libraries, even if they exist in conf',
Mads Ager418d1ca2017-05-22 09:35:49 +020078 default=False,
79 action='store_true')
80 result.add_option('--no-debug',
81 help='Run without debug asserts.',
82 default=False,
83 action='store_true')
84 result.add_option('--version',
Rico Windb57bbc12018-09-20 19:23:32 +020085 help='The version of the app to run')
Mads Ager418d1ca2017-05-22 09:35:49 +020086 result.add_option('-k',
87 help='Override the default ProGuard keep rules')
Tamas Kenez139acc12017-06-14 17:14:58 +020088 result.add_option('--compiler-flags',
89 help='Additional option(s) for the compiler. ' +
90 'If passing several options use a quoted string.')
Mads Ager418d1ca2017-05-22 09:35:49 +020091 result.add_option('--r8-flags',
Tamas Kenez139acc12017-06-14 17:14:58 +020092 help='Additional option(s) for the compiler. ' +
Tamas Kenezfc34cd82017-07-13 12:43:57 +020093 'Same as --compiler-flags, keeping it for backward'
94 ' compatibility. ' +
Mads Ager418d1ca2017-05-22 09:35:49 +020095 'If passing several options use a quoted string.')
Tamas Kenezfc34cd82017-07-13 12:43:57 +020096 # TODO(tamaskenez) remove track-memory-to-file as soon as we updated golem
97 # to use --print-memoryuse instead
Mads Ager418d1ca2017-05-22 09:35:49 +020098 result.add_option('--track-memory-to-file',
99 help='Track how much memory the jvm is using while ' +
100 ' compiling. Output to the specified file.')
101 result.add_option('--profile',
102 help='Profile R8 run.',
103 default=False,
104 action='store_true')
105 result.add_option('--dump-args-file',
106 help='Dump a file with the arguments for the specified ' +
107 'configuration. For use as a @<file> argument to perform ' +
108 'the run.')
Tamas Kenezf2ee2a32017-06-21 10:30:20 +0200109 result.add_option('--print-runtimeraw',
110 metavar='BENCHMARKNAME',
Tamas Kenez02bff032017-07-18 12:13:58 +0200111 help='Print the line \'<BENCHMARKNAME>(RunTimeRaw):' +
112 ' <elapsed> ms\' at the end where <elapsed> is' +
113 ' the elapsed time in milliseconds.')
Tamas Kenezfc34cd82017-07-13 12:43:57 +0200114 result.add_option('--print-memoryuse',
115 metavar='BENCHMARKNAME',
Tamas Kenez02bff032017-07-18 12:13:58 +0200116 help='Print the line \'<BENCHMARKNAME>(MemoryUse):' +
117 ' <mem>\' at the end where <mem> is the peak' +
118 ' peak resident set size (VmHWM) in bytes.')
119 result.add_option('--print-dexsegments',
120 metavar='BENCHMARKNAME',
121 help='Print the sizes of individual dex segments as ' +
122 '\'<BENCHMARKNAME>-<segment>(CodeSize): <bytes>\'')
Tamas Kenez5b1c5852017-07-21 13:38:33 +0200123 return result.parse_args(argv)
Mads Ager418d1ca2017-05-22 09:35:49 +0200124
Man Cao29b9ef12019-03-25 11:19:35 -0700125# Most apps have -printmapping, -printseeds, -printusage and
126# -printconfiguration in the Proguard configuration. However we don't
127# want to write these files in the locations specified.
128# Instead generate an auxiliary Proguard configuration placing these
129# output files together with the dex output.
Søren Gjesse3a5aed92017-06-14 15:36:02 +0200130def GenerateAdditionalProguardConfiguration(temp, outdir):
131 name = "output.config"
Tamas Kenezfc34cd82017-07-13 12:43:57 +0200132 with open(os.path.join(temp, name), 'w') as f:
133 f.write('-printmapping ' + os.path.join(outdir, 'proguard.map') + "\n")
134 f.write('-printseeds ' + os.path.join(outdir, 'proguard.seeds') + "\n")
Søren Gjesse59459582018-04-06 10:12:45 +0200135 f.write('-printusage ' + os.path.join(outdir, 'proguard.usage') + "\n")
Man Cao29b9ef12019-03-25 11:19:35 -0700136 f.write('-printconfiguration ' + os.path.join(outdir, 'proguard.config') + "\n")
Tamas Kenezfc34cd82017-07-13 12:43:57 +0200137 return os.path.abspath(f.name)
Søren Gjesse3a5aed92017-06-14 15:36:02 +0200138
Rico Wind3f9302b2018-09-21 08:53:09 +0200139# Please add bug number for disabled permutations and please explicitly
140# do Bug: #BUG in the commit message of disabling to ensure re-enabling
141DISABLED_PERMUTATIONS = [
Ian Zernyd459b5f2018-10-03 06:46:21 +0200142 # (app, version, type), e.g., ('gmail', '180826.15', 'deploy'),
Rico Winded788332018-12-14 10:39:20 +0100143 ('youtube', '13.37', 'deploy'), # b/120977564
Rico Wind3f9302b2018-09-21 08:53:09 +0200144]
145
Rico Windb57bbc12018-09-20 19:23:32 +0200146def get_permutations():
147 data_providers = {
148 'gmscore': gmscore_data,
Christoffer Quist Adamsena2a58772018-10-03 09:47:46 +0200149 'nest': nest_data,
Rico Windb57bbc12018-09-20 19:23:32 +0200150 'youtube': youtube_data,
151 'chrome': chrome_data,
152 'gmail': gmail_data
153 }
154 # Check to ensure that we add all variants here.
155 assert len(APPS) == len(data_providers)
156 for app, data in data_providers.iteritems():
157 for version in data.VERSIONS:
158 for type in data.VERSIONS[version]:
Rico Wind3f9302b2018-09-21 08:53:09 +0200159 if (app, version, type) not in DISABLED_PERMUTATIONS:
Tamas Keneza730a7e2018-12-10 15:02:28 +0100160 for use_r8lib in [False, True]:
161 yield app, version, type, use_r8lib
Rico Windb57bbc12018-09-20 19:23:32 +0200162
163def run_all(options, args):
164 # Args will be destroyed
165 assert len(args) == 0
Tamas Keneza730a7e2018-12-10 15:02:28 +0100166 for name, version, type, use_r8lib in get_permutations():
Rico Windb57bbc12018-09-20 19:23:32 +0200167 compiler = 'r8' if type == 'deploy' else 'd8'
Tamas Kenez63a51d02019-01-07 15:53:02 +0100168 compiler_build = 'lib' if use_r8lib else 'full'
169 print('Executing %s/%s with %s %s %s' % (compiler, compiler_build, name,
170 version, type))
Tamas Keneza730a7e2018-12-10 15:02:28 +0100171
Rico Windb57bbc12018-09-20 19:23:32 +0200172 fixed_options = copy.copy(options)
173 fixed_options.app = name
174 fixed_options.version = version
175 fixed_options.compiler = compiler
Tamas Kenez63a51d02019-01-07 15:53:02 +0100176 fixed_options.compiler_build = compiler_build
Rico Windb57bbc12018-09-20 19:23:32 +0200177 fixed_options.type = type
178 exit_code = run_with_options(fixed_options, [])
179 if exit_code != 0:
Tamas Kenez63a51d02019-01-07 15:53:02 +0100180 print('Failed %s %s %s with %s/%s' % (name, version, type, compiler,
181 compiler_build))
Rico Windb57bbc12018-09-20 19:23:32 +0200182 exit(exit_code)
183
Rico Wind5fdec152018-12-17 09:16:14 +0100184def find_min_xmx(options, args):
185 # Args will be destroyed
186 assert len(args) == 0
187 # If we can run in 128 MB then we are good (which we can for small examples
188 # or D8 on medium sized examples)
Jinseong Jeon158a3f12019-02-08 01:40:59 -0800189 not_working = 128 if options.compiler == 'd8' else 1024
Rico Wind5fdec152018-12-17 09:16:14 +0100190 working = 1024 * 8
191 exit_code = 0
192 while working - not_working > 32:
193 next_candidate = working - ((working - not_working)/2)
194 print('working: %s, non_working: %s, next_candidate: %s' %
195 (working, not_working, next_candidate))
196 extra_args = ['-Xmx%sM' % next_candidate]
197 new_options = copy.copy(options)
198 t0 = time.time()
199 exit_code = run_with_options(options, [], extra_args)
200 t1 = time.time()
201 print('Running took: %s ms' % (1000.0 * (t1 - t0)))
Jinseong Jeon158a3f12019-02-08 01:40:59 -0800202 if exit_code != 0:
203 if exit_code not in [OOM_EXIT_CODE, TIMEOUT_KILL_CODE]:
204 print('Non OOM/Timeout error executing, exiting')
205 return 2
Rico Wind5fdec152018-12-17 09:16:14 +0100206 if exit_code == 0:
207 working = next_candidate
Jinseong Jeon158a3f12019-02-08 01:40:59 -0800208 elif exit_code == TIMEOUT_KILL_CODE:
209 print('Timeout. Continue to the next candidate.')
210 not_working = next_candidate
Rico Wind5fdec152018-12-17 09:16:14 +0100211 else:
212 assert exit_code == OOM_EXIT_CODE
213 not_working = next_candidate
214
215 assert working - not_working <= 32
216 print('Found range: %s - %s' % (not_working, working))
217 return 0
218
Tamas Kenez5b1c5852017-07-21 13:38:33 +0200219def main(argv):
Tamas Kenez5b1c5852017-07-21 13:38:33 +0200220 (options, args) = ParseOptions(argv)
Rico Windb57bbc12018-09-20 19:23:32 +0200221 if options.run_all:
222 return run_all(options, args)
Rico Wind5fdec152018-12-17 09:16:14 +0100223 if options.find_min_xmx:
224 return find_min_xmx(options, args)
Rico Windb57bbc12018-09-20 19:23:32 +0200225 return run_with_options(options, args)
226
Tamas Kenez63a51d02019-01-07 15:53:02 +0100227def run_with_options(options, args, extra_args=None):
228 if extra_args is None:
229 extra_args = []
Rico Windb57bbc12018-09-20 19:23:32 +0200230 app_provided_pg_conf = False;
Rico Windadd08132018-12-14 14:17:15 +0100231 # todo(121018500): remove when memory is under control
Rico Wind20602b72019-01-09 09:17:13 +0100232 if not any('-Xmx' in arg for arg in extra_args):
233 extra_args.append('-Xmx8G')
Rico Wind1f4172c2018-09-06 16:29:03 +0200234 if options.golem:
235 golem.link_third_party()
Rico Wind9bd3f5f2018-10-01 10:53:18 +0200236 options.out = os.getcwd()
Rico Windafdbbfd2019-02-22 09:32:07 +0100237 if not options.ignore_java_version:
238 utils.check_java_version()
239
Mads Ager418d1ca2017-05-22 09:35:49 +0200240 outdir = options.out
241 data = None
242 if options.app == 'gmscore':
243 options.version = options.version or 'v9'
244 data = gmscore_data
Christoffer Quist Adamsena2a58772018-10-03 09:47:46 +0200245 elif options.app == 'nest':
246 options.version = options.version or '20180926'
247 data = nest_data
Mads Ager418d1ca2017-05-22 09:35:49 +0200248 elif options.app == 'youtube':
Søren Gjessecc33fb42017-06-09 10:25:08 +0200249 options.version = options.version or '12.22'
Mads Ager418d1ca2017-05-22 09:35:49 +0200250 data = youtube_data
Rico Wind86bfc832018-09-18 07:48:21 +0200251 elif options.app == 'chrome':
252 options.version = options.version or 'default'
253 data = chrome_data
Søren Gjesse5ecb04a2017-06-13 09:44:32 +0200254 elif options.app == 'gmail':
255 options.version = options.version or '170604.16'
256 data = gmail_data
Mads Ager418d1ca2017-05-22 09:35:49 +0200257 else:
Tamas Kenez5b1c5852017-07-21 13:38:33 +0200258 raise Exception("You need to specify '--app={}'".format('|'.join(APPS)))
259
260 if options.compiler not in COMPILERS:
261 raise Exception("You need to specify '--compiler={}'"
262 .format('|'.join(COMPILERS)))
Mads Ager418d1ca2017-05-22 09:35:49 +0200263
Tamas Kenez63a51d02019-01-07 15:53:02 +0100264 if options.compiler_build not in COMPILER_BUILDS:
265 raise Exception("You need to specify '--compiler-build={}'"
266 .format('|'.join(COMPILER_BUILDS)))
267
Mads Ager418d1ca2017-05-22 09:35:49 +0200268 if not options.version in data.VERSIONS.keys():
Tamas Kenezfc34cd82017-07-13 12:43:57 +0200269 print('No version {} for application {}'
270 .format(options.version, options.app))
271 print('Valid versions are {}'.format(data.VERSIONS.keys()))
Mads Ager418d1ca2017-05-22 09:35:49 +0200272 return 1
273
274 version = data.VERSIONS[options.version]
275
Tamas Kenez3fdaabd2017-06-15 13:05:12 +0200276 if not options.type:
Tamas Kenez63a51d02019-01-07 15:53:02 +0100277 options.type = 'deploy' if options.compiler == 'r8' \
Tamas Kenez3fdaabd2017-06-15 13:05:12 +0200278 else 'proguarded'
279
Mads Ager418d1ca2017-05-22 09:35:49 +0200280 if options.type not in version:
Tamas Kenezfc34cd82017-07-13 12:43:57 +0200281 print('No type {} for version {}'.format(options.type, options.version))
282 print('Valid types are {}'.format(version.keys()))
Mads Ager418d1ca2017-05-22 09:35:49 +0200283 return 1
284 values = version[options.type]
285 inputs = None
Tamas Kenezfc34cd82017-07-13 12:43:57 +0200286 # For R8 'deploy' the JAR is located using the Proguard configuration
Christoffer Quist Adamsena2a58772018-10-03 09:47:46 +0200287 # -injars option. For chrome and nest we don't have the injars in the
288 # proguard files.
Tamas Kenez63a51d02019-01-07 15:53:02 +0100289 if 'inputs' in values and (options.compiler != 'r8'
Rico Wind86bfc832018-09-18 07:48:21 +0200290 or options.type != 'deploy'
Christoffer Quist Adamsena2a58772018-10-03 09:47:46 +0200291 or options.app == 'chrome'
292 or options.app == 'nest'):
Mads Ager418d1ca2017-05-22 09:35:49 +0200293 inputs = values['inputs']
294
295 args.extend(['--output', outdir])
Ian Zerny877c1862017-07-06 11:12:26 +0200296 if 'min-api' in values:
297 args.extend(['--min-api', values['min-api']])
Søren Gjesse932881f2017-06-13 10:43:36 +0200298
Søren Gjesse8ae55eb2018-09-28 11:11:36 +0200299 if 'main-dex-list' in values:
300 args.extend(['--main-dex-list', values['main-dex-list']])
301
Tamas Kenez63a51d02019-01-07 15:53:02 +0100302 if options.compiler == 'r8':
Søren Gjesse932881f2017-06-13 10:43:36 +0200303 if 'pgconf' in values and not options.k:
Søren Gjesse74645302019-04-12 12:53:50 +0000304 for pgconf in values['pgconf']:
305 args.extend(['--pg-conf', pgconf])
306 app_provided_pg_conf = True
Søren Gjesse932881f2017-06-13 10:43:36 +0200307 if options.k:
308 args.extend(['--pg-conf', options.k])
Søren Gjessec801ecc2017-08-03 13:40:06 +0200309 if 'maindexrules' in values:
310 for rules in values['maindexrules']:
311 args.extend(['--main-dex-rules', rules])
Rico Wind79e4eb52018-12-13 13:00:49 +0100312 if 'allow-type-errors' in values:
313 extra_args.append('-Dcom.android.tools.r8.allowTypeErrors=1')
Søren Gjesse932881f2017-06-13 10:43:36 +0200314
Mads Ager418d1ca2017-05-22 09:35:49 +0200315 if not options.no_libraries and 'libraries' in values:
316 for lib in values['libraries']:
317 args.extend(['--lib', lib])
318
Tamas Kenezfc34cd82017-07-13 12:43:57 +0200319 if not outdir.endswith('.zip') and not outdir.endswith('.jar') \
320 and not os.path.exists(outdir):
Mads Ager418d1ca2017-05-22 09:35:49 +0200321 os.makedirs(outdir)
322
Søren Gjesse8ae55eb2018-09-28 11:11:36 +0200323 # Additional flags for the compiler from the configuration file.
324 if 'flags' in values:
325 args.extend(values['flags'].split(' '))
Tamas Kenez63a51d02019-01-07 15:53:02 +0100326 if options.compiler == 'r8':
Søren Gjesse932881f2017-06-13 10:43:36 +0200327 if 'r8-flags' in values:
328 args.extend(values['r8-flags'].split(' '))
Tamas Kenez139acc12017-06-14 17:14:58 +0200329
Søren Gjesse8ae55eb2018-09-28 11:11:36 +0200330 # Additional flags for the compiler from the command line.
Tamas Kenez139acc12017-06-14 17:14:58 +0200331 if options.compiler_flags:
332 args.extend(options.compiler_flags.split(' '))
333 if options.r8_flags:
334 args.extend(options.r8_flags.split(' '))
Mads Ager418d1ca2017-05-22 09:35:49 +0200335
336 if inputs:
337 args.extend(inputs)
338
Tamas Kenezf2ee2a32017-06-21 10:30:20 +0200339 t0 = time.time()
Mads Ager418d1ca2017-05-22 09:35:49 +0200340 if options.dump_args_file:
341 with open(options.dump_args_file, 'w') as args_file:
342 args_file.writelines([arg + os.linesep for arg in args])
343 else:
Tamas Kenezfc34cd82017-07-13 12:43:57 +0200344 with utils.TempDir() as temp:
345 if options.print_memoryuse and not options.track_memory_to_file:
346 options.track_memory_to_file = os.path.join(temp,
347 utils.MEMORY_USE_TMP_FILE)
Tamas Kenez63a51d02019-01-07 15:53:02 +0100348 if options.compiler == 'r8' and app_provided_pg_conf:
Mathias Ravdd6a6de2018-05-18 10:18:33 +0200349 # Ensure that output of -printmapping and -printseeds go to the output
350 # location and not where the app Proguard configuration places them.
351 if outdir.endswith('.zip') or outdir.endswith('.jar'):
352 pg_outdir = os.path.dirname(outdir)
353 else:
354 pg_outdir = outdir
355 additional_pg_conf = GenerateAdditionalProguardConfiguration(
356 temp, os.path.abspath(pg_outdir))
357 args.extend(['--pg-conf', additional_pg_conf])
Rico Wind1f4172c2018-09-06 16:29:03 +0200358 build = not options.no_build and not options.golem
Rico Wind5fdec152018-12-17 09:16:14 +0100359 stderr_path = os.path.join(temp, 'stderr')
360 with open(stderr_path, 'w') as stderr:
Tamas Kenez63a51d02019-01-07 15:53:02 +0100361 if options.compiler_build == 'full':
362 tool = options.compiler
363 else:
364 assert(options.compiler_build == 'lib')
365 tool = 'r8lib-' + options.compiler
366 exit_code = toolhelper.run(tool, args,
Rico Wind5fdec152018-12-17 09:16:14 +0100367 build=build,
368 debug=not options.no_debug,
369 profile=options.profile,
370 track_memory_file=options.track_memory_to_file,
Jinseong Jeon158a3f12019-02-08 01:40:59 -0800371 extra_args=extra_args,
372 stderr=stderr,
373 timeout=options.timeout)
Christoffer Quist Adamsen21c66602018-08-09 16:22:54 +0200374 if exit_code != 0:
Rico Wind5fdec152018-12-17 09:16:14 +0100375 with open(stderr_path) as stderr:
376 stderr_text = stderr.read()
377 print(stderr_text)
378 if 'java.lang.OutOfMemoryError' in stderr_text:
379 print('Failure was OOM')
380 return OOM_EXIT_CODE
381 return exit_code
Christoffer Quist Adamsen21c66602018-08-09 16:22:54 +0200382
Tamas Kenezfc34cd82017-07-13 12:43:57 +0200383 if options.print_memoryuse:
384 print('{}(MemoryUse): {}'
385 .format(options.print_memoryuse,
386 utils.grep_memoryuse(options.track_memory_to_file)))
Mads Ager418d1ca2017-05-22 09:35:49 +0200387
Tamas Kenezf2ee2a32017-06-21 10:30:20 +0200388 if options.print_runtimeraw:
389 print('{}(RunTimeRaw): {} ms'
390 .format(options.print_runtimeraw, 1000.0 * (time.time() - t0)))
391
Tamas Kenez02bff032017-07-18 12:13:58 +0200392 if options.print_dexsegments:
393 dex_files = glob(os.path.join(outdir, '*.dex'))
394 utils.print_dexsegments(options.print_dexsegments, dex_files)
Rico Windb57bbc12018-09-20 19:23:32 +0200395 return 0
Tamas Kenez02bff032017-07-18 12:13:58 +0200396
Mads Ager418d1ca2017-05-22 09:35:49 +0200397if __name__ == '__main__':
Tamas Kenez5b1c5852017-07-21 13:38:33 +0200398 sys.exit(main(sys.argv[1:]))