blob: df5b9bb2c8f16326fa72fde767fddf3c8055147a [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
24
25def _CreateParser():
Mirko Bonadei8cc66952020-10-30 10:13:45 +010026 parser = argparse.ArgumentParser()
Andrey Logvin728b5d02020-11-11 17:16:26 +000027 parser.add_argument('--perf-dashboard-machine-group', required=True,
Mirko Bonadei8cc66952020-10-30 10:13:45 +010028 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 Logvin728b5d02020-11-11 17:16:26 +000031 parser.add_argument('--bot', required=True,
Mirko Bonadei8cc66952020-10-30 10:13:45 +010032 help='The bot running the test (e.g. '
Andrey Logvin728b5d02020-11-11 17:16:26 +000033 '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 Bonadei8cc66952020-10-30 10:13:45 +010039 help='webrtc.googlesource.com commit hash.')
Andrey Logvin728b5d02020-11-11 17:16:26 +000040 parser.add_argument('--commit-position', type=int, required=True,
Mirko Bonadei8cc66952020-10-30 10:13:45 +010041 help='Commit pos corresponding to the git hash.')
Andrey Logvin728b5d02020-11-11 17:16:26 +000042 parser.add_argument('--build-page-url', required=True,
Mirko Bonadei8cc66952020-10-30 10:13:45 +010043 help='URL to the build page for this build.')
Andrey Logvin728b5d02020-11-11 17:16:26 +000044 parser.add_argument('--dashboard-url', required=True,
Mirko Bonadei8cc66952020-10-30 10:13:45 +010045 help='Which dashboard to use.')
Andrey Logvin728b5d02020-11-11 17:16:26 +000046 parser.add_argument('--input-results-file', type=argparse.FileType(),
Mirko Bonadei8cc66952020-10-30 10:13:45 +010047 required=True,
48 help='A JSON file with output from WebRTC tests.')
Andrey Logvin728b5d02020-11-11 17:16:26 +000049 parser.add_argument('--output-json-file', type=argparse.FileType('w'),
Mirko Bonadei8cc66952020-10-30 10:13:45 +010050 help='Where to write the output (for debugging).')
Andrey Logvin728b5d02020-11-11 17:16:26 +000051 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 Bonadei8cc66952020-10-30 10:13:45 +010065 return parser
Patrik Höglundcb0b8742019-11-18 13:46:38 +010066
67
Patrik Höglund0569a122020-03-13 12:26:42 +010068def _ConfigurePythonPath(options):
Mirko Bonadei8cc66952020-10-30 10:13:45 +010069 # We just yank the python scripts we require into the PYTHONPATH. You could
Andrey Logvin728b5d02020-11-11 17:16:26 +000070 # 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 Bonadei8cc66952020-10-30 10:13:45 +010075 #
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öglund0569a122020-03-13 12:26:42 +010081
Mirko Bonadei8cc66952020-10-30 10:13:45 +010082 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öglund0569a122020-03-13 12:26:42 +010086
Andrey Logvin728b5d02020-11-11 17:16:26 +000087 # 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 Bonadei8cc66952020-10-30 10:13:45 +010090 histogram_proto_path = os.path.join(options.outdir, 'pyproto', 'tracing',
91 'tracing', 'proto')
92 sys.path.insert(0, histogram_proto_path)
Patrik Höglund0569a122020-03-13 12:26:42 +010093
Mirko Bonadei8cc66952020-10-30 10:13:45 +010094 # 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öglund0569a122020-03-13 12:26:42 +0100102
103
Patrik Höglundcb0b8742019-11-18 13:46:38 +0100104def main(args):
Mirko Bonadei8cc66952020-10-30 10:13:45 +0100105 parser = _CreateParser()
106 options = parser.parse_args(args)
Patrik Höglundcb0b8742019-11-18 13:46:38 +0100107
Mirko Bonadei8cc66952020-10-30 10:13:45 +0100108 _ConfigurePythonPath(options)
Patrik Höglundcb0b8742019-11-18 13:46:38 +0100109
Mirko Bonadei8cc66952020-10-30 10:13:45 +0100110 import catapult_uploader
Patrik Höglundcb0b8742019-11-18 13:46:38 +0100111
Mirko Bonadei8cc66952020-10-30 10:13:45 +0100112 return catapult_uploader.UploadToDashboard(options)
113
Patrik Höglundcb0b8742019-11-18 13:46:38 +0100114
115if __name__ == '__main__':
Mirko Bonadei8cc66952020-10-30 10:13:45 +0100116 sys.exit(main(sys.argv[1:]))