| OLD | NEW |
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 # Disable the line-too-long warning. | 5 # Disable the line-too-long warning. |
| 6 # pylint: disable=C0301 | 6 # pylint: disable=C0301 |
| 7 """This module implements the Chromium Performance Dashboard JSON v1.0 data | 7 """This module implements the Chromium Performance Dashboard JSON v1.0 data |
| 8 format. | 8 format. |
| 9 | 9 |
| 10 See http://www.chromium.org/developers/speed-infra/performance-dashboard/sending
-data-to-the-performance-dashboard. | 10 See http://www.chromium.org/developers/speed-infra/performance-dashboard/sending
-data-to-the-performance-dashboard. |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 """Returns the number of git commits in the repository of the cwd.""" | 108 """Returns the number of git commits in the repository of the cwd.""" |
| 109 return subprocess.check_output( | 109 return subprocess.check_output( |
| 110 ['git', 'rev-list', 'HEAD', '--count']).strip() | 110 ['git', 'rev-list', 'HEAD', '--count']).strip() |
| 111 | 111 |
| 112 | 112 |
| 113 def _get_current_commit(): | 113 def _get_current_commit(): |
| 114 """Returns the hash of the current commit in the repository of the cwd.""" | 114 """Returns the hash of the current commit in the repository of the cwd.""" |
| 115 return subprocess.check_output(["git", "rev-parse", "HEAD"]).strip() | 115 return subprocess.check_output(["git", "rev-parse", "HEAD"]).strip() |
| 116 | 116 |
| 117 | 117 |
| 118 class _UploadException(Exception): |
| 119 pass |
| 120 |
| 121 |
| 122 def _upload(server_url, json_data): |
| 123 """Make an HTTP POST with the given data to the performance dashboard. |
| 124 |
| 125 Args: |
| 126 server_url: URL of the performance dashboard instance. |
| 127 json_data: JSON string that contains the data to be sent. |
| 128 |
| 129 Raises: |
| 130 _UploadException: An error occurred during uploading. |
| 131 """ |
| 132 # When data is provided to urllib2.Request, a POST is sent instead of GET. |
| 133 # The data must be in the application/x-www-form-urlencoded format. |
| 134 data = urllib.urlencode({"data": json_data}) |
| 135 req = urllib2.Request("%s/add_point" % server_url, data) |
| 136 try: |
| 137 urllib2.urlopen(req) |
| 138 except urllib2.HTTPError as e: |
| 139 raise _UploadException('HTTPError: %d. Response: %s\n' |
| 140 'JSON: %s\n' % (e.code, e.read(), json_data)) |
| 141 except urllib2.URLError as e: |
| 142 raise _UploadException('URLError: %s for JSON %s\n' % |
| 143 (str(e.reason), json_data)) |
| 144 except httplib.HTTPException as e: |
| 145 raise _UploadException('HTTPException for JSON %s\n' % json_data) |
| 146 |
| 147 |
| 118 def upload_chart_data(master_name, bot_name, test_name, builder_name, | 148 def upload_chart_data(master_name, bot_name, test_name, builder_name, |
| 119 build_number, chart_data, server_url=None, dry_run=False): | 149 build_number, chart_data, server_url=None, dry_run=False): |
| 120 """Uploads the provided chart data to an instance of performance dashboard. | 150 """Uploads the provided chart data to an instance of performance dashboard. |
| 121 See the argparse help above for description of the arguments. | 151 See the argparse help above for description of the arguments. |
| 122 | 152 |
| 123 | 153 |
| 124 Returns: | 154 Returns: |
| 125 A boolean value indicating whether the operation succeeded or not. | 155 A boolean value indicating whether the operation succeeded or not. |
| 126 """ | 156 """ |
| 127 class _UploadException(Exception): | |
| 128 pass | |
| 129 | |
| 130 def _upload(server_url, json_data): | |
| 131 """Make an HTTP POST with the given data to the performance dashboard. | |
| 132 | |
| 133 Args: | |
| 134 server_url: URL of the performance dashboard instance. | |
| 135 json_data: JSON string that contains the data to be sent. | |
| 136 | |
| 137 Raises: | |
| 138 _UploadException: An error occurred during uploading. | |
| 139 """ | |
| 140 # When data is provided to urllib2.Request, a POST is sent instead of GET. | |
| 141 # The data must be in the application/x-www-form-urlencoded format. | |
| 142 data = urllib.urlencode({"data": json_data}) | |
| 143 req = urllib2.Request("%s/add_point" % server_url, data) | |
| 144 try: | |
| 145 urllib2.urlopen(req) | |
| 146 except urllib2.HTTPError as e: | |
| 147 raise _UploadException('HTTPError: %d. Response: %s\n' | |
| 148 'JSON: %s\n' % (e.code, e.read(), json_data)) | |
| 149 except urllib2.URLError as e: | |
| 150 raise _UploadException('URLError: %s for JSON %s\n' % | |
| 151 (str(e.reason), json_data)) | |
| 152 except httplib.HTTPException as e: | |
| 153 raise _UploadException('HTTPException for JSON %s\n' % json_data) | |
| 154 | 157 |
| 155 if (not master_name or not bot_name or not test_name or not builder_name or | 158 if (not master_name or not bot_name or not test_name or not builder_name or |
| 156 not build_number): | 159 not build_number): |
| 157 print ('Cannot upload perf data to the dashboard because not all of the ' | 160 print ('Cannot upload perf data to the dashboard because not all of the ' |
| 158 'following values are specified: master-name, bot-name, test_name, ' | 161 'following values are specified: master-name, bot-name, test_name, ' |
| 159 'builder-name, build-number.') | 162 'builder-name, build-number.') |
| 160 return False | 163 return False |
| 161 | 164 |
| 162 point_id = _get_commit_count() | 165 point_id = _get_commit_count() |
| 163 cur_commit = _get_current_commit() | 166 cur_commit = _get_current_commit() |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 | 199 |
| 197 dashboard_params = urllib.urlencode({ | 200 dashboard_params = urllib.urlencode({ |
| 198 'masters': master_name, | 201 'masters': master_name, |
| 199 'bots': bot_name, | 202 'bots': bot_name, |
| 200 'tests': test_name, | 203 'tests': test_name, |
| 201 'rev': point_id | 204 'rev': point_id |
| 202 }) | 205 }) |
| 203 print 'Results Dashboard: %s/report?%s' % (upload_url, dashboard_params) | 206 print 'Results Dashboard: %s/report?%s' % (upload_url, dashboard_params) |
| 204 | 207 |
| 205 return True | 208 return True |
| OLD | NEW |