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