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 gzip | 7 import gzip |
8 import json | |
8 import logging | 9 import logging |
9 import optparse | 10 import optparse |
10 import os | 11 import os |
11 import re | 12 import re |
12 import select | 13 import select |
13 import shutil | 14 import shutil |
14 import sys | 15 import sys |
15 import threading | 16 import threading |
16 import time | 17 import time |
17 import webbrowser | 18 import webbrowser |
(...skipping 28 matching lines...) Expand all Loading... | |
46 self._trace_interval = None | 47 self._trace_interval = None |
47 self._trace_start_re = \ | 48 self._trace_start_re = \ |
48 re.compile(r'Logging performance trace to file') | 49 re.compile(r'Logging performance trace to file') |
49 self._trace_finish_re = \ | 50 self._trace_finish_re = \ |
50 re.compile(r'Profiler finished[.] Results are in (.*)[.]') | 51 re.compile(r'Profiler finished[.] Results are in (.*)[.]') |
51 self._device.old_interface.StartMonitoringLogcat(clear=False) | 52 self._device.old_interface.StartMonitoringLogcat(clear=False) |
52 | 53 |
53 def __str__(self): | 54 def __str__(self): |
54 return 'chrome trace' | 55 return 'chrome trace' |
55 | 56 |
57 @staticmethod | |
58 def GetCategories(device, package_info): | |
59 device.old_interface.BroadcastIntent( | |
60 package_info.package, 'GPU_PROFILER_LIST_CATEGORY') | |
61 try: | |
62 json_category_list = device.old_interface.WaitForLogMatch( | |
63 re.compile(r'{"traceCategoriesList(.*)'), None, timeout=5).group(0) | |
64 | |
65 record_categories = [] | |
66 disabled_by_default_categories = [] | |
67 try: | |
68 json_data = json.loads(json_category_list)['traceCategoriesList'] | |
69 for item in json_data: | |
70 if item.startswith('disabled-by-default'): | |
71 disabled_by_default_categories.append(item) | |
72 else: | |
73 record_categories.append(item) | |
74 except (ValueError, KeyError, TypeError): | |
75 logging.error('JSON format error') | |
Sami
2014/05/06 14:29:51
I'd prefer just passing these exceptions through s
r.kasibhatla
2014/05/06 15:22:29
Done.
| |
76 | |
77 _PrintMessage('Record Categories:') | |
Sami
2014/05/06 14:29:51
Instead of printing the results here, could you re
r.kasibhatla
2014/05/06 15:22:29
In the original patch, I was returning the tuple,
| |
78 _PrintMessage('\n'.join(str('\t%s' % item) \ | |
Sami
2014/05/06 14:29:51
Nit: "str" is unneeded here.
r.kasibhatla
2014/05/06 15:22:29
Done.
| |
79 for item in sorted(record_categories))) | |
80 | |
81 _PrintMessage('\nDisabled by Default Categories:') | |
82 _PrintMessage('\n'.join(str('\t%s' % item) \ | |
Sami
2014/05/06 14:29:51
Ditto.
r.kasibhatla
2014/05/06 15:22:29
Done.
| |
83 for item in sorted(disabled_by_default_categories))) | |
84 | |
85 except pexpect.TIMEOUT: | |
Sami
2014/05/06 14:29:51
Please move this try/except block immediately arou
r.kasibhatla
2014/05/06 15:22:29
Done.
| |
86 raise RuntimeError('Performance trace category list marker not found. ' | |
87 'Is the correct version of the browser running?') | |
88 | |
56 def StartTracing(self, interval): | 89 def StartTracing(self, interval): |
57 self._trace_interval = interval | 90 self._trace_interval = interval |
58 self._device.old_interface.SyncLogCat() | 91 self._device.old_interface.SyncLogCat() |
59 self._device.old_interface.BroadcastIntent( | 92 self._device.old_interface.BroadcastIntent( |
60 self._package_info.package, 'GPU_PROFILER_START', | 93 self._package_info.package, 'GPU_PROFILER_START', |
61 '-e categories "%s"' % ','.join(self._categories), | 94 '-e categories "%s"' % ','.join(self._categories), |
62 '-e continuous' if self._ring_buffer else '') | 95 '-e continuous' if self._ring_buffer else '') |
63 # Chrome logs two different messages related to tracing: | 96 # Chrome logs two different messages related to tracing: |
64 # | 97 # |
65 # 1. "Logging performance trace to file" | 98 # 1. "Logging performance trace to file" |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
317 'ring buffer and save its contents when stopping ' | 350 'ring buffer and save its contents when stopping ' |
318 'instead of appending events into one long trace.', | 351 'instead of appending events into one long trace.', |
319 action='store_true') | 352 action='store_true') |
320 parser.add_option_group(cont_options) | 353 parser.add_option_group(cont_options) |
321 | 354 |
322 categories = optparse.OptionGroup(parser, 'Trace categories') | 355 categories = optparse.OptionGroup(parser, 'Trace categories') |
323 categories.add_option('-c', '--categories', help='Select Chrome tracing ' | 356 categories.add_option('-c', '--categories', help='Select Chrome tracing ' |
324 'categories with comma-delimited wildcards, ' | 357 'categories with comma-delimited wildcards, ' |
325 'e.g., "*", "cat1*,-cat1a". Omit this option to trace ' | 358 'e.g., "*", "cat1*,-cat1a". Omit this option to trace ' |
326 'Chrome\'s default categories. Chrome tracing can be ' | 359 'Chrome\'s default categories. Chrome tracing can be ' |
327 'disabled with "--categories=\'\'".', | 360 'disabled with "--categories=\'\'". Use "list" to see ' |
361 'the available categories.', | |
328 metavar='CHROME_CATEGORIES', dest='chrome_categories', | 362 metavar='CHROME_CATEGORIES', dest='chrome_categories', |
329 default=_DEFAULT_CHROME_CATEGORIES) | 363 default=_DEFAULT_CHROME_CATEGORIES) |
330 categories.add_option('-s', '--systrace', help='Capture a systrace with the ' | 364 categories.add_option('-s', '--systrace', help='Capture a systrace with the ' |
331 'chosen comma-delimited systrace categories. You can ' | 365 'chosen comma-delimited systrace categories. You can ' |
332 'also capture a combined Chrome + systrace by enabling ' | 366 'also capture a combined Chrome + systrace by enabling ' |
333 'both types of categories. Use "list" to see the ' | 367 'both types of categories. Use "list" to see the ' |
334 'available categories. Systrace is disabled by ' | 368 'available categories. Systrace is disabled by ' |
335 'default.', metavar='SYS_CATEGORIES', | 369 'default.', metavar='SYS_CATEGORIES', |
336 dest='systrace_categories', default='') | 370 dest='systrace_categories', default='') |
337 categories.add_option('--trace-cc', | 371 categories.add_option('--trace-cc', |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
376 When in doubt, just try out --trace-frame-viewer. | 410 When in doubt, just try out --trace-frame-viewer. |
377 """) | 411 """) |
378 | 412 |
379 if options.verbose: | 413 if options.verbose: |
380 logging.getLogger().setLevel(logging.DEBUG) | 414 logging.getLogger().setLevel(logging.DEBUG) |
381 | 415 |
382 devices = android_commands.GetAttachedDevices() | 416 devices = android_commands.GetAttachedDevices() |
383 if len(devices) != 1: | 417 if len(devices) != 1: |
384 parser.error('Exactly 1 device much be attached.') | 418 parser.error('Exactly 1 device much be attached.') |
385 device = device_utils.DeviceUtils(devices[0]) | 419 device = device_utils.DeviceUtils(devices[0]) |
420 package_info = _GetSupportedBrowsers()[options.browser] | |
421 | |
422 if options.chrome_categories in ['list', 'help']: | |
423 _PrintMessage('Collecting data...', '\r') | |
Sami
2014/05/06 14:29:51
Nit: please use eol='' to match the other function
r.kasibhatla
2014/05/06 15:22:29
Done.
| |
424 ChromeTracingController.GetCategories(device, package_info) | |
425 return 0 | |
386 | 426 |
387 if options.systrace_categories in ['list', 'help']: | 427 if options.systrace_categories in ['list', 'help']: |
388 _PrintMessage('\n'.join(SystraceController.GetCategories(device))) | 428 _PrintMessage('\n'.join(SystraceController.GetCategories(device))) |
389 return 0 | 429 return 0 |
390 | 430 |
391 if not options.time and not options.continuous: | 431 if not options.time and not options.continuous: |
392 _PrintMessage('Time interval or continuous tracing should be specified.') | 432 _PrintMessage('Time interval or continuous tracing should be specified.') |
393 return 1 | 433 return 1 |
394 | 434 |
395 chrome_categories = _ComputeChromeCategories(options) | 435 chrome_categories = _ComputeChromeCategories(options) |
396 systrace_categories = _ComputeSystraceCategories(options) | 436 systrace_categories = _ComputeSystraceCategories(options) |
397 package_info = _GetSupportedBrowsers()[options.browser] | |
398 | 437 |
399 if chrome_categories and 'webview' in systrace_categories: | 438 if chrome_categories and 'webview' in systrace_categories: |
400 logging.warning('Using the "webview" category in systrace together with ' | 439 logging.warning('Using the "webview" category in systrace together with ' |
401 'Chrome tracing results in duplicate trace events.') | 440 'Chrome tracing results in duplicate trace events.') |
402 | 441 |
403 controllers = [] | 442 controllers = [] |
404 if chrome_categories: | 443 if chrome_categories: |
405 controllers.append(ChromeTracingController(device, | 444 controllers.append(ChromeTracingController(device, |
406 package_info, | 445 package_info, |
407 chrome_categories, | 446 chrome_categories, |
(...skipping 16 matching lines...) Expand all Loading... | |
424 options.json) | 463 options.json) |
425 if options.view: | 464 if options.view: |
426 if sys.platform == 'darwin': | 465 if sys.platform == 'darwin': |
427 os.system('/usr/bin/open %s' % os.path.abspath(result)) | 466 os.system('/usr/bin/open %s' % os.path.abspath(result)) |
428 else: | 467 else: |
429 webbrowser.open(result) | 468 webbrowser.open(result) |
430 | 469 |
431 | 470 |
432 if __name__ == '__main__': | 471 if __name__ == '__main__': |
433 sys.exit(main()) | 472 sys.exit(main()) |
OLD | NEW |