Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(207)

Side by Side Diff: build/android/adb_profile_chrome.py

Issue 257093004: [Android] Add an option to view the tracing record categories when running from python script. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Minor style cleanup! Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 logging 8 import logging
9 import optparse 9 import optparse
10 import os 10 import os
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 self._trace_interval = None 46 self._trace_interval = None
47 self._trace_start_re = \ 47 self._trace_start_re = \
48 re.compile(r'Logging performance trace to file') 48 re.compile(r'Logging performance trace to file')
49 self._trace_finish_re = \ 49 self._trace_finish_re = \
50 re.compile(r'Profiler finished[.] Results are in (.*)[.]') 50 re.compile(r'Profiler finished[.] Results are in (.*)[.]')
51 self._device.old_interface.StartMonitoringLogcat(clear=False) 51 self._device.old_interface.StartMonitoringLogcat(clear=False)
52 52
53 def __str__(self): 53 def __str__(self):
54 return 'chrome trace' 54 return 'chrome trace'
55 55
56 @staticmethod
57 def GetCategories(device, package_info):
58 device.old_interface.BroadcastIntent(
59 package_info.package, 'GPU_PROFILER_LIST_CATEGORY')
60 try:
61 trace_list_category_re = re.compile(r'{"traceCategoriesList": \[(.*)\]}')
62 category_list = device.old_interface.WaitForLogMatch(
Xianzhu 2014/05/05 16:32:21 You may want to use 'import json'.
r.kasibhatla 2014/05/06 11:04:06 Done.
63 trace_list_category_re, None, timeout=5).group(1).split(',')
64
65 record_categories = []
66 disabled_by_default_categories = []
67 # Divide the list into default and debug lists.
68 for item in category_list:
69 item = item.strip("\"")
70 if item.startswith('disabled-by-default'):
71 disabled_by_default_categories.append(item)
72 else:
73 record_categories.append(item)
74
75 # Sort the individual lists.
76 record_categories = list(set(record_categories))
77 record_categories.sort()
78 disabled_by_default_categories = list(set(disabled_by_default_categories))
79 disabled_by_default_categories.sort()
80
81 return record_categories, disabled_by_default_categories
82
83 except pexpect.TIMEOUT:
84 raise RuntimeError('Performance trace category list marker not found. '
85 'Is the correct version of the browser running?')
86
56 def StartTracing(self, interval): 87 def StartTracing(self, interval):
57 self._trace_interval = interval 88 self._trace_interval = interval
58 self._device.old_interface.SyncLogCat() 89 self._device.old_interface.SyncLogCat()
59 self._device.old_interface.BroadcastIntent( 90 self._device.old_interface.BroadcastIntent(
60 self._package_info.package, 'GPU_PROFILER_START', 91 self._package_info.package, 'GPU_PROFILER_START',
61 '-e categories "%s"' % ','.join(self._categories), 92 '-e categories "%s"' % ','.join(self._categories),
62 '-e continuous' if self._ring_buffer else '') 93 '-e continuous' if self._ring_buffer else '')
63 # Chrome logs two different messages related to tracing: 94 # Chrome logs two different messages related to tracing:
64 # 95 #
65 # 1. "Logging performance trace to file" 96 # 1. "Logging performance trace to file"
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 'ring buffer and save its contents when stopping ' 348 'ring buffer and save its contents when stopping '
318 'instead of appending events into one long trace.', 349 'instead of appending events into one long trace.',
319 action='store_true') 350 action='store_true')
320 parser.add_option_group(cont_options) 351 parser.add_option_group(cont_options)
321 352
322 categories = optparse.OptionGroup(parser, 'Trace categories') 353 categories = optparse.OptionGroup(parser, 'Trace categories')
323 categories.add_option('-c', '--categories', help='Select Chrome tracing ' 354 categories.add_option('-c', '--categories', help='Select Chrome tracing '
324 'categories with comma-delimited wildcards, ' 355 'categories with comma-delimited wildcards, '
325 'e.g., "*", "cat1*,-cat1a". Omit this option to trace ' 356 'e.g., "*", "cat1*,-cat1a". Omit this option to trace '
326 'Chrome\'s default categories. Chrome tracing can be ' 357 'Chrome\'s default categories. Chrome tracing can be '
327 'disabled with "--categories=\'\'".', 358 'disabled with "--categories=\'\'". Use "list" to see '
359 'the available categories.',
328 metavar='CHROME_CATEGORIES', dest='chrome_categories', 360 metavar='CHROME_CATEGORIES', dest='chrome_categories',
329 default=_DEFAULT_CHROME_CATEGORIES) 361 default=_DEFAULT_CHROME_CATEGORIES)
330 categories.add_option('-s', '--systrace', help='Capture a systrace with the ' 362 categories.add_option('-s', '--systrace', help='Capture a systrace with the '
331 'chosen comma-delimited systrace categories. You can ' 363 'chosen comma-delimited systrace categories. You can '
332 'also capture a combined Chrome + systrace by enabling ' 364 'also capture a combined Chrome + systrace by enabling '
333 'both types of categories. Use "list" to see the ' 365 'both types of categories. Use "list" to see the '
334 'available categories. Systrace is disabled by ' 366 'available categories. Systrace is disabled by '
335 'default.', metavar='SYS_CATEGORIES', 367 'default.', metavar='SYS_CATEGORIES',
336 dest='systrace_categories', default='') 368 dest='systrace_categories', default='')
337 categories.add_option('--trace-cc', 369 categories.add_option('--trace-cc',
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 When in doubt, just try out --trace-frame-viewer. 408 When in doubt, just try out --trace-frame-viewer.
377 """) 409 """)
378 410
379 if options.verbose: 411 if options.verbose:
380 logging.getLogger().setLevel(logging.DEBUG) 412 logging.getLogger().setLevel(logging.DEBUG)
381 413
382 devices = android_commands.GetAttachedDevices() 414 devices = android_commands.GetAttachedDevices()
383 if len(devices) != 1: 415 if len(devices) != 1:
384 parser.error('Exactly 1 device much be attached.') 416 parser.error('Exactly 1 device much be attached.')
385 device = device_utils.DeviceUtils(devices[0]) 417 device = device_utils.DeviceUtils(devices[0])
418 package_info = _GetSupportedBrowsers()[options.browser]
419
420 if options.chrome_categories in ['list', 'help']:
421 _PrintMessage('Fetching the record categories list ...')
422 record_categories = []
423 disabled_by_default_categories = []
424 record_categories, disabled_by_default_categories = \
425 ChromeTracingController.GetCategories(device, package_info)
426
427 _PrintMessage('\nRecord Categories -\n')
428 for item in record_categories:
429 _PrintMessage(item)
430
431 _PrintMessage('\nDisabled by Default Categories -\n')
432 for item in disabled_by_default_categories:
433 _PrintMessage(item)
434
435 return 0
386 436
387 if options.systrace_categories in ['list', 'help']: 437 if options.systrace_categories in ['list', 'help']:
388 _PrintMessage('\n'.join(SystraceController.GetCategories(device))) 438 _PrintMessage('\n'.join(SystraceController.GetCategories(device)))
389 return 0 439 return 0
390 440
391 if not options.time and not options.continuous: 441 if not options.time and not options.continuous:
392 _PrintMessage('Time interval or continuous tracing should be specified.') 442 _PrintMessage('Time interval or continuous tracing should be specified.')
393 return 1 443 return 1
394 444
395 chrome_categories = _ComputeChromeCategories(options) 445 chrome_categories = _ComputeChromeCategories(options)
396 systrace_categories = _ComputeSystraceCategories(options) 446 systrace_categories = _ComputeSystraceCategories(options)
397 package_info = _GetSupportedBrowsers()[options.browser]
398 447
399 if chrome_categories and 'webview' in systrace_categories: 448 if chrome_categories and 'webview' in systrace_categories:
400 logging.warning('Using the "webview" category in systrace together with ' 449 logging.warning('Using the "webview" category in systrace together with '
401 'Chrome tracing results in duplicate trace events.') 450 'Chrome tracing results in duplicate trace events.')
402 451
403 controllers = [] 452 controllers = []
404 if chrome_categories: 453 if chrome_categories:
405 controllers.append(ChromeTracingController(device, 454 controllers.append(ChromeTracingController(device,
406 package_info, 455 package_info,
407 chrome_categories, 456 chrome_categories,
(...skipping 16 matching lines...) Expand all
424 options.json) 473 options.json)
425 if options.view: 474 if options.view:
426 if sys.platform == 'darwin': 475 if sys.platform == 'darwin':
427 os.system('/usr/bin/open %s' % os.path.abspath(result)) 476 os.system('/usr/bin/open %s' % os.path.abspath(result))
428 else: 477 else:
429 webbrowser.open(result) 478 webbrowser.open(result)
430 479
431 480
432 if __name__ == '__main__': 481 if __name__ == '__main__':
433 sys.exit(main()) 482 sys.exit(main())
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698