blob: 19db0250cfa1d127155a8cd7f3d6d2d07967afad [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,
Andrey Logvin7a3db9d2021-06-30 19:30:44 +000053 help='A HistogramSet proto file with output from '
54 'WebRTC tests.')
Andrey Logvin728b5d02020-11-11 17:16:26 +000055 parser.add_argument('--output-json-file', type=argparse.FileType('w'),
Mirko Bonadei8cc66952020-10-30 10:13:45 +010056 help='Where to write the output (for debugging).')
Andrey Logvin728b5d02020-11-11 17:16:26 +000057 parser.add_argument('--outdir', required=True,
58 help='Path to the local out/ dir (usually out/Default)')
59 parser.add_argument('--wait-for-upload', action='store_true',
60 help='If specified, script will wait untill Chrome '
61 'perf dashboard confirms that the data was succesfully '
62 'proccessed and uploaded')
63 parser.add_argument('--wait-timeout-sec', type=int, default=1200,
64 help='Used only if wait-for-upload is True. Maximum '
65 'amount of time in seconds that the script will wait '
66 'for the confirmation.')
67 parser.add_argument('--wait-polling-period-sec', type=int, default=120,
68 help='Used only if wait-for-upload is True. Status '
69 'will be requested from the Dashboard every '
70 'wait-polling-period-sec seconds.')
Mirko Bonadei8cc66952020-10-30 10:13:45 +010071 return parser
Patrik Höglundcb0b8742019-11-18 13:46:38 +010072
73
Patrik Höglund0569a122020-03-13 12:26:42 +010074def _ConfigurePythonPath(options):
Mirko Bonadei8cc66952020-10-30 10:13:45 +010075 # We just yank the python scripts we require into the PYTHONPATH. You could
Andrey Logvin728b5d02020-11-11 17:16:26 +000076 # also imagine a solution where we use for instance
77 # protobuf:py_proto_runtime to copy catapult and protobuf code to out/.
78 # This is the convention in Chromium and WebRTC python scripts. We do need
79 # to build histogram_pb2 however, so that's why we add out/ to sys.path
80 # below.
Mirko Bonadei8cc66952020-10-30 10:13:45 +010081 #
82 # It would be better if there was an equivalent to py_binary in GN, but
83 # there's not.
84 script_dir = os.path.dirname(os.path.realpath(__file__))
85 checkout_root = os.path.abspath(
86 os.path.join(script_dir, os.pardir, os.pardir))
Patrik Höglund0569a122020-03-13 12:26:42 +010087
Mirko Bonadei8cc66952020-10-30 10:13:45 +010088 sys.path.insert(
89 0, os.path.join(checkout_root, 'third_party', 'catapult', 'tracing'))
90 sys.path.insert(
91 0, os.path.join(checkout_root, 'third_party', 'protobuf', 'python'))
Patrik Höglund0569a122020-03-13 12:26:42 +010092
Andrey Logvin728b5d02020-11-11 17:16:26 +000093 # The webrtc_dashboard_upload gn rule will build the protobuf stub for
94 # python, so put it in the path for this script before we attempt to import
95 # it.
Mirko Bonadei8cc66952020-10-30 10:13:45 +010096 histogram_proto_path = os.path.join(options.outdir, 'pyproto', 'tracing',
97 'tracing', 'proto')
98 sys.path.insert(0, histogram_proto_path)
Patrik Höglund0569a122020-03-13 12:26:42 +010099
Mirko Bonadei8cc66952020-10-30 10:13:45 +0100100 # Fail early in case the proto hasn't been built.
101 from tracing.proto import histogram_proto
102 if not histogram_proto.HAS_PROTO:
103 raise ImportError(
104 'Could not find histogram_pb2. You need to build the '
105 'webrtc_dashboard_upload target before invoking this '
106 'script. Expected to find '
107 'histogram_pb2.py in %s.' % histogram_proto_path)
Patrik Höglund0569a122020-03-13 12:26:42 +0100108
109
Patrik Höglundcb0b8742019-11-18 13:46:38 +0100110def main(args):
Mirko Bonadei8cc66952020-10-30 10:13:45 +0100111 parser = _CreateParser()
112 options = parser.parse_args(args)
Patrik Höglundcb0b8742019-11-18 13:46:38 +0100113
Mirko Bonadei8cc66952020-10-30 10:13:45 +0100114 _ConfigurePythonPath(options)
Patrik Höglundcb0b8742019-11-18 13:46:38 +0100115
Mirko Bonadei8cc66952020-10-30 10:13:45 +0100116 import catapult_uploader
Patrik Höglundcb0b8742019-11-18 13:46:38 +0100117
Mirko Bonadei8cc66952020-10-30 10:13:45 +0100118 return catapult_uploader.UploadToDashboard(options)
119
Patrik Höglundcb0b8742019-11-18 13:46:38 +0100120
121if __name__ == '__main__':
Mirko Bonadei8cc66952020-10-30 10:13:45 +0100122 sys.exit(main(sys.argv[1:]))