blob: ed1b35e038228bb1b69914d9ebca9b113e246fd8 [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.
9
Patrik Höglundabea2682020-01-17 13:36:29 +010010"""Adds build info to perf results and uploads them.
Patrik Höglundcb0b8742019-11-18 13:46:38 +010011
Patrik Höglundabea2682020-01-17 13:36:29 +010012The tests don't know which bot executed the tests or at what revision, so we
Patrik Höglund83245bd2020-01-30 09:33:57 +010013need to take their output and enrich it with this information. We load the proto
Patrik Höglundabea2682020-01-17 13:36:29 +010014from the tests, add the build information as shared diagnostics and then
15upload it to the dashboard.
Patrik Höglundcb0b8742019-11-18 13:46:38 +010016
17This script can't be in recipes, because we can't access the catapult APIs from
18there. It needs to be here source-side.
Patrik Höglundcb0b8742019-11-18 13:46:38 +010019"""
20
21import argparse
Patrik Höglundabea2682020-01-17 13:36:29 +010022import os
Patrik Höglundcb0b8742019-11-18 13:46:38 +010023import sys
Patrik Höglundcb0b8742019-11-18 13:46:38 +010024
25
26def _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öglund8f47b272020-03-11 14:20:14 +010047 parser.add_argument('--input-results-file', type=argparse.FileType(),
Patrik Höglundcb0b8742019-11-18 13:46:38 +010048 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öglund83245bd2020-01-30 09:33:57 +010052 parser.add_argument('--outdir', required=True,
53 help='Path to the local out/ dir (usually out/Default)')
Patrik Höglundcb0b8742019-11-18 13:46:38 +010054 return parser
55
56
Patrik Höglund0569a122020-03-13 12:26:42 +010057def _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öglundcb0b8742019-11-18 13:46:38 +010090def main(args):
91 parser = _CreateParser()
92 options = parser.parse_args(args)
93
Patrik Höglund0569a122020-03-13 12:26:42 +010094 _ConfigurePythonPath(options)
Patrik Höglundcb0b8742019-11-18 13:46:38 +010095
Patrik Höglund0569a122020-03-13 12:26:42 +010096 import catapult_uploader
Patrik Höglundcb0b8742019-11-18 13:46:38 +010097
Patrik Höglund0569a122020-03-13 12:26:42 +010098 return catapult_uploader.UploadToDashboard(options)
Patrik Höglundcb0b8742019-11-18 13:46:38 +010099
100if __name__ == '__main__':
101 sys.exit(main(sys.argv[1:]))