OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2014 The Chromium Authors. All rights reserved. | 2 # Copyright 2014 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 import os | 6 import os |
7 import re | 7 import re |
8 import skypy.paths as paths | 8 from skypy.paths import Paths |
9 import subprocess | 9 import subprocess |
10 import requests | 10 import requests |
11 | 11 |
12 | 12 |
13 SUPPORTED_MIME_TYPES = [ | 13 SUPPORTED_MIME_TYPES = [ |
14 'text/html', | 14 'text/html', |
15 'text/sky', | 15 'text/sky', |
16 'text/plain', | 16 'text/plain', |
17 ] | 17 ] |
18 HTTP_PORT = 9999 | 18 HTTP_PORT = 9999 |
19 | 19 |
20 DASHBOARD_URL = 'https://chromeperf.appspot.com/add_point' | 20 DASHBOARD_URL = 'https://chromeperf.appspot.com/add_point' |
21 | 21 |
22 | 22 |
23 def sky_tester_command(url): | |
24 content_handlers = ['%s,%s' % (mime_type, 'mojo://sky_viewer/') | |
25 for mime_type in SUPPORTED_MIME_TYPES] | |
26 return [ | |
27 paths.MOJO_SHELL_PATH, | |
28 '--args-for=mojo://native_viewport_service/ --use-headless-config --use-
osmesa', | |
29 '--args-for=mojo://window_manager/ %s' % url, | |
30 '--content-handlers=%s' % ','.join(content_handlers), | |
31 '--url-mappings=mojo:window_manager=mojo://sky_tester/', | |
32 'mojo:window_manager', | |
33 ] | |
34 | |
35 | |
36 def start_sky_server(port): | |
37 return subprocess.Popen([ | |
38 os.path.join(paths.SKY_TOOLS_DIRECTORY, 'sky_server'), | |
39 paths.SRC_ROOT, | |
40 str(port), | |
41 ]) | |
42 | |
43 | |
44 def values_from_output(output): | 23 def values_from_output(output): |
45 # Parse out the raw values from the PerfRunner output: | 24 # Parse out the raw values from the PerfRunner output: |
46 # values 90, 89, 93 ms | 25 # values 90, 89, 93 ms |
47 # We'll probably need a fancier parser at some point. | 26 # We'll probably need a fancier parser at some point. |
48 match = re.search(r'values (.+) ms', output, flags=re.MULTILINE) | 27 match = re.search(r'values (.+) ms', output, flags=re.MULTILINE) |
49 return map(float, match.group(1).split(', ')) | 28 return map(float, match.group(1).split(', ')) |
50 | 29 |
51 | 30 |
52 def create_json_blob(values): | 31 def create_json_blob(values): |
53 revision = subprocess.check_output(["git", "show-ref", "HEAD", "-s"]).strip(
) | 32 revision = subprocess.check_output(["git", "show-ref", "HEAD", "-s"]).strip(
) |
(...skipping 21 matching lines...) Expand all Loading... |
75 } | 54 } |
76 | 55 |
77 | 56 |
78 def send_json_to_dashboard(json): | 57 def send_json_to_dashboard(json): |
79 requests.post(DASHBOARD_URL, params={ 'data': json }) | 58 requests.post(DASHBOARD_URL, params={ 'data': json }) |
80 | 59 |
81 | 60 |
82 class PerfHarness(object): | 61 class PerfHarness(object): |
83 def __init__(self): | 62 def __init__(self): |
84 self._sky_server = None | 63 self._sky_server = None |
| 64 self.paths = Paths(os.path.join('out', 'Debug')) |
85 | 65 |
86 def _start_server(self): | 66 def _start_server(self): |
87 self._sky_server = start_sky_server(HTTP_PORT) | 67 return subprocess.Popen([ |
| 68 os.path.join(self.paths.sky_tools_directory, 'sky_server'), |
| 69 self.paths.src_root, |
| 70 str(HTTP_PORT), |
| 71 ]) |
| 72 |
| 73 def _sky_tester_command(self, url): |
| 74 content_handlers = ['%s,%s' % (mime_type, 'mojo://sky_viewer/') |
| 75 for mime_type in SUPPORTED_MIME_TYPES] |
| 76 return [ |
| 77 self.paths.mojo_shell_path, |
| 78 '--args-for=mojo://native_viewport_service/ --use-headless-config --
use-osmesa', |
| 79 '--args-for=mojo://window_manager/ %s' % url, |
| 80 '--content-handlers=%s' % ','.join(content_handlers), |
| 81 '--url-mappings=mojo:window_manager=mojo://sky_tester/', |
| 82 'mojo:window_manager', |
| 83 ] |
| 84 |
88 | 85 |
89 def main(self): | 86 def main(self): |
90 test = 'http://localhost:9999/sky/benchmarks/layout/simple-blocks.sky' | 87 test = 'http://localhost:9999/sky/benchmarks/layout/simple-blocks.sky' |
91 | 88 |
92 self._start_server() | 89 self._start_server() |
93 output = subprocess.check_output(sky_tester_command(test)) | 90 output = subprocess.check_output(self._sky_tester_command(test)) |
94 values = values_from_output(output) | 91 values = values_from_output(output) |
95 json = create_json_blob(values) | 92 json = create_json_blob(values) |
96 send_json_to_dashboard(json) | 93 send_json_to_dashboard(json) |
97 | 94 |
98 def shutdown(self): | 95 def shutdown(self): |
99 if self._sky_server: | 96 if self._sky_server: |
100 self._sky_server.terminate() | 97 self._sky_server.terminate() |
101 | 98 |
102 | 99 |
103 if __name__ == '__main__': | 100 if __name__ == '__main__': |
104 harness = PerfHarness() | 101 harness = PerfHarness() |
105 try: | 102 try: |
106 harness.main() | 103 harness.main() |
107 except (KeyboardInterrupt, SystemExit): | 104 except (KeyboardInterrupt, SystemExit): |
108 pass | 105 pass |
109 finally: | 106 finally: |
110 harness.shutdown() | 107 harness.shutdown() |
OLD | NEW |