Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(722)

Side by Side Diff: mojo/tools/mopy/perf_data_uploader.py

Issue 1421823002: Move performance dashboard upload logic to devtoolslib. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Move the argparse part too. Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « mojo/tools/get_test_list.py ('k') | mojo/tools/perf_test_runner.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4
5 """Uploads data points to the performance dashboard.
6
7 By default uploads to a local testing dashboard assumed to be running on the
8 host. To run such server, check out Catapult and follow instructions at
9 https://github.com/catapult-project/catapult/blob/master/dashboard/README.md .
10 """
11
12 import httplib
13 import json
14 import pprint
15 import urllib
16 import urllib2
17
18 # TODO(yzshen): The following are missing currently:
19 # (1) CL range on the dashboard;
20 # (2) improvement direction on the dashboard;
21 # (3) a link from the build step pointing to the dashboard page.
22
23 _PRODUCTION_SERVER = "https://chromeperf.appspot.com"
24 _TESTING_SERVER = "http://127.0.0.1:8080"
25
26
27 def UploadPerfData(master_name, perf_id, test_name, builder_name, build_number,
28 revision, chart_data, point_id, dry_run=False,
29 testing_dashboard=True):
30 """Uploads the provided chart data to performance dashboard.
31
32 Returns:
33 A boolean value indicating whether the operation succeeded or not.
34 """
35 class _UploadException(Exception):
36 pass
37
38 def _Upload(server_url, json_data):
39 """Make an HTTP POST with the given data to the performance dashboard.
40
41 Args:
42 server_url: URL of the performance dashboard instance.
43 json_data: JSON string that contains the data to be sent.
44
45 Raises:
46 _UploadException: An error occurred during uploading.
47 """
48 # When data is provided to urllib2.Request, a POST is sent instead of GET.
49 # The data must be in the application/x-www-form-urlencoded format.
50 data = urllib.urlencode({"data": json_data})
51 req = urllib2.Request("%s/add_point" % server_url, data)
52 try:
53 urllib2.urlopen(req)
54 except urllib2.HTTPError as e:
55 raise _UploadException("HTTPError: %d. Response: %s\n"
56 "JSON: %s\n" % (e.code, e.read(), json_data))
57 except urllib2.URLError as e:
58 raise _UploadException("URLError: %s for JSON %s\n" %
59 (str(e.reason), json_data))
60 except httplib.HTTPException as e:
61 raise _UploadException("HTTPException for JSON %s\n" % json_data)
62
63 # Wrap the |chart_data| with meta data as required by the spec.
64 formatted_data = {
65 "master": master_name,
66 "bot": perf_id,
67 "masterid": master_name,
68 "buildername": builder_name,
69 "buildnumber": build_number,
70 "versions": {
71 "mojo": revision
72 },
73 "point_id": point_id,
74 "supplemental": {},
75 "chart_data": chart_data
76 }
77
78 server_url = _TESTING_SERVER if testing_dashboard else _PRODUCTION_SERVER
79
80 if dry_run:
81 print "Won't upload because --dry-run is specified."
82 print "Server: %s" % server_url
83 print "Data:"
84 pprint.pprint(formatted_data)
85 else:
86 print "Uploading data to %s ..." % server_url
87 try:
88 _Upload(server_url, json.dumps(formatted_data))
89 except _UploadException as e:
90 print e
91 return False
92
93 print "Done."
94
95 dashboard_params = urllib.urlencode({
96 "masters": master_name,
97 "bots": perf_id,
98 "tests": test_name,
99 "rev": point_id
100 })
101 print "Results Dashboard: %s/report?%s" % (server_url, dashboard_params)
102
103 return True
OLDNEW
« no previous file with comments | « mojo/tools/get_test_list.py ('k') | mojo/tools/perf_test_runner.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698