blob: 25de2264ef98183143985ff12e23c3965fb4ba96 [file] [log] [blame]
Patrik Höglundcb0b8742019-11-18 13:46:38 +01001#!/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.
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()
27 parser.add_argument('--perf-dashboard-machine-group',
28 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',
33 required=True,
34 help='The bot running the test (e.g. '
35 'webrtc-win-large-tests).')
36 parser.add_argument(
37 '--test-suite',
38 required=True,
39 help='The key for the test in the dashboard (i.e. what '
40 'you select in the top-level test suite selector in the '
41 'dashboard')
42 parser.add_argument('--webrtc-git-hash',
43 required=True,
44 help='webrtc.googlesource.com commit hash.')
45 parser.add_argument('--commit-position',
46 type=int,
47 required=True,
48 help='Commit pos corresponding to the git hash.')
49 parser.add_argument('--build-page-url',
50 required=True,
51 help='URL to the build page for this build.')
52 parser.add_argument('--dashboard-url',
53 required=True,
54 help='Which dashboard to use.')
55 parser.add_argument('--input-results-file',
56 type=argparse.FileType(),
57 required=True,
58 help='A JSON file with output from WebRTC tests.')
59 parser.add_argument('--output-json-file',
60 type=argparse.FileType('w'),
61 help='Where to write the output (for debugging).')
62 parser.add_argument(
63 '--outdir',
64 required=True,
65 help='Path to the local out/ dir (usually out/Default)')
66 return parser
Patrik Höglundcb0b8742019-11-18 13:46:38 +010067
68
Patrik Höglund0569a122020-03-13 12:26:42 +010069def _ConfigurePythonPath(options):
Mirko Bonadei8cc66952020-10-30 10:13:45 +010070 # We just yank the python scripts we require into the PYTHONPATH. You could
71 # also imagine a solution where we use for instance protobuf:py_proto_runtime
72 # to copy catapult and protobuf code to out/. This is the convention in
73 # Chromium and WebRTC python scripts. We do need to build histogram_pb2
74 # however, so that's why we add out/ to sys.path below.
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ö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
Mirko Bonadei8cc66952020-10-30 10:13:45 +010087 # The webrtc_dashboard_upload gn rule will build the protobuf stub for python,
88 # so put it in the path for this script before we attempt to import it.
89 histogram_proto_path = os.path.join(options.outdir, 'pyproto', 'tracing',
90 'tracing', 'proto')
91 sys.path.insert(0, histogram_proto_path)
Patrik Höglund0569a122020-03-13 12:26:42 +010092
Mirko Bonadei8cc66952020-10-30 10:13:45 +010093 # Fail early in case the proto hasn't been built.
94 from tracing.proto import histogram_proto
95 if not histogram_proto.HAS_PROTO:
96 raise ImportError(
97 'Could not find histogram_pb2. You need to build the '
98 'webrtc_dashboard_upload target before invoking this '
99 'script. Expected to find '
100 'histogram_pb2.py in %s.' % histogram_proto_path)
Patrik Höglund0569a122020-03-13 12:26:42 +0100101
102
Patrik Höglundcb0b8742019-11-18 13:46:38 +0100103def main(args):
Mirko Bonadei8cc66952020-10-30 10:13:45 +0100104 parser = _CreateParser()
105 options = parser.parse_args(args)
Patrik Höglundcb0b8742019-11-18 13:46:38 +0100106
Mirko Bonadei8cc66952020-10-30 10:13:45 +0100107 _ConfigurePythonPath(options)
Patrik Höglundcb0b8742019-11-18 13:46:38 +0100108
Mirko Bonadei8cc66952020-10-30 10:13:45 +0100109 import catapult_uploader
Patrik Höglundcb0b8742019-11-18 13:46:38 +0100110
Mirko Bonadei8cc66952020-10-30 10:13:45 +0100111 return catapult_uploader.UploadToDashboard(options)
112
Patrik Höglundcb0b8742019-11-18 13:46:38 +0100113
114if __name__ == '__main__':
Mirko Bonadei8cc66952020-10-30 10:13:45 +0100115 sys.exit(main(sys.argv[1:]))