blob: a40cf2addd3ac09cc44a118538aa0a412d874cff [file] [log] [blame]
Ian Zernydcb172e2022-02-22 15:36:45 +01001#!/usr/bin/env python3
Rico Windf9231222019-01-08 14:43:52 +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# Convenience script for running run_on_app.py finding minimum memory need for
7# compiling a given app back in time. This utilizes the prebuilt r8 jars on
8# cloud storage.
9# The script find all commits that exists on cloud storage in the given range.
10# It will then run the oldest and newest such commit, and gradually fill in
11# the commits in between.
12
Ian Zerny02a4b5b2019-10-21 13:32:41 +020013import historic_run
Rico Windf9231222019-01-08 14:43:52 +010014import optparse
15import os
16import subprocess
17import sys
18import utils
19
20APPS = ['gmscore', 'nest', 'youtube', 'gmail', 'chrome']
21COMPILERS = ['d8', 'r8']
22
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +020023
Rico Windf9231222019-01-08 14:43:52 +010024def ParseOptions(argv):
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +020025 result = optparse.OptionParser()
26 result.add_option('--compiler',
27 help='The compiler to use',
28 default='d8',
29 choices=COMPILERS)
30 result.add_option('--app',
31 help='What app to run on',
32 default='gmail',
33 choices=APPS)
34 result.add_option('--top',
35 default=historic_run.top_or_default(),
36 help='The most recent commit to test')
37 result.add_option('--bottom', help='The oldest commit to test')
38 result.add_option('--output',
39 default='build',
40 help='Directory where to output results')
41 result.add_option('--timeout',
42 type=int,
43 default=0,
44 help='Set timeout instead of waiting for OOM.')
45 return result.parse_args(argv)
46
Rico Windf9231222019-01-08 14:43:52 +010047
Ian Zerny02a4b5b2019-10-21 13:32:41 +020048def make_run_on_app_command(options):
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +020049 return lambda commit: run_on_app(options, commit)
50
Rico Windf9231222019-01-08 14:43:52 +010051
52def run_on_app(options, commit):
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +020053 app = options.app
54 compiler = options.compiler
55 cmd = [
56 'tools/run_on_app.py', '--app', app, '--compiler', compiler,
57 '--timeout',
58 str(options.timeout), '--no-build', '--find-min-xmx'
59 ]
60 stdout = subprocess.check_output(cmd)
61 output_path = options.output or 'build'
62 time_commit = '%s_%s' % (commit.timestamp, commit.git_hash)
63 time_commit_path = os.path.join(output_path, time_commit)
64 if not os.path.exists(time_commit_path):
65 os.makedirs(time_commit_path)
66 stdout_path = os.path.join(time_commit_path, 'stdout')
67 with open(stdout_path, 'w') as f:
68 f.write(stdout)
69 print('Wrote stdout to: %s' % stdout_path)
70
Rico Windf9231222019-01-08 14:43:52 +010071
Rico Windf9231222019-01-08 14:43:52 +010072def main(argv):
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +020073 (options, args) = ParseOptions(argv)
74 if not options.app:
75 raise Exception('Please specify an app')
76 top = historic_run.top_or_default(options.top)
77 bottom = historic_run.bottom_or_default(options.bottom)
78 command = make_run_on_app_command(options)
79 historic_run.run(command, top, bottom)
80
Rico Windf9231222019-01-08 14:43:52 +010081
82if __name__ == '__main__':
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +020083 sys.exit(main(sys.argv[1:]))