blob: a709af5dcd5061927f63ed6d7f21568d15ae75cf [file] [log] [blame]
Mirko Bonadei0958ca32020-11-20 08:49:45 +01001#!/usr/bin/env vpython
Patrik Höglundcb0b8742019-11-18 13:46:38 +01002# 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öglundabea2682020-01-17 13:36:29 +01009"""Adds build info to perf results and uploads them.
Patrik Höglundcb0b8742019-11-18 13:46:38 +010010
Patrik Höglundabea2682020-01-17 13:36:29 +010011The tests don't know which bot executed the tests or at what revision, so we
Patrik Höglund83245bd2020-01-30 09:33:57 +010012need to take their output and enrich it with this information. We load the proto
Patrik Höglundabea2682020-01-17 13:36:29 +010013from the tests, add the build information as shared diagnostics and then
14upload it to the dashboard.
Patrik Höglundcb0b8742019-11-18 13:46:38 +010015
16This script can't be in recipes, because we can't access the catapult APIs from
17there. It needs to be here source-side.
Patrik Höglundcb0b8742019-11-18 13:46:38 +010018"""
19
20import argparse
Patrik Höglundabea2682020-01-17 13:36:29 +010021import os
Patrik Höglundcb0b8742019-11-18 13:46:38 +010022import sys
Patrik Höglundcb0b8742019-11-18 13:46:38 +010023
Mirko Bonadeidb9095d2020-11-23 17:45:52 +010024# Even if protobuf is not used directly, this allows transitive imports
25# of the protobuf library to use the vpython wheel specified in the root
26# level .vpython (see bugs.webrtc.org/12211 for context).
27import google.protobuf # pylint: disable=unused-import
28
Patrik Höglundcb0b8742019-11-18 13:46:38 +010029
30def _CreateParser():
Mirko Bonadei8cc66952020-10-30 10:13:45 +010031 parser = argparse.ArgumentParser()
Andrey Logvin728b5d02020-11-11 17:16:26 +000032 parser.add_argument('--perf-dashboard-machine-group', required=True,
Mirko Bonadei8cc66952020-10-30 10:13:45 +010033 help='The "master" the bots are grouped under. This '
34 'string is the group in the the perf dashboard path '
35 'group/bot/perf_id/metric/subtest.')
Andrey Logvin728b5d02020-11-11 17:16:26 +000036 parser.add_argument('--bot', required=True,
Mirko Bonadei8cc66952020-10-30 10:13:45 +010037 help='The bot running the test (e.g. '
Andrey Logvin728b5d02020-11-11 17:16:26 +000038 'webrtc-win-large-tests).')
39 parser.add_argument('--test-suite', required=True,
40 help='The key for the test in the dashboard (i.e. what '
41 'you select in the top-level test suite selector in '
42 'the dashboard')
43 parser.add_argument('--webrtc-git-hash', required=True,
Mirko Bonadei8cc66952020-10-30 10:13:45 +010044 help='webrtc.googlesource.com commit hash.')
Andrey Logvin728b5d02020-11-11 17:16:26 +000045 parser.add_argument('--commit-position', type=int, required=True,
Mirko Bonadei8cc66952020-10-30 10:13:45 +010046 help='Commit pos corresponding to the git hash.')
Andrey Logvin728b5d02020-11-11 17:16:26 +000047 parser.add_argument('--build-page-url', required=True,
Mirko Bonadei8cc66952020-10-30 10:13:45 +010048 help='URL to the build page for this build.')
Andrey Logvin728b5d02020-11-11 17:16:26 +000049 parser.add_argument('--dashboard-url', required=True,
Mirko Bonadei8cc66952020-10-30 10:13:45 +010050 help='Which dashboard to use.')
Andrey Logvin728b5d02020-11-11 17:16:26 +000051 parser.add_argument('--input-results-file', type=argparse.FileType(),
Mirko Bonadei8cc66952020-10-30 10:13:45 +010052 required=True,
53 help='A JSON file with output from WebRTC tests.')
Andrey Logvin728b5d02020-11-11 17:16:26 +000054 parser.add_argument('--output-json-file', type=argparse.FileType('w'),
Mirko Bonadei8cc66952020-10-30 10:13:45 +010055 help='Where to write the output (for debugging).')
Andrey Logvin728b5d02020-11-11 17:16:26 +000056 parser.add_argument('--outdir', required=True,
57 help='Path to the local out/ dir (usually out/Default)')
58 parser.add_argument('--wait-for-upload', action='store_true',
59 help='If specified, script will wait untill Chrome '
60 'perf dashboard confirms that the data was succesfully '
61 'proccessed and uploaded')
62 parser.add_argument('--wait-timeout-sec', type=int, default=1200,
63 help='Used only if wait-for-upload is True. Maximum '
64 'amount of time in seconds that the script will wait '
65 'for the confirmation.')
66 parser.add_argument('--wait-polling-period-sec', type=int, default=120,
67 help='Used only if wait-for-upload is True. Status '
68 'will be requested from the Dashboard every '
69 'wait-polling-period-sec seconds.')
Mirko Bonadei8cc66952020-10-30 10:13:45 +010070 return parser
Patrik Höglundcb0b8742019-11-18 13:46:38 +010071
72
Patrik Höglund0569a122020-03-13 12:26:42 +010073def _ConfigurePythonPath(options):
Mirko Bonadei8cc66952020-10-30 10:13:45 +010074 # We just yank the python scripts we require into the PYTHONPATH. You could
Andrey Logvin728b5d02020-11-11 17:16:26 +000075 # also imagine a solution where we use for instance
76 # protobuf:py_proto_runtime to copy catapult and protobuf code to out/.
77 # This is the convention in Chromium and WebRTC python scripts. We do need
78 # to build histogram_pb2 however, so that's why we add out/ to sys.path
79 # below.
Mirko Bonadei8cc66952020-10-30 10:13:45 +010080 #
81 # It would be better if there was an equivalent to py_binary in GN, but
82 # there's not.
83 script_dir = os.path.dirname(os.path.realpath(__file__))
84 checkout_root = os.path.abspath(
85 os.path.join(script_dir, os.pardir, os.pardir))
Patrik Höglund0569a122020-03-13 12:26:42 +010086
Mirko Bonadei8cc66952020-10-30 10:13:45 +010087 sys.path.insert(
88 0, os.path.join(checkout_root, 'third_party', 'catapult', 'tracing'))
89 sys.path.insert(
90 0, os.path.join(checkout_root, 'third_party', 'protobuf', 'python'))
Patrik Höglund0569a122020-03-13 12:26:42 +010091
Andrey Logvin728b5d02020-11-11 17:16:26 +000092 # The webrtc_dashboard_upload gn rule will build the protobuf stub for
93 # python, so put it in the path for this script before we attempt to import
94 # it.
Mirko Bonadei8cc66952020-10-30 10:13:45 +010095 histogram_proto_path = os.path.join(options.outdir, 'pyproto', 'tracing',
96 'tracing', 'proto')
97 sys.path.insert(0, histogram_proto_path)
Patrik Höglund0569a122020-03-13 12:26:42 +010098
Mirko Bonadei8cc66952020-10-30 10:13:45 +010099 # Fail early in case the proto hasn't been built.
100 from tracing.proto import histogram_proto
101 if not histogram_proto.HAS_PROTO:
102 raise ImportError(
103 'Could not find histogram_pb2. You need to build the '
104 'webrtc_dashboard_upload target before invoking this '
105 'script. Expected to find '
106 'histogram_pb2.py in %s.' % histogram_proto_path)
Patrik Höglund0569a122020-03-13 12:26:42 +0100107
108
Patrik Höglundcb0b8742019-11-18 13:46:38 +0100109def main(args):
Mirko Bonadei8cc66952020-10-30 10:13:45 +0100110 parser = _CreateParser()
111 options = parser.parse_args(args)
Patrik Höglundcb0b8742019-11-18 13:46:38 +0100112
Mirko Bonadei8cc66952020-10-30 10:13:45 +0100113 _ConfigurePythonPath(options)
Patrik Höglundcb0b8742019-11-18 13:46:38 +0100114
Mirko Bonadei8cc66952020-10-30 10:13:45 +0100115 import catapult_uploader
Patrik Höglundcb0b8742019-11-18 13:46:38 +0100116
Mirko Bonadei8cc66952020-10-30 10:13:45 +0100117 return catapult_uploader.UploadToDashboard(options)
118
Patrik Höglundcb0b8742019-11-18 13:46:38 +0100119
120if __name__ == '__main__':
Mirko Bonadei8cc66952020-10-30 10:13:45 +0100121 sys.exit(main(sys.argv[1:]))