| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # | 2 # |
| 3 # Copyright 2013 The Chromium Authors. All rights reserved. | 3 # Copyright 2013 The Chromium Authors. All rights reserved. |
| 4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
| 6 | 6 |
| 7 import base64 | 7 import base64 |
| 8 import gzip | 8 import gzip |
| 9 import logging | 9 import logging |
| 10 import optparse | 10 import optparse |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 </head> | 58 </head> |
| 59 <body> | 59 <body> |
| 60 <div class="view"></view> | 60 <div class="view"></view> |
| 61 </body> | 61 </body> |
| 62 </html>""" | 62 </html>""" |
| 63 | 63 |
| 64 _DEFAULT_CHROME_CATEGORIES = '_DEFAULT_CHROME_CATEGORIES' | 64 _DEFAULT_CHROME_CATEGORIES = '_DEFAULT_CHROME_CATEGORIES' |
| 65 | 65 |
| 66 | 66 |
| 67 def _GetTraceTimestamp(): | 67 def _GetTraceTimestamp(): |
| 68 return time.strftime('%Y-%m-%d-%H%M%S', time.localtime()) | 68 return time.strftime('%Y-%m-%d-%H%M%S', time.localtime()) |
| 69 | 69 |
| 70 | 70 |
| 71 def _PackageTraceAsHtml(trace_file_name, html_file_name): | 71 def _PackageTraceAsHtml(trace_file_name, html_file_name): |
| 72 trace_viewer_root = os.path.join(constants.DIR_SOURCE_ROOT, | 72 trace_viewer_root = os.path.join(constants.DIR_SOURCE_ROOT, |
| 73 'third_party', 'trace-viewer') | 73 'third_party', 'trace-viewer') |
| 74 build_dir = os.path.join(trace_viewer_root, 'build') | 74 build_dir = os.path.join(trace_viewer_root, 'build') |
| 75 src_dir = os.path.join(trace_viewer_root, 'src') | 75 src_dir = os.path.join(trace_viewer_root, 'src') |
| 76 if not build_dir in sys.path: | 76 if not build_dir in sys.path: |
| 77 sys.path.append(build_dir) | 77 sys.path.append(build_dir) |
| 78 generate = __import__('generate', {}, {}) | 78 generate = __import__('generate', {}, {}) |
| 79 parse_deps = __import__('parse_deps', {}, {}) | 79 parse_deps = __import__('parse_deps', {}, {}) |
| 80 | 80 |
| 81 basename = os.path.splitext(trace_file_name)[0] | |
| 82 load_sequence = parse_deps.calc_load_sequence( | 81 load_sequence = parse_deps.calc_load_sequence( |
| 83 ['tracing/standalone_timeline_view.js'], [src_dir]) | 82 ['tracing/standalone_timeline_view.js'], [src_dir]) |
| 84 | 83 |
| 85 with open(trace_file_name) as trace_file: | 84 with open(trace_file_name) as trace_file: |
| 86 trace_data = base64.b64encode(trace_file.read()) | 85 trace_data = base64.b64encode(trace_file.read()) |
| 87 with open(html_file_name, 'w') as html_file: | 86 with open(html_file_name, 'w') as html_file: |
| 88 html = _TRACE_VIEWER_TEMPLATE % { | 87 html = _TRACE_VIEWER_TEMPLATE % { |
| 89 'title': os.path.basename(os.path.splitext(trace_file_name)[0]), | 88 'title': os.path.basename(os.path.splitext(trace_file_name)[0]), |
| 90 'timeline_js': generate.generate_js(load_sequence), | 89 'timeline_js': generate.generate_js(load_sequence), |
| 91 'timeline_css': generate.generate_css(load_sequence), | 90 'timeline_css': generate.generate_css(load_sequence), |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 self._thread = None | 167 self._thread = None |
| 169 self._trace_data = None | 168 self._trace_data = None |
| 170 | 169 |
| 171 def __str__(self): | 170 def __str__(self): |
| 172 return 'systrace' | 171 return 'systrace' |
| 173 | 172 |
| 174 @staticmethod | 173 @staticmethod |
| 175 def GetCategories(adb): | 174 def GetCategories(adb): |
| 176 return adb.RunShellCommand('atrace --list_categories') | 175 return adb.RunShellCommand('atrace --list_categories') |
| 177 | 176 |
| 178 def StartTracing(self, interval): | 177 def StartTracing(self, _): |
| 179 self._thread = threading.Thread(target=self._CollectData) | 178 self._thread = threading.Thread(target=self._CollectData) |
| 180 self._thread.start() | 179 self._thread.start() |
| 181 | 180 |
| 182 def StopTracing(self): | 181 def StopTracing(self): |
| 183 self._done.set() | 182 self._done.set() |
| 184 | 183 |
| 185 def PullTrace(self): | 184 def PullTrace(self): |
| 186 self._thread.join() | 185 self._thread.join() |
| 187 self._thread = None | 186 self._thread = None |
| 188 if self._trace_data: | 187 if self._trace_data: |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 393 | 392 |
| 394 browsers = sorted(_GetSupportedBrowsers().keys()) | 393 browsers = sorted(_GetSupportedBrowsers().keys()) |
| 395 parser.add_option('-b', '--browser', help='Select among installed browsers. ' | 394 parser.add_option('-b', '--browser', help='Select among installed browsers. ' |
| 396 'One of ' + ', '.join(browsers) + ', "stable" is used by ' | 395 'One of ' + ', '.join(browsers) + ', "stable" is used by ' |
| 397 'default.', type='choice', choices=browsers, | 396 'default.', type='choice', choices=browsers, |
| 398 default='stable') | 397 default='stable') |
| 399 parser.add_option('-v', '--verbose', help='Verbose logging.', | 398 parser.add_option('-v', '--verbose', help='Verbose logging.', |
| 400 action='store_true') | 399 action='store_true') |
| 401 parser.add_option('-z', '--compress', help='Compress the resulting trace ' | 400 parser.add_option('-z', '--compress', help='Compress the resulting trace ' |
| 402 'with gzip. ', action='store_true') | 401 'with gzip. ', action='store_true') |
| 403 options, args = parser.parse_args() | 402 options, _ = parser.parse_args() |
| 404 | 403 |
| 405 if options.verbose: | 404 if options.verbose: |
| 406 logging.getLogger().setLevel(logging.DEBUG) | 405 logging.getLogger().setLevel(logging.DEBUG) |
| 407 | 406 |
| 408 adb = android_commands.AndroidCommands() | 407 adb = android_commands.AndroidCommands() |
| 409 if options.systrace_categories in ['list', 'help']: | 408 if options.systrace_categories in ['list', 'help']: |
| 410 _PrintMessage('\n'.join(SystraceController.GetCategories(adb))) | 409 _PrintMessage('\n'.join(SystraceController.GetCategories(adb))) |
| 411 return 0 | 410 return 0 |
| 412 | 411 |
| 413 if not options.time and not options.continuous: | 412 if not options.time and not options.continuous: |
| (...skipping 27 matching lines...) Expand all Loading... |
| 441 options.time if not options.continuous else 0, | 440 options.time if not options.continuous else 0, |
| 442 options.output, | 441 options.output, |
| 443 options.compress, | 442 options.compress, |
| 444 options.html) | 443 options.html) |
| 445 if options.view: | 444 if options.view: |
| 446 webbrowser.open(result) | 445 webbrowser.open(result) |
| 447 | 446 |
| 448 | 447 |
| 449 if __name__ == '__main__': | 448 if __name__ == '__main__': |
| 450 sys.exit(main()) | 449 sys.exit(main()) |
| OLD | NEW |