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

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: Rework! 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
« no previous file with comments | « no previous file | content/browser/android/tracing_controller_android.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 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
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_CATEGORIES')
61 try:
62 json_category_list = device.old_interface.WaitForLogMatch(
63 re.compile(r'{"traceCategoriesList(.*)'), None, timeout=5).group(0)
64 except pexpect.TIMEOUT:
65 raise RuntimeError('Performance trace category list marker not found. '
66 'Is the correct version of the browser running?')
67
68 record_categories = []
69 disabled_by_default_categories = []
70 json_data = json.loads(json_category_list)['traceCategoriesList']
71 for item in json_data:
72 if item.startswith('disabled-by-default'):
73 disabled_by_default_categories.append(item)
74 else:
75 record_categories.append(item)
76
77 return record_categories, disabled_by_default_categories
78
56 def StartTracing(self, interval): 79 def StartTracing(self, interval):
57 self._trace_interval = interval 80 self._trace_interval = interval
58 self._device.old_interface.SyncLogCat() 81 self._device.old_interface.SyncLogCat()
59 self._device.old_interface.BroadcastIntent( 82 self._device.old_interface.BroadcastIntent(
60 self._package_info.package, 'GPU_PROFILER_START', 83 self._package_info.package, 'GPU_PROFILER_START',
61 '-e categories "%s"' % ','.join(self._categories), 84 '-e categories "%s"' % ','.join(self._categories),
62 '-e continuous' if self._ring_buffer else '') 85 '-e continuous' if self._ring_buffer else '')
63 # Chrome logs two different messages related to tracing: 86 # Chrome logs two different messages related to tracing:
64 # 87 #
65 # 1. "Logging performance trace to file" 88 # 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 ' 340 'ring buffer and save its contents when stopping '
318 'instead of appending events into one long trace.', 341 'instead of appending events into one long trace.',
319 action='store_true') 342 action='store_true')
320 parser.add_option_group(cont_options) 343 parser.add_option_group(cont_options)
321 344
322 categories = optparse.OptionGroup(parser, 'Trace categories') 345 categories = optparse.OptionGroup(parser, 'Trace categories')
323 categories.add_option('-c', '--categories', help='Select Chrome tracing ' 346 categories.add_option('-c', '--categories', help='Select Chrome tracing '
324 'categories with comma-delimited wildcards, ' 347 'categories with comma-delimited wildcards, '
325 'e.g., "*", "cat1*,-cat1a". Omit this option to trace ' 348 'e.g., "*", "cat1*,-cat1a". Omit this option to trace '
326 'Chrome\'s default categories. Chrome tracing can be ' 349 'Chrome\'s default categories. Chrome tracing can be '
327 'disabled with "--categories=\'\'".', 350 'disabled with "--categories=\'\'". Use "list" to see '
351 'the available categories.',
328 metavar='CHROME_CATEGORIES', dest='chrome_categories', 352 metavar='CHROME_CATEGORIES', dest='chrome_categories',
329 default=_DEFAULT_CHROME_CATEGORIES) 353 default=_DEFAULT_CHROME_CATEGORIES)
330 categories.add_option('-s', '--systrace', help='Capture a systrace with the ' 354 categories.add_option('-s', '--systrace', help='Capture a systrace with the '
331 'chosen comma-delimited systrace categories. You can ' 355 'chosen comma-delimited systrace categories. You can '
332 'also capture a combined Chrome + systrace by enabling ' 356 'also capture a combined Chrome + systrace by enabling '
333 'both types of categories. Use "list" to see the ' 357 'both types of categories. Use "list" to see the '
334 'available categories. Systrace is disabled by ' 358 'available categories. Systrace is disabled by '
335 'default.', metavar='SYS_CATEGORIES', 359 'default.', metavar='SYS_CATEGORIES',
336 dest='systrace_categories', default='') 360 dest='systrace_categories', default='')
337 categories.add_option('--trace-cc', 361 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. 400 When in doubt, just try out --trace-frame-viewer.
377 """) 401 """)
378 402
379 if options.verbose: 403 if options.verbose:
380 logging.getLogger().setLevel(logging.DEBUG) 404 logging.getLogger().setLevel(logging.DEBUG)
381 405
382 devices = android_commands.GetAttachedDevices() 406 devices = android_commands.GetAttachedDevices()
383 if len(devices) != 1: 407 if len(devices) != 1:
384 parser.error('Exactly 1 device much be attached.') 408 parser.error('Exactly 1 device much be attached.')
385 device = device_utils.DeviceUtils(devices[0]) 409 device = device_utils.DeviceUtils(devices[0])
410 package_info = _GetSupportedBrowsers()[options.browser]
411
412 if options.chrome_categories in ['list', 'help']:
413 _PrintMessage('Collecting record categories list...', eol='')
414 record_categories = []
415 disabled_by_default_categories = []
416 record_categories, disabled_by_default_categories = \
417 ChromeTracingController.GetCategories(device, package_info)
418
419 _PrintMessage('done')
420 _PrintMessage('Record Categories:')
421 _PrintMessage('\n'.join('\t%s' % item \
422 for item in sorted(record_categories)))
423
424 _PrintMessage('\nDisabled by Default Categories:')
425 _PrintMessage('\n'.join('\t%s' % item \
426 for item in sorted(disabled_by_default_categories)))
427
428 return 0
386 429
387 if options.systrace_categories in ['list', 'help']: 430 if options.systrace_categories in ['list', 'help']:
388 _PrintMessage('\n'.join(SystraceController.GetCategories(device))) 431 _PrintMessage('\n'.join(SystraceController.GetCategories(device)))
389 return 0 432 return 0
390 433
391 if not options.time and not options.continuous: 434 if not options.time and not options.continuous:
392 _PrintMessage('Time interval or continuous tracing should be specified.') 435 _PrintMessage('Time interval or continuous tracing should be specified.')
393 return 1 436 return 1
394 437
395 chrome_categories = _ComputeChromeCategories(options) 438 chrome_categories = _ComputeChromeCategories(options)
396 systrace_categories = _ComputeSystraceCategories(options) 439 systrace_categories = _ComputeSystraceCategories(options)
397 package_info = _GetSupportedBrowsers()[options.browser]
398 440
399 if chrome_categories and 'webview' in systrace_categories: 441 if chrome_categories and 'webview' in systrace_categories:
400 logging.warning('Using the "webview" category in systrace together with ' 442 logging.warning('Using the "webview" category in systrace together with '
401 'Chrome tracing results in duplicate trace events.') 443 'Chrome tracing results in duplicate trace events.')
402 444
403 controllers = [] 445 controllers = []
404 if chrome_categories: 446 if chrome_categories:
405 controllers.append(ChromeTracingController(device, 447 controllers.append(ChromeTracingController(device,
406 package_info, 448 package_info,
407 chrome_categories, 449 chrome_categories,
(...skipping 16 matching lines...) Expand all
424 options.json) 466 options.json)
425 if options.view: 467 if options.view:
426 if sys.platform == 'darwin': 468 if sys.platform == 'darwin':
427 os.system('/usr/bin/open %s' % os.path.abspath(result)) 469 os.system('/usr/bin/open %s' % os.path.abspath(result))
428 else: 470 else:
429 webbrowser.open(result) 471 webbrowser.open(result)
430 472
431 473
432 if __name__ == '__main__': 474 if __name__ == '__main__':
433 sys.exit(main()) 475 sys.exit(main())
OLDNEW
« no previous file with comments | « no previous file | content/browser/android/tracing_controller_android.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698