Repurpose upload script to read natively generated histogram json.
This script will be used when tests write proto-backed JSON. It still
has to reside source-side because we need to access the catapult Python
API to get at HistogramSet and reserved_infos, etc.
WebRTC tests will write proto-backed JSON, and this script can read
it because the Histogram class has been made capable of doing it.
Build information diagnostics are added, and then we upload in the
old JSON format (the dashboard can read the new format as well, but
there's no reason to implement export to the new format at this point).
We could imagine more outlandish solutions where the test binaries
themselves do the uploading, but then we would have to pass the
build information to them, and they would have to upload from the
shards. Alternatively, we could pass build information to tests so
they write it right into the histograms.
This solution is probably the best one for now since it's
1) consistent with how Chromium does it
2) flexible in the right ways
3) we don't have to worry if uploading from shards even works.
Bug: webrtc:11084
Change-Id: I8888ce9f24e0ca58f984d2c2e9af7740ee5e89b6
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/166464
Commit-Queue: Patrik Höglund <phoglund@webrtc.org>
Reviewed-by: Artem Titov <titovartem@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#30301}
diff --git a/tools_webrtc/perf/webrtc_dashboard_upload.py b/tools_webrtc/perf/webrtc_dashboard_upload.py
index d04374a..2eb1d97 100644
--- a/tools_webrtc/perf/webrtc_dashboard_upload.py
+++ b/tools_webrtc/perf/webrtc_dashboard_upload.py
@@ -7,32 +7,33 @@
# in the file PATENTS. All contributing project authors may
# be found in the AUTHORS file in the root of the source tree.
-"""Converts and uploads results to the Chrome perf dashboard.
+"""Adds build info to perf results and uploads them.
-This conversion step is needed because test/testsupport/perf_test.cc can't
-output histograms natively. There is, unfortunately, no C++ API for histograms.
-This script is in python so it can depend on Catapult's python API instead.
-See histogram_util.py for how this is done. We should move to the C++ API and
-delete the scripts in this dir as soon as there is a C++ API (less conversions =
-easier to understand).
+The tests don't know which bot executed the tests or at what revision, so we
+need to take their output and enrich it with this information. We load the JSON
+from the tests, add the build information as shared diagnostics and then
+upload it to the dashboard.
This script can't be in recipes, because we can't access the catapult APIs from
there. It needs to be here source-side.
-
-This script is adapted from the downstream variant like this:
- * Follows upstream naming conventions.
- * Downstream-only parameters and concepts go away.
- * oAuth tokens are generated by luci-auth.
"""
import argparse
import httplib2
import json
+import os
import sys
import subprocess
import zlib
-import histogram_util
+SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__))
+CHECKOUT_ROOT = os.path.abspath(os.path.join(SCRIPT_DIR, os.pardir, os.pardir))
+sys.path.insert(0, os.path.join(CHECKOUT_ROOT, 'third_party', 'catapult',
+ 'tracing'))
+
+from tracing.value import histogram_set
+from tracing.value.diagnostics import generic_set
+from tracing.value.diagnostics import reserved_infos
def _GenerateOauthToken():
@@ -47,18 +48,23 @@
(p.stdout.read(), p.stderr.read()))
-def _SendHistogramSetJson(url, histogram_json, oauth_token):
+def _SendHistogramSet(url, histograms, oauth_token):
"""Make a HTTP POST with the given JSON to the Performance Dashboard.
Args:
url: URL of Performance Dashboard instance, e.g.
"https://chromeperf.appspot.com".
- histogram_json: a JSON object that contains the data to be sent.
+ histograms: a histogram set object that contains the data to be sent.
oauth_token: An oauth token to use for authorization.
"""
headers = {'Authorization': 'Bearer %s' % oauth_token}
- serialized = json.dumps(histogram_json.AsDicts(), indent=4)
- data = zlib.compress(serialized)
+ serialized = json.dumps(histograms.AsDicts(), indent=4)
+
+ if url.startswith('http://localhost'):
+ # The catapult server turns off compression in developer mode.
+ data = serialized
+ else:
+ data = zlib.compress(serialized)
http = httplib2.Http()
response, content = http.request(url + '/add_histograms', method='POST',
@@ -66,21 +72,33 @@
return response, content
-def _LoadHistogramSetJson(options):
+def _LoadHistogramSetFromJson(options):
with options.input_results_file as f:
json_data = json.load(f)
- histograms = histogram_util.LoadHistograms(json_data)
- hs = histogram_util.MakeWebRtcHistogramSet(
- stats=histograms,
- commit_pos=options.commit_position,
- commit_hash=options.webrtc_git_hash,
- master=options.perf_dashboard_machine_group,
- bot=options.bot,
- test_suite=options.test_suite,
- build_url=options.build_page_url)
+ histograms = histogram_set.HistogramSet()
+ histograms.ImportDicts(json_data)
+ return histograms
- return hs
+
+def _AddBuildInfo(histograms, options):
+ common_diagnostics = {
+ reserved_infos.MASTERS: options.perf_dashboard_machine_group,
+ reserved_infos.BOTS: options.bot,
+ reserved_infos.POINT_ID: options.commit_position,
+ reserved_infos.BENCHMARKS: options.test_suite,
+ reserved_infos.WEBRTC_REVISIONS: str(options.webrtc_git_hash),
+ reserved_infos.BUILD_URLS: options.build_page_url,
+ }
+
+ for k, v in common_diagnostics.items():
+ histograms.AddSharedDiagnosticToAllHistograms(
+ k.name, generic_set.GenericSet([v]))
+
+
+def _DumpOutput(histograms, output_file):
+ with output_file:
+ json.dump(histograms.AsDicts(), output_file, indent=4)
def _CreateParser():
@@ -116,15 +134,15 @@
parser = _CreateParser()
options = parser.parse_args(args)
- histogram_json = _LoadHistogramSetJson(options)
+ histograms = _LoadHistogramSetFromJson(options)
+ _AddBuildInfo(histograms, options)
if options.output_json_file:
- with options.output_json_file as output_file:
- json.dump(histogram_json.AsDicts(), output_file, indent=4)
+ _DumpOutput(histograms, options.output_json_file)
oauth_token = _GenerateOauthToken()
- response, content = _SendHistogramSetJson(
- options.dashboard_url, histogram_json, oauth_token)
+ response, content = _SendHistogramSet(
+ options.dashboard_url, histograms, oauth_token)
if response.status == 200:
return 0