Patrik Höglund | cb0b874 | 2019-11-18 13:46:38 +0100 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 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. |
| 9 | |
Patrik Höglund | abea268 | 2020-01-17 13:36:29 +0100 | [diff] [blame] | 10 | """Adds build info to perf results and uploads them. |
Patrik Höglund | cb0b874 | 2019-11-18 13:46:38 +0100 | [diff] [blame] | 11 | |
Patrik Höglund | abea268 | 2020-01-17 13:36:29 +0100 | [diff] [blame] | 12 | 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] | 13 | 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] | 14 | from the tests, add the build information as shared diagnostics and then |
| 15 | upload it to the dashboard. |
Patrik Höglund | cb0b874 | 2019-11-18 13:46:38 +0100 | [diff] [blame] | 16 | |
| 17 | This script can't be in recipes, because we can't access the catapult APIs from |
| 18 | there. It needs to be here source-side. |
Patrik Höglund | cb0b874 | 2019-11-18 13:46:38 +0100 | [diff] [blame] | 19 | """ |
| 20 | |
| 21 | import argparse |
Patrik Höglund | abea268 | 2020-01-17 13:36:29 +0100 | [diff] [blame] | 22 | import os |
Patrik Höglund | cb0b874 | 2019-11-18 13:46:38 +0100 | [diff] [blame] | 23 | import sys |
Patrik Höglund | cb0b874 | 2019-11-18 13:46:38 +0100 | [diff] [blame] | 24 | |
| 25 | |
| 26 | def _CreateParser(): |
| 27 | parser = argparse.ArgumentParser() |
| 28 | parser.add_argument('--perf-dashboard-machine-group', required=True, |
| 29 | help='The "master" the bots are grouped under. This ' |
| 30 | 'string is the group in the the perf dashboard path ' |
| 31 | 'group/bot/perf_id/metric/subtest.') |
| 32 | parser.add_argument('--bot', required=True, |
| 33 | help='The bot running the test (e.g. ' |
| 34 | 'webrtc-win-large-tests).') |
| 35 | parser.add_argument('--test-suite', required=True, |
| 36 | help='The key for the test in the dashboard (i.e. what ' |
| 37 | 'you select in the top-level test suite selector in the ' |
| 38 | 'dashboard') |
| 39 | parser.add_argument('--webrtc-git-hash', required=True, |
| 40 | help='webrtc.googlesource.com commit hash.') |
| 41 | parser.add_argument('--commit-position', type=int, required=True, |
| 42 | help='Commit pos corresponding to the git hash.') |
| 43 | parser.add_argument('--build-page-url', required=True, |
| 44 | help='URL to the build page for this build.') |
| 45 | parser.add_argument('--dashboard-url', required=True, |
| 46 | help='Which dashboard to use.') |
Patrik Höglund | 8f47b27 | 2020-03-11 14:20:14 +0100 | [diff] [blame] | 47 | parser.add_argument('--input-results-file', type=argparse.FileType(), |
Patrik Höglund | cb0b874 | 2019-11-18 13:46:38 +0100 | [diff] [blame] | 48 | required=True, |
| 49 | help='A JSON file with output from WebRTC tests.') |
| 50 | parser.add_argument('--output-json-file', type=argparse.FileType('w'), |
| 51 | help='Where to write the output (for debugging).') |
Patrik Höglund | 83245bd | 2020-01-30 09:33:57 +0100 | [diff] [blame] | 52 | parser.add_argument('--outdir', required=True, |
| 53 | help='Path to the local out/ dir (usually out/Default)') |
Patrik Höglund | cb0b874 | 2019-11-18 13:46:38 +0100 | [diff] [blame] | 54 | return parser |
| 55 | |
| 56 | |
Patrik Höglund | 0569a12 | 2020-03-13 12:26:42 +0100 | [diff] [blame^] | 57 | def _ConfigurePythonPath(options): |
| 58 | # We just yank the python scripts we require into the PYTHONPATH. You could |
| 59 | # also imagine a solution where we use for instance protobuf:py_proto_runtime |
| 60 | # to copy catapult and protobuf code to out/. This is the convention in |
| 61 | # Chromium and WebRTC python scripts. We do need to build histogram_pb2 |
| 62 | # however, so that's why we add out/ to sys.path below. |
| 63 | # |
| 64 | # It would be better if there was an equivalent to py_binary in GN, but |
| 65 | # there's not. |
| 66 | script_dir = os.path.dirname(os.path.realpath(__file__)) |
| 67 | checkout_root = os.path.abspath( |
| 68 | os.path.join(script_dir, os.pardir, os.pardir)) |
| 69 | |
| 70 | sys.path.insert(0, os.path.join(checkout_root, 'third_party', 'catapult', |
| 71 | 'tracing')) |
| 72 | sys.path.insert(0, os.path.join(checkout_root, 'third_party', 'protobuf', |
| 73 | 'python')) |
| 74 | |
| 75 | # The webrtc_dashboard_upload gn rule will build the protobuf stub for python, |
| 76 | # so put it in the path for this script before we attempt to import it. |
| 77 | histogram_proto_path = os.path.join( |
| 78 | options.outdir, 'pyproto', 'tracing', 'tracing', 'proto') |
| 79 | sys.path.insert(0, histogram_proto_path) |
| 80 | |
| 81 | # Fail early in case the proto hasn't been built. |
| 82 | from tracing.proto import histogram_proto |
| 83 | if not histogram_proto.HAS_PROTO: |
| 84 | raise ImportError('Could not find histogram_pb2. You need to build the ' |
| 85 | 'webrtc_dashboard_upload target before invoking this ' |
| 86 | 'script. Expected to find ' |
| 87 | 'histogram_pb2.py in %s.' % histogram_proto_path) |
| 88 | |
| 89 | |
Patrik Höglund | cb0b874 | 2019-11-18 13:46:38 +0100 | [diff] [blame] | 90 | def main(args): |
| 91 | parser = _CreateParser() |
| 92 | options = parser.parse_args(args) |
| 93 | |
Patrik Höglund | 0569a12 | 2020-03-13 12:26:42 +0100 | [diff] [blame^] | 94 | _ConfigurePythonPath(options) |
Patrik Höglund | cb0b874 | 2019-11-18 13:46:38 +0100 | [diff] [blame] | 95 | |
Patrik Höglund | 0569a12 | 2020-03-13 12:26:42 +0100 | [diff] [blame^] | 96 | import catapult_uploader |
Patrik Höglund | cb0b874 | 2019-11-18 13:46:38 +0100 | [diff] [blame] | 97 | |
Patrik Höglund | 0569a12 | 2020-03-13 12:26:42 +0100 | [diff] [blame^] | 98 | return catapult_uploader.UploadToDashboard(options) |
Patrik Höglund | cb0b874 | 2019-11-18 13:46:38 +0100 | [diff] [blame] | 99 | |
| 100 | if __name__ == '__main__': |
| 101 | sys.exit(main(sys.argv[1:])) |