Mirko Bonadei | 0958ca3 | 2020-11-20 08:49:45 +0100 | [diff] [blame] | 1 | #!/usr/bin/env vpython |
Patrik Höglund | cb0b874 | 2019-11-18 13:46:38 +0100 | [diff] [blame] | 2 | # Copyright (c) 2019 The WebRTC project authors. All Rights Reserved. |
| 3 | # |
| 4 | # Use of this source code is governed by a BSD-style license |
| 5 | # that can be found in the LICENSE file in the root of the source |
| 6 | # tree. An additional intellectual property rights grant can be found |
| 7 | # in the file PATENTS. All contributing project authors may |
| 8 | # be found in the AUTHORS file in the root of the source tree. |
Patrik Höglund | abea268 | 2020-01-17 13:36:29 +0100 | [diff] [blame] | 9 | """Adds build info to perf results and uploads them. |
Patrik Höglund | cb0b874 | 2019-11-18 13:46:38 +0100 | [diff] [blame] | 10 | |
Patrik Höglund | abea268 | 2020-01-17 13:36:29 +0100 | [diff] [blame] | 11 | The tests don't know which bot executed the tests or at what revision, so we |
Patrik Höglund | 83245bd | 2020-01-30 09:33:57 +0100 | [diff] [blame] | 12 | need to take their output and enrich it with this information. We load the proto |
Patrik Höglund | abea268 | 2020-01-17 13:36:29 +0100 | [diff] [blame] | 13 | from the tests, add the build information as shared diagnostics and then |
| 14 | upload it to the dashboard. |
Patrik Höglund | cb0b874 | 2019-11-18 13:46:38 +0100 | [diff] [blame] | 15 | |
| 16 | This script can't be in recipes, because we can't access the catapult APIs from |
| 17 | there. It needs to be here source-side. |
Patrik Höglund | cb0b874 | 2019-11-18 13:46:38 +0100 | [diff] [blame] | 18 | """ |
| 19 | |
| 20 | import argparse |
Patrik Höglund | abea268 | 2020-01-17 13:36:29 +0100 | [diff] [blame] | 21 | import os |
Patrik Höglund | cb0b874 | 2019-11-18 13:46:38 +0100 | [diff] [blame] | 22 | import sys |
Patrik Höglund | cb0b874 | 2019-11-18 13:46:38 +0100 | [diff] [blame] | 23 | |
| 24 | |
| 25 | def _CreateParser(): |
Mirko Bonadei | 8cc6695 | 2020-10-30 10:13:45 +0100 | [diff] [blame] | 26 | parser = argparse.ArgumentParser() |
Andrey Logvin | 728b5d0 | 2020-11-11 17:16:26 +0000 | [diff] [blame] | 27 | parser.add_argument('--perf-dashboard-machine-group', required=True, |
Mirko Bonadei | 8cc6695 | 2020-10-30 10:13:45 +0100 | [diff] [blame] | 28 | help='The "master" the bots are grouped under. This ' |
| 29 | 'string is the group in the the perf dashboard path ' |
| 30 | 'group/bot/perf_id/metric/subtest.') |
Andrey Logvin | 728b5d0 | 2020-11-11 17:16:26 +0000 | [diff] [blame] | 31 | parser.add_argument('--bot', required=True, |
Mirko Bonadei | 8cc6695 | 2020-10-30 10:13:45 +0100 | [diff] [blame] | 32 | help='The bot running the test (e.g. ' |
Andrey Logvin | 728b5d0 | 2020-11-11 17:16:26 +0000 | [diff] [blame] | 33 | 'webrtc-win-large-tests).') |
| 34 | parser.add_argument('--test-suite', required=True, |
| 35 | help='The key for the test in the dashboard (i.e. what ' |
| 36 | 'you select in the top-level test suite selector in ' |
| 37 | 'the dashboard') |
| 38 | parser.add_argument('--webrtc-git-hash', required=True, |
Mirko Bonadei | 8cc6695 | 2020-10-30 10:13:45 +0100 | [diff] [blame] | 39 | help='webrtc.googlesource.com commit hash.') |
Andrey Logvin | 728b5d0 | 2020-11-11 17:16:26 +0000 | [diff] [blame] | 40 | parser.add_argument('--commit-position', type=int, required=True, |
Mirko Bonadei | 8cc6695 | 2020-10-30 10:13:45 +0100 | [diff] [blame] | 41 | help='Commit pos corresponding to the git hash.') |
Andrey Logvin | 728b5d0 | 2020-11-11 17:16:26 +0000 | [diff] [blame] | 42 | parser.add_argument('--build-page-url', required=True, |
Mirko Bonadei | 8cc6695 | 2020-10-30 10:13:45 +0100 | [diff] [blame] | 43 | help='URL to the build page for this build.') |
Andrey Logvin | 728b5d0 | 2020-11-11 17:16:26 +0000 | [diff] [blame] | 44 | parser.add_argument('--dashboard-url', required=True, |
Mirko Bonadei | 8cc6695 | 2020-10-30 10:13:45 +0100 | [diff] [blame] | 45 | help='Which dashboard to use.') |
Andrey Logvin | 728b5d0 | 2020-11-11 17:16:26 +0000 | [diff] [blame] | 46 | parser.add_argument('--input-results-file', type=argparse.FileType(), |
Mirko Bonadei | 8cc6695 | 2020-10-30 10:13:45 +0100 | [diff] [blame] | 47 | required=True, |
| 48 | help='A JSON file with output from WebRTC tests.') |
Andrey Logvin | 728b5d0 | 2020-11-11 17:16:26 +0000 | [diff] [blame] | 49 | parser.add_argument('--output-json-file', type=argparse.FileType('w'), |
Mirko Bonadei | 8cc6695 | 2020-10-30 10:13:45 +0100 | [diff] [blame] | 50 | help='Where to write the output (for debugging).') |
Andrey Logvin | 728b5d0 | 2020-11-11 17:16:26 +0000 | [diff] [blame] | 51 | parser.add_argument('--outdir', required=True, |
| 52 | help='Path to the local out/ dir (usually out/Default)') |
| 53 | parser.add_argument('--wait-for-upload', action='store_true', |
| 54 | help='If specified, script will wait untill Chrome ' |
| 55 | 'perf dashboard confirms that the data was succesfully ' |
| 56 | 'proccessed and uploaded') |
| 57 | parser.add_argument('--wait-timeout-sec', type=int, default=1200, |
| 58 | help='Used only if wait-for-upload is True. Maximum ' |
| 59 | 'amount of time in seconds that the script will wait ' |
| 60 | 'for the confirmation.') |
| 61 | parser.add_argument('--wait-polling-period-sec', type=int, default=120, |
| 62 | help='Used only if wait-for-upload is True. Status ' |
| 63 | 'will be requested from the Dashboard every ' |
| 64 | 'wait-polling-period-sec seconds.') |
Mirko Bonadei | 8cc6695 | 2020-10-30 10:13:45 +0100 | [diff] [blame] | 65 | return parser |
Patrik Höglund | cb0b874 | 2019-11-18 13:46:38 +0100 | [diff] [blame] | 66 | |
| 67 | |
Patrik Höglund | 0569a12 | 2020-03-13 12:26:42 +0100 | [diff] [blame] | 68 | def _ConfigurePythonPath(options): |
Mirko Bonadei | 8cc6695 | 2020-10-30 10:13:45 +0100 | [diff] [blame] | 69 | # We just yank the python scripts we require into the PYTHONPATH. You could |
Andrey Logvin | 728b5d0 | 2020-11-11 17:16:26 +0000 | [diff] [blame] | 70 | # also imagine a solution where we use for instance |
| 71 | # protobuf:py_proto_runtime to copy catapult and protobuf code to out/. |
| 72 | # This is the convention in Chromium and WebRTC python scripts. We do need |
| 73 | # to build histogram_pb2 however, so that's why we add out/ to sys.path |
| 74 | # below. |
Mirko Bonadei | 8cc6695 | 2020-10-30 10:13:45 +0100 | [diff] [blame] | 75 | # |
| 76 | # It would be better if there was an equivalent to py_binary in GN, but |
| 77 | # there's not. |
| 78 | script_dir = os.path.dirname(os.path.realpath(__file__)) |
| 79 | checkout_root = os.path.abspath( |
| 80 | os.path.join(script_dir, os.pardir, os.pardir)) |
Patrik Höglund | 0569a12 | 2020-03-13 12:26:42 +0100 | [diff] [blame] | 81 | |
Mirko Bonadei | 8cc6695 | 2020-10-30 10:13:45 +0100 | [diff] [blame] | 82 | sys.path.insert( |
| 83 | 0, os.path.join(checkout_root, 'third_party', 'catapult', 'tracing')) |
| 84 | sys.path.insert( |
| 85 | 0, os.path.join(checkout_root, 'third_party', 'protobuf', 'python')) |
Patrik Höglund | 0569a12 | 2020-03-13 12:26:42 +0100 | [diff] [blame] | 86 | |
Andrey Logvin | 728b5d0 | 2020-11-11 17:16:26 +0000 | [diff] [blame] | 87 | # The webrtc_dashboard_upload gn rule will build the protobuf stub for |
| 88 | # python, so put it in the path for this script before we attempt to import |
| 89 | # it. |
Mirko Bonadei | 8cc6695 | 2020-10-30 10:13:45 +0100 | [diff] [blame] | 90 | histogram_proto_path = os.path.join(options.outdir, 'pyproto', 'tracing', |
| 91 | 'tracing', 'proto') |
| 92 | sys.path.insert(0, histogram_proto_path) |
Patrik Höglund | 0569a12 | 2020-03-13 12:26:42 +0100 | [diff] [blame] | 93 | |
Mirko Bonadei | 8cc6695 | 2020-10-30 10:13:45 +0100 | [diff] [blame] | 94 | # Fail early in case the proto hasn't been built. |
| 95 | from tracing.proto import histogram_proto |
| 96 | if not histogram_proto.HAS_PROTO: |
| 97 | raise ImportError( |
| 98 | 'Could not find histogram_pb2. You need to build the ' |
| 99 | 'webrtc_dashboard_upload target before invoking this ' |
| 100 | 'script. Expected to find ' |
| 101 | 'histogram_pb2.py in %s.' % histogram_proto_path) |
Patrik Höglund | 0569a12 | 2020-03-13 12:26:42 +0100 | [diff] [blame] | 102 | |
| 103 | |
Patrik Höglund | cb0b874 | 2019-11-18 13:46:38 +0100 | [diff] [blame] | 104 | def main(args): |
Mirko Bonadei | 8cc6695 | 2020-10-30 10:13:45 +0100 | [diff] [blame] | 105 | parser = _CreateParser() |
| 106 | options = parser.parse_args(args) |
Patrik Höglund | cb0b874 | 2019-11-18 13:46:38 +0100 | [diff] [blame] | 107 | |
Mirko Bonadei | 8cc6695 | 2020-10-30 10:13:45 +0100 | [diff] [blame] | 108 | _ConfigurePythonPath(options) |
Patrik Höglund | cb0b874 | 2019-11-18 13:46:38 +0100 | [diff] [blame] | 109 | |
Mirko Bonadei | 8cc6695 | 2020-10-30 10:13:45 +0100 | [diff] [blame] | 110 | import catapult_uploader |
Patrik Höglund | cb0b874 | 2019-11-18 13:46:38 +0100 | [diff] [blame] | 111 | |
Mirko Bonadei | 8cc6695 | 2020-10-30 10:13:45 +0100 | [diff] [blame] | 112 | return catapult_uploader.UploadToDashboard(options) |
| 113 | |
Patrik Höglund | cb0b874 | 2019-11-18 13:46:38 +0100 | [diff] [blame] | 114 | |
| 115 | if __name__ == '__main__': |
Mirko Bonadei | 8cc6695 | 2020-10-30 10:13:45 +0100 | [diff] [blame] | 116 | sys.exit(main(sys.argv[1:])) |