зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1272768 - Teach `mach resource-usage` to load arbitrary URLs; r=chmanchester
Firefox automation now uploads resource usage JSON files as job artifacts (see bug 1272202). Now that the build system writes the same data format and `mach resource-usage` can read this data format, let's teach `mach resource-usage` to load arbitrary URLs. This allows people to view system resource usage for arbitrary jobs in automation. Currently, you have to look at Treeherder to find the URL to the build-resources.json artifact. Perhaps in the future we can make finding the URL easier. Or we could integrate source resource viewing into Treeherder itself (this is probably preferred). This commit continues the tradition of `mach resource-usage` being a hacked up mess. Instead of loading the URL in the browser, we download the URL from Python then serve it from the HTTP server running as part of `mach resource-usage`. This is somewhat horrible. But it was easiest to implement. It also conveniently bypasses any cross origin request restrictions the browser may impose. So it is useful. MozReview-Commit-ID: IR1Cfs7SrRN --HG-- extra : rebase_source : 91f5f807c19643ac4d1edb8f6652110813f7e53f
This commit is contained in:
Родитель
5b37de35f1
Коммит
d897b3b204
|
@ -10,6 +10,8 @@ import BaseHTTPServer
|
|||
import json
|
||||
import os
|
||||
|
||||
import requests
|
||||
|
||||
|
||||
class HTTPHandler(BaseHTTPServer.BaseHTTPRequestHandler):
|
||||
def do_GET(self):
|
||||
|
@ -36,9 +38,7 @@ class HTTPHandler(BaseHTTPServer.BaseHTTPRequestHandler):
|
|||
self.send_header('Content-Type', 'application/json; charset=utf-8')
|
||||
self.end_headers()
|
||||
|
||||
with open(s.json_files[key], 'rb') as fh:
|
||||
self.wfile.write(fh.read())
|
||||
|
||||
self.wfile.write(s.json_files[key])
|
||||
return
|
||||
|
||||
if p == '/':
|
||||
|
@ -105,7 +105,15 @@ class BuildViewerServer(object):
|
|||
"""Register a resource JSON file with the server.
|
||||
|
||||
The file will be made available under the name/key specified."""
|
||||
self.json_files[key] = path
|
||||
with open(path, 'rb') as fh:
|
||||
self.json_files[key] = fh.read()
|
||||
|
||||
def add_resource_json_url(self, key, url):
|
||||
"""Register a resource JSON file at a URL."""
|
||||
r = requests.get(url)
|
||||
if r.status_code != 200:
|
||||
raise Exception('Non-200 HTTP response code')
|
||||
self.json_files[key] = r.text
|
||||
|
||||
def run(self):
|
||||
while not self.do_shutdown:
|
||||
|
|
|
@ -579,19 +579,25 @@ class Build(MachCommandBase):
|
|||
help='Port number the HTTP server should listen on.')
|
||||
@CommandArgument('--browser', default='firefox',
|
||||
help='Web browser to automatically open. See webbrowser Python module.')
|
||||
def resource_usage(self, address=None, port=None, browser=None):
|
||||
@CommandArgument('--url',
|
||||
help='URL of JSON document to display')
|
||||
def resource_usage(self, address=None, port=None, browser=None, url=None):
|
||||
import webbrowser
|
||||
from mozbuild.html_build_viewer import BuildViewerServer
|
||||
|
||||
last = self._get_state_filename('build_resources.json')
|
||||
if not os.path.exists(last):
|
||||
print('Build resources not available. If you have performed a '
|
||||
'build and receive this message, the psutil Python package '
|
||||
'likely failed to initialize properly.')
|
||||
return 1
|
||||
|
||||
server = BuildViewerServer(address, port)
|
||||
server.add_resource_json_file('last', last)
|
||||
|
||||
if url:
|
||||
server.add_resource_json_url('url', url)
|
||||
else:
|
||||
last = self._get_state_filename('build_resources.json')
|
||||
if not os.path.exists(last):
|
||||
print('Build resources not available. If you have performed a '
|
||||
'build and receive this message, the psutil Python package '
|
||||
'likely failed to initialize properly.')
|
||||
return 1
|
||||
|
||||
server.add_resource_json_file('last', last)
|
||||
try:
|
||||
webbrowser.get(browser).open_new_tab(server.url)
|
||||
except Exception:
|
||||
|
|
Загрузка…
Ссылка в новой задаче