| 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 argparse | 6 import argparse |
| 7 import codecs | 7 import codecs |
| 8 import logging | 8 import logging |
| 9 import os.path | 9 import os.path |
| 10 import requests | 10 import requests |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 | 38 |
| 39 def _send_request(request, payload=None): | 39 def _send_request(request, payload=None): |
| 40 """Sends a request to mojo:debugger.""" | 40 """Sends a request to mojo:debugger.""" |
| 41 try: | 41 try: |
| 42 url = 'http://localhost:%s/%s' % (_MOJO_DEBUGGER_PORT, request) | 42 url = 'http://localhost:%s/%s' % (_MOJO_DEBUGGER_PORT, request) |
| 43 if payload: | 43 if payload: |
| 44 return requests.post(url, payload) | 44 return requests.post(url, payload) |
| 45 else: | 45 else: |
| 46 return requests.get(url) | 46 return requests.get(url) |
| 47 except requests.exceptions.ConnectionError: | 47 except requests.exceptions.ConnectionError: |
| 48 print 'Failed to connect to mojo:debugger, make sure the shell is running.' | 48 print ('Failed to connect to debugger.mojo. Make sure the shell is running ' |
| 49 'and the app was started with debugger, ie. through ' |
| 50 '`mojo_run --debugger APP_URL`') |
| 51 |
| 49 return None | 52 return None |
| 50 | 53 |
| 51 | 54 |
| 52 def _tracing_start(_): | 55 def _tracing_start(_): |
| 53 """Starts tracing.""" | 56 """Starts tracing.""" |
| 54 if not _send_request('start_tracing'): | 57 if not _send_request('start_tracing'): |
| 55 return 1 | 58 return 1 |
| 56 print "Started tracing." | 59 print "Started tracing." |
| 57 return 0 | 60 return 0 |
| 58 | 61 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 84 trace_file.write('{"traceEvents":[') | 87 trace_file.write('{"traceEvents":[') |
| 85 trace_file.write(response.content) | 88 trace_file.write(response.content) |
| 86 trace_file.write(']}') | 89 trace_file.write(']}') |
| 87 print "Trace saved in %s" % file_name | 90 print "Trace saved in %s" % file_name |
| 88 return 0 | 91 return 0 |
| 89 | 92 |
| 90 | 93 |
| 91 def _add_tracing_command(subparsers): | 94 def _add_tracing_command(subparsers): |
| 92 """Sets up the command line parser to manage tracing.""" | 95 """Sets up the command line parser to manage tracing.""" |
| 93 tracing_parser = subparsers.add_parser('tracing', | 96 tracing_parser = subparsers.add_parser('tracing', |
| 94 help='trace event profiler') | 97 help='tracer (requires debugger.mojo)') |
| 95 tracing_subparser = tracing_parser.add_subparsers( | 98 tracing_subparser = tracing_parser.add_subparsers( |
| 96 help='the command to run') | 99 help='the command to run') |
| 97 | 100 |
| 98 start_tracing_parser = tracing_subparser.add_parser('start', | 101 start_tracing_parser = tracing_subparser.add_parser('start', |
| 99 help='start tracing') | 102 help='start tracing') |
| 100 start_tracing_parser.set_defaults(func=_tracing_start) | 103 start_tracing_parser.set_defaults(func=_tracing_start) |
| 101 | 104 |
| 102 stop_tracing_parser = tracing_subparser.add_parser('stop', | 105 stop_tracing_parser = tracing_subparser.add_parser('stop', |
| 103 help='stop tracing and retrieve the result') | 106 help='stop tracing and retrieve the result') |
| 104 stop_tracing_parser.add_argument('file_name', type=str, nargs='?', | 107 stop_tracing_parser.add_argument('file_name', type=str, nargs='?', |
| 105 help='name of the output file (optional)') | 108 help='name of the output file (optional)') |
| 106 stop_tracing_parser.set_defaults(func=_tracing_stop) | 109 stop_tracing_parser.set_defaults(func=_tracing_stop) |
| 107 | 110 |
| 108 | 111 |
| 109 def _wm_load(args): | 112 def _wm_load(args): |
| 110 """Loads (embeds) the given url in the window manager.""" | 113 """Loads (embeds) the given url in the window manager.""" |
| 111 if not _send_request('load', args.url): | 114 if not _send_request('load', args.url): |
| 112 return 1 | 115 return 1 |
| 113 return 0 | 116 return 0 |
| 114 | 117 |
| 115 | 118 |
| 116 def _add_wm_command(subparsers): | 119 def _add_wm_command(subparsers): |
| 117 """Sets up the parser for the 'wm' command.""" | 120 """Sets up the parser for the 'wm' command.""" |
| 118 wm_parser = subparsers.add_parser('wm', help='window manager') | 121 wm_parser = subparsers.add_parser('wm', help='window manager (requires ' |
| 122 'debugger.mojo)') |
| 119 wm_subparser = wm_parser.add_subparsers( | 123 wm_subparser = wm_parser.add_subparsers( |
| 120 help='the command to run') | 124 help='the command to run') |
| 121 | 125 |
| 122 wm_load_parser = wm_subparser.add_parser('load', | 126 wm_load_parser = wm_subparser.add_parser('load', |
| 123 help='load (embed) the given url') | 127 help='load (embed) the given url') |
| 124 wm_load_parser.add_argument('url', type=str, | 128 wm_load_parser.add_argument('url', type=str, |
| 125 help='the url to load') | 129 help='the url to load') |
| 126 wm_load_parser.set_defaults(func=_wm_load) | 130 wm_load_parser.set_defaults(func=_wm_load) |
| 127 | 131 |
| 128 | 132 |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 _add_device_command(subparsers) | 325 _add_device_command(subparsers) |
| 322 _add_tracing_command(subparsers) | 326 _add_tracing_command(subparsers) |
| 323 _add_wm_command(subparsers) | 327 _add_wm_command(subparsers) |
| 324 _add_gdb_command(subparsers) | 328 _add_gdb_command(subparsers) |
| 325 | 329 |
| 326 args = parser.parse_args() | 330 args = parser.parse_args() |
| 327 return args.func(args) | 331 return args.func(args) |
| 328 | 332 |
| 329 if __name__ == '__main__': | 333 if __name__ == '__main__': |
| 330 sys.exit(main()) | 334 sys.exit(main()) |
| OLD | NEW |