Ian Zerny | dcb172e | 2022-02-22 15:36:45 +0100 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Rico Wind | f923122 | 2019-01-08 14:43:52 +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 | # 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 Zerny | 02a4b5b | 2019-10-21 13:32:41 +0200 | [diff] [blame] | 13 | import historic_run |
Rico Wind | f923122 | 2019-01-08 14:43:52 +0100 | [diff] [blame] | 14 | import optparse |
| 15 | import os |
| 16 | import subprocess |
| 17 | import sys |
| 18 | import utils |
| 19 | |
| 20 | APPS = ['gmscore', 'nest', 'youtube', 'gmail', 'chrome'] |
| 21 | COMPILERS = ['d8', 'r8'] |
| 22 | |
| 23 | def ParseOptions(argv): |
| 24 | result = optparse.OptionParser() |
| 25 | result.add_option('--compiler', |
| 26 | help='The compiler to use', |
| 27 | default='d8', |
| 28 | choices=COMPILERS) |
| 29 | result.add_option('--app', |
| 30 | help='What app to run on', |
| 31 | default='gmail', |
| 32 | choices=APPS) |
| 33 | result.add_option('--top', |
Ian Zerny | 02a4b5b | 2019-10-21 13:32:41 +0200 | [diff] [blame] | 34 | default=historic_run.top_or_default(), |
Rico Wind | f923122 | 2019-01-08 14:43:52 +0100 | [diff] [blame] | 35 | help='The most recent commit to test') |
| 36 | result.add_option('--bottom', |
| 37 | help='The oldest commit to test') |
| 38 | result.add_option('--output', |
| 39 | default='build', |
| 40 | help='Directory where to output results') |
Jinseong Jeon | 158a3f1 | 2019-02-08 01:40:59 -0800 | [diff] [blame] | 41 | result.add_option('--timeout', |
| 42 | type=int, |
| 43 | default=0, |
| 44 | help='Set timeout instead of waiting for OOM.') |
Rico Wind | f923122 | 2019-01-08 14:43:52 +0100 | [diff] [blame] | 45 | return result.parse_args(argv) |
| 46 | |
Ian Zerny | 02a4b5b | 2019-10-21 13:32:41 +0200 | [diff] [blame] | 47 | def make_run_on_app_command(options): |
| 48 | return lambda commit: run_on_app(options, commit) |
Rico Wind | f923122 | 2019-01-08 14:43:52 +0100 | [diff] [blame] | 49 | |
| 50 | def run_on_app(options, commit): |
| 51 | app = options.app |
| 52 | compiler = options.compiler |
Jinseong Jeon | 158a3f1 | 2019-02-08 01:40:59 -0800 | [diff] [blame] | 53 | cmd = ['tools/run_on_app.py', |
| 54 | '--app', app, |
| 55 | '--compiler', compiler, |
| 56 | '--timeout', str(options.timeout), |
Rico Wind | f2017bf | 2019-01-10 09:45:33 +0100 | [diff] [blame] | 57 | '--no-build', '--find-min-xmx'] |
Rico Wind | f923122 | 2019-01-08 14:43:52 +0100 | [diff] [blame] | 58 | stdout = subprocess.check_output(cmd) |
| 59 | output_path = options.output or 'build' |
| 60 | time_commit = '%s_%s' % (commit.timestamp, commit.git_hash) |
| 61 | time_commit_path = os.path.join(output_path, time_commit) |
| 62 | if not os.path.exists(time_commit_path): |
| 63 | os.makedirs(time_commit_path) |
| 64 | stdout_path = os.path.join(time_commit_path, 'stdout') |
| 65 | with open(stdout_path, 'w') as f: |
| 66 | f.write(stdout) |
| 67 | print('Wrote stdout to: %s' % stdout_path) |
| 68 | |
Rico Wind | f923122 | 2019-01-08 14:43:52 +0100 | [diff] [blame] | 69 | def main(argv): |
| 70 | (options, args) = ParseOptions(argv) |
| 71 | if not options.app: |
| 72 | raise Exception('Please specify an app') |
Ian Zerny | 02a4b5b | 2019-10-21 13:32:41 +0200 | [diff] [blame] | 73 | top = historic_run.top_or_default(options.top) |
| 74 | bottom = historic_run.bottom_or_default(options.bottom) |
| 75 | command = make_run_on_app_command(options) |
| 76 | historic_run.run(command, top, bottom) |
Rico Wind | f923122 | 2019-01-08 14:43:52 +0100 | [diff] [blame] | 77 | |
| 78 | if __name__ == '__main__': |
| 79 | sys.exit(main(sys.argv[1:])) |