|
10 | 10 | """Adds build info to perf results and uploads them.
|
11 | 11 |
|
12 | 12 | The tests don't know which bot executed the tests or at what revision, so we
|
13 |
| -need to take their output and enrich it with this information. We load the JSON |
| 13 | +need to take their output and enrich it with this information. We load the proto |
14 | 14 | from the tests, add the build information as shared diagnostics and then
|
15 | 15 | upload it to the dashboard.
|
16 | 16 |
|
|
26 | 26 | import subprocess
|
27 | 27 | import zlib
|
28 | 28 |
|
| 29 | +# We just yank the python scripts we require into the PYTHONPATH. You could also |
| 30 | +# imagine a solution where we use for instance protobuf:py_proto_runtime to copy |
| 31 | +# catapult and protobuf code to out/, but this approach is allowed by |
| 32 | +# convention. Fortunately neither catapult nor protobuf require any build rules |
| 33 | +# to be executed. We can't do this for the histogram proto stub though because |
| 34 | +# it's generated; see _LoadHistogramSetFromProto. |
| 35 | +# |
| 36 | +# It would be better if there was an equivalent to py_binary in GN, but there's |
| 37 | +# not. |
29 | 38 | SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__))
|
30 | 39 | CHECKOUT_ROOT = os.path.abspath(os.path.join(SCRIPT_DIR, os.pardir, os.pardir))
|
31 | 40 | sys.path.insert(0, os.path.join(CHECKOUT_ROOT, 'third_party', 'catapult',
|
32 | 41 | 'tracing'))
|
| 42 | +sys.path.insert(0, os.path.join(CHECKOUT_ROOT, 'third_party', 'protobuf', |
| 43 | + 'python')) |
33 | 44 |
|
34 | 45 | from tracing.value import histogram_set
|
35 | 46 | from tracing.value.diagnostics import generic_set
|
36 | 47 | from tracing.value.diagnostics import reserved_infos
|
37 | 48 |
|
| 49 | +from google.protobuf import json_format |
| 50 | + |
38 | 51 |
|
39 | 52 | def _GenerateOauthToken():
|
40 | 53 | args = ['luci-auth', 'token']
|
@@ -72,13 +85,33 @@ def _SendHistogramSet(url, histograms, oauth_token):
|
72 | 85 | return response, content
|
73 | 86 |
|
74 | 87 |
|
75 |
| -def _LoadHistogramSetFromJson(options): |
| 88 | +def _LoadHistogramSetFromProto(options): |
| 89 | + # The webrtc_dashboard_upload gn rule will build the protobuf stub for python, |
| 90 | + # so put it in the path for this script before we attempt to import it. |
| 91 | + histogram_proto_path = os.path.join(options.outdir, 'pyproto', 'tracing', |
| 92 | + 'tracing', 'proto') |
| 93 | + sys.path.insert(0, histogram_proto_path) |
| 94 | + |
| 95 | + # TODO(https://crbug.com/1029452): Get rid of this import hack once we can |
| 96 | + # just hand the contents of input_results_file straight to the histogram set. |
| 97 | + try: |
| 98 | + import histogram_pb2 |
| 99 | + except ImportError: |
| 100 | + raise ImportError('Could not find histogram_pb2. You need to build the ' |
| 101 | + 'webrtc_dashboard_upload target before invoking this ' |
| 102 | + 'script. Expected to find ' |
| 103 | + 'histogram_pb2 in %s.' % histogram_proto_path) |
| 104 | + |
76 | 105 | with options.input_results_file as f:
|
77 |
| - json_data = json.load(f) |
| 106 | + histograms = histogram_pb2.HistogramSet() |
| 107 | + histograms.ParseFromString(f.read()) |
78 | 108 |
|
79 |
| - histograms = histogram_set.HistogramSet() |
80 |
| - histograms.ImportDicts(json_data) |
81 |
| - return histograms |
| 109 | + # TODO(https://crbug.com/1029452): Don't convert to JSON as a middle step once |
| 110 | + # there is a proto de-serializer ready in catapult. |
| 111 | + json_data = json.loads(json_format.MessageToJson(histograms)) |
| 112 | + hs = histogram_set.HistogramSet() |
| 113 | + hs.ImportDicts(json_data) |
| 114 | + return hs |
82 | 115 |
|
83 | 116 |
|
84 | 117 | def _AddBuildInfo(histograms, options):
|
@@ -127,14 +160,16 @@ def _CreateParser():
|
127 | 160 | help='A JSON file with output from WebRTC tests.')
|
128 | 161 | parser.add_argument('--output-json-file', type=argparse.FileType('w'),
|
129 | 162 | help='Where to write the output (for debugging).')
|
| 163 | + parser.add_argument('--outdir', required=True, |
| 164 | + help='Path to the local out/ dir (usually out/Default)') |
130 | 165 | return parser
|
131 | 166 |
|
132 | 167 |
|
133 | 168 | def main(args):
|
134 | 169 | parser = _CreateParser()
|
135 | 170 | options = parser.parse_args(args)
|
136 | 171 |
|
137 |
| - histograms = _LoadHistogramSetFromJson(options) |
| 172 | + histograms = _LoadHistogramSetFromProto(options) |
138 | 173 | _AddBuildInfo(histograms, options)
|
139 | 174 |
|
140 | 175 | if options.output_json_file:
|
|
0 commit comments