Skip to content
This repository was archived by the owner on Oct 25, 2024. It is now read-only.

Commit 728b5d0

Browse files
Andrey LogvinCommit Bot
authored andcommitted
Add possibility of upload check for pc perf tests
Presubmit bot failures are unrelated to the cl. No-Presubmit: True Bug: webrtc:12162 Change-Id: I598d3aea8df9429bdff18b80a400c358fa1461d2 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/186123 Commit-Queue: Andrey Logvin <[email protected]> Reviewed-by: Mirko Bonadei <[email protected]> Reviewed-by: Artem Titov <[email protected]> Cr-Commit-Position: refs/heads/master@{#32592}
1 parent 7dff9f3 commit 728b5d0

File tree

2 files changed

+120
-48
lines changed

2 files changed

+120
-48
lines changed

tools_webrtc/perf/catapult_uploader.py

Lines changed: 85 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77
# in the file PATENTS. All contributing project authors may
88
# be found in the AUTHORS file in the root of the source tree.
99

10+
import datetime
1011
import httplib2
1112
import json
1213
import subprocess
14+
import time
1315
import zlib
1416

1517
from tracing.value import histogram
@@ -33,12 +35,12 @@ def _GenerateOauthToken():
3335
def _SendHistogramSet(url, histograms, oauth_token):
3436
"""Make a HTTP POST with the given JSON to the Performance Dashboard.
3537
36-
Args:
37-
url: URL of Performance Dashboard instance, e.g.
38-
"https://chromeperf.appspot.com".
39-
histograms: a histogram set object that contains the data to be sent.
40-
oauth_token: An oauth token to use for authorization.
41-
"""
38+
Args:
39+
url: URL of Performance Dashboard instance, e.g.
40+
"https://chromeperf.appspot.com".
41+
histograms: a histogram set object that contains the data to be sent.
42+
oauth_token: An oauth token to use for authorization.
43+
"""
4244
headers = {'Authorization': 'Bearer %s' % oauth_token}
4345

4446
serialized = json.dumps(_ApplyHacks(histograms.AsDicts()), indent=4)
@@ -59,6 +61,52 @@ def _SendHistogramSet(url, histograms, oauth_token):
5961
return response, content
6062

6163

64+
def _WaitForUploadConfirmation(url, oauth_token, upload_token, wait_timeout,
65+
wait_polling_period):
66+
"""Make a HTTP GET requests to the Performance Dashboard untill upload
67+
status is known or the time is out.
68+
69+
Args:
70+
url: URL of Performance Dashboard instance, e.g.
71+
"https://chromeperf.appspot.com".
72+
oauth_token: An oauth token to use for authorization.
73+
upload_token: String that identifies Performance Dashboard and can be used
74+
for the status check.
75+
wait_timeout: (datetime.timedelta) Maximum time to wait for the
76+
confirmation.
77+
wait_polling_period: (datetime.timedelta) Performance Dashboard will be
78+
polled every wait_polling_period amount of time.
79+
"""
80+
assert wait_polling_period <= wait_timeout
81+
82+
headers = {'Authorization': 'Bearer %s' % oauth_token}
83+
http = httplib2.Http()
84+
85+
response = None
86+
resp_json = None
87+
current_time = datetime.datetime.now()
88+
end_time = current_time + wait_timeout
89+
next_poll_time = current_time + wait_polling_period
90+
while datetime.datetime.now() < end_time:
91+
current_time = datetime.datetime.now()
92+
if next_poll_time > current_time:
93+
time.sleep((next_poll_time - current_time).total_seconds())
94+
next_poll_time = datetime.datetime.now() + wait_polling_period
95+
96+
response, content = http.request(url + '/uploads' + upload_token,
97+
method='GET', headers=headers)
98+
resp_json = json.loads(content)
99+
100+
print 'Upload state polled. Response: %s.' % content
101+
102+
if (response.status != 200 or
103+
resp_json['state'] == 'COMPLETED' or
104+
resp_json['state'] == 'FAILED'):
105+
break
106+
107+
return response, resp_json
108+
109+
62110
# TODO(https://crbug.com/1029452): HACKHACK
63111
# Remove once we have doubles in the proto and handle -infinity correctly.
64112
def _ApplyHacks(dicts):
@@ -113,13 +161,36 @@ def UploadToDashboard(options):
113161
_DumpOutput(histograms, options.output_json_file)
114162

115163
oauth_token = _GenerateOauthToken()
116-
response, content = _SendHistogramSet(options.dashboard_url, histograms,
117-
oauth_token)
164+
response, content = _SendHistogramSet(
165+
options.dashboard_url, histograms, oauth_token)
166+
167+
upload_token = json.loads(content).get('token')
168+
if not options.wait_for_upload or not upload_token:
169+
print 'Not waiting for upload status confirmation.'
170+
if response.status == 200:
171+
print 'Received 200 from dashboard.'
172+
return 0
173+
else:
174+
print('Upload failed with %d: %s\n\n%s' % (response.status,
175+
response.reason, content))
176+
return 1
177+
178+
response, resp_json = _WaitForUploadConfirmation(
179+
options.dashboard_url,
180+
oauth_token,
181+
upload_token,
182+
datetime.timedelta(seconds=options.wait_timeout_sec),
183+
datetime.timedelta(seconds=options.wait_polling_period_sec))
184+
185+
if response.status != 200 or resp_json['state'] == 'FAILED':
186+
print('Upload failed with %d: %s\n\n%s' % (response.status,
187+
response.reason,
188+
str(resp_json)))
189+
return 1
118190

119-
if response.status == 200:
120-
print 'Received 200 from dashboard.'
191+
if resp_json['state'] == 'COMPLETED':
192+
print 'Upload completed.'
121193
return 0
122-
else:
123-
print('Upload failed with %d: %s\n\n%s' %
124-
(response.status, response.reason, content))
125-
return 1
194+
195+
print('Upload wasn\'t completed in a given time: %d.', options.wait_timeout)
196+
return 1

tools_webrtc/perf/webrtc_dashboard_upload.py

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -24,54 +24,54 @@
2424

2525
def _CreateParser():
2626
parser = argparse.ArgumentParser()
27-
parser.add_argument('--perf-dashboard-machine-group',
28-
required=True,
27+
parser.add_argument('--perf-dashboard-machine-group', required=True,
2928
help='The "master" the bots are grouped under. This '
3029
'string is the group in the the perf dashboard path '
3130
'group/bot/perf_id/metric/subtest.')
32-
parser.add_argument('--bot',
33-
required=True,
31+
parser.add_argument('--bot', required=True,
3432
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,
33+
'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,
4439
help='webrtc.googlesource.com commit hash.')
45-
parser.add_argument('--commit-position',
46-
type=int,
47-
required=True,
40+
parser.add_argument('--commit-position', type=int, required=True,
4841
help='Commit pos corresponding to the git hash.')
49-
parser.add_argument('--build-page-url',
50-
required=True,
42+
parser.add_argument('--build-page-url', required=True,
5143
help='URL to the build page for this build.')
52-
parser.add_argument('--dashboard-url',
53-
required=True,
44+
parser.add_argument('--dashboard-url', required=True,
5445
help='Which dashboard to use.')
55-
parser.add_argument('--input-results-file',
56-
type=argparse.FileType(),
46+
parser.add_argument('--input-results-file', type=argparse.FileType(),
5747
required=True,
5848
help='A JSON file with output from WebRTC tests.')
59-
parser.add_argument('--output-json-file',
60-
type=argparse.FileType('w'),
49+
parser.add_argument('--output-json-file', type=argparse.FileType('w'),
6150
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)')
51+
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.')
6665
return parser
6766

6867

6968
def _ConfigurePythonPath(options):
7069
# 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.
70+
# 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.
7575
#
7676
# It would be better if there was an equivalent to py_binary in GN, but
7777
# there's not.
@@ -84,8 +84,9 @@ def _ConfigurePythonPath(options):
8484
sys.path.insert(
8585
0, os.path.join(checkout_root, 'third_party', 'protobuf', 'python'))
8686

87-
# 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.
87+
# 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.
8990
histogram_proto_path = os.path.join(options.outdir, 'pyproto', 'tracing',
9091
'tracing', 'proto')
9192
sys.path.insert(0, histogram_proto_path)

0 commit comments

Comments
 (0)