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

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

Issue 291723002: Add --trace-memory option for tracing heap memory (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 | no next file » | 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 json
9 import logging 9 import logging
10 import optparse 10 import optparse
(...skipping 13 matching lines...) Expand all
24 from pylib import constants 24 from pylib import constants
25 from pylib import pexpect 25 from pylib import pexpect
26 from pylib.device import device_utils 26 from pylib.device import device_utils
27 27
28 _TRACE_VIEWER_ROOT = os.path.join(constants.DIR_SOURCE_ROOT, 28 _TRACE_VIEWER_ROOT = os.path.join(constants.DIR_SOURCE_ROOT,
29 'third_party', 'trace-viewer') 29 'third_party', 'trace-viewer')
30 sys.path.append(_TRACE_VIEWER_ROOT) 30 sys.path.append(_TRACE_VIEWER_ROOT)
31 from trace_viewer.build import trace2html # pylint: disable=F0401 31 from trace_viewer.build import trace2html # pylint: disable=F0401
32 32
33 _DEFAULT_CHROME_CATEGORIES = '_DEFAULT_CHROME_CATEGORIES' 33 _DEFAULT_CHROME_CATEGORIES = '_DEFAULT_CHROME_CATEGORIES'
34 34 _HEAP_PROFILE_MMAP_PROPERTY = 'heapprof.mmap'
35 35
36 def _GetTraceTimestamp(): 36 def _GetTraceTimestamp():
37 return time.strftime('%Y-%m-%d-%H%M%S', time.localtime()) 37 return time.strftime('%Y-%m-%d-%H%M%S', time.localtime())
38 38
39 39
40 class ChromeTracingController(object): 40 class ChromeTracingController(object):
41 def __init__(self, device, package_info, categories, ring_buffer): 41 def __init__(self, device, package_info, categories, ring_buffer):
42 self._device = device 42 self._device = device
43 self._package_info = package_info 43 self._package_info = package_info
44 self._categories = categories 44 self._categories = categories
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 def _ComputeChromeCategories(options): 302 def _ComputeChromeCategories(options):
303 categories = [] 303 categories = []
304 if options.trace_frame_viewer: 304 if options.trace_frame_viewer:
305 categories.append('disabled-by-default-cc.debug') 305 categories.append('disabled-by-default-cc.debug')
306 if options.trace_ubercompositor: 306 if options.trace_ubercompositor:
307 categories.append('disabled-by-default-cc.debug*') 307 categories.append('disabled-by-default-cc.debug*')
308 if options.trace_gpu: 308 if options.trace_gpu:
309 categories.append('disabled-by-default-gpu.debug*') 309 categories.append('disabled-by-default-gpu.debug*')
310 if options.trace_flow: 310 if options.trace_flow:
311 categories.append('disabled-by-default-toplevel.flow') 311 categories.append('disabled-by-default-toplevel.flow')
312 if options.trace_memory:
313 categories.append('disabled-by-default-memory')
312 if options.chrome_categories: 314 if options.chrome_categories:
313 categories += options.chrome_categories.split(',') 315 categories += options.chrome_categories.split(',')
314 return categories 316 return categories
315 317
316 318
317 def _ComputeSystraceCategories(options): 319 def _ComputeSystraceCategories(options):
318 if not options.systrace_categories: 320 if not options.systrace_categories:
319 return [] 321 return []
320 return options.systrace_categories.split(',') 322 return options.systrace_categories.split(',')
321 323
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 categories.add_option('--trace-frame-viewer', 366 categories.add_option('--trace-frame-viewer',
365 help='Enable enough trace categories for ' 367 help='Enable enough trace categories for '
366 'compositor frame viewing.', action='store_true') 368 'compositor frame viewing.', action='store_true')
367 categories.add_option('--trace-ubercompositor', 369 categories.add_option('--trace-ubercompositor',
368 help='Enable enough trace categories for ' 370 help='Enable enough trace categories for '
369 'ubercompositor frame data.', action='store_true') 371 'ubercompositor frame data.', action='store_true')
370 categories.add_option('--trace-gpu', help='Enable extra trace categories for ' 372 categories.add_option('--trace-gpu', help='Enable extra trace categories for '
371 'GPU data.', action='store_true') 373 'GPU data.', action='store_true')
372 categories.add_option('--trace-flow', help='Enable extra trace categories ' 374 categories.add_option('--trace-flow', help='Enable extra trace categories '
373 'for IPC message flows.', action='store_true') 375 'for IPC message flows.', action='store_true')
376 categories.add_option('--trace-memory', help='Enable extra trace categories '
377 'for memory profile. (tcmalloc required)',
378 action='store_true')
374 parser.add_option_group(categories) 379 parser.add_option_group(categories)
375 380
376 output_options = optparse.OptionGroup(parser, 'Output options') 381 output_options = optparse.OptionGroup(parser, 'Output options')
377 output_options.add_option('-o', '--output', help='Save trace output to file.') 382 output_options.add_option('-o', '--output', help='Save trace output to file.')
378 output_options.add_option('--json', help='Save trace as raw JSON instead of ' 383 output_options.add_option('--json', help='Save trace as raw JSON instead of '
379 'HTML.', action='store_true') 384 'HTML.', action='store_true')
380 output_options.add_option('--view', help='Open resulting trace file in a ' 385 output_options.add_option('--view', help='Open resulting trace file in a '
381 'browser.', action='store_true') 386 'browser.', action='store_true')
382 parser.add_option_group(output_options) 387 parser.add_option_group(output_options)
383 388
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 return 0 433 return 0
429 434
430 if options.systrace_categories in ['list', 'help']: 435 if options.systrace_categories in ['list', 'help']:
431 _PrintMessage('\n'.join(SystraceController.GetCategories(device))) 436 _PrintMessage('\n'.join(SystraceController.GetCategories(device)))
432 return 0 437 return 0
433 438
434 if not options.time and not options.continuous: 439 if not options.time and not options.continuous:
435 _PrintMessage('Time interval or continuous tracing should be specified.') 440 _PrintMessage('Time interval or continuous tracing should be specified.')
436 return 1 441 return 1
437 442
443 system_properties = device.old_interface.system_properties
Sami 2014/05/22 15:52:38 Could you please move this bit of code to ChromeTr
444 if options.trace_memory:
445 device.old_interface.EnableAdbRoot()
446 system_properties[_HEAP_PROFILE_MMAP_PROPERTY] = 1
447
438 chrome_categories = _ComputeChromeCategories(options) 448 chrome_categories = _ComputeChromeCategories(options)
439 systrace_categories = _ComputeSystraceCategories(options) 449 systrace_categories = _ComputeSystraceCategories(options)
440 450
441 if chrome_categories and 'webview' in systrace_categories: 451 if chrome_categories and 'webview' in systrace_categories:
442 logging.warning('Using the "webview" category in systrace together with ' 452 logging.warning('Using the "webview" category in systrace together with '
443 'Chrome tracing results in duplicate trace events.') 453 'Chrome tracing results in duplicate trace events.')
444 454
445 controllers = [] 455 controllers = []
446 if chrome_categories: 456 if chrome_categories:
447 controllers.append(ChromeTracingController(device, 457 controllers.append(ChromeTracingController(device,
448 package_info, 458 package_info,
449 chrome_categories, 459 chrome_categories,
450 options.ring_buffer)) 460 options.ring_buffer))
451 if systrace_categories: 461 if systrace_categories:
452 controllers.append(SystraceController(device, 462 controllers.append(SystraceController(device,
453 systrace_categories, 463 systrace_categories,
454 options.ring_buffer)) 464 options.ring_buffer))
455 465
456 if not controllers: 466 if not controllers:
457 _PrintMessage('No trace categories enabled.') 467 _PrintMessage('No trace categories enabled.')
458 return 1 468 return 1
459 469
460 if options.output: 470 if options.output:
461 options.output = os.path.expanduser(options.output) 471 options.output = os.path.expanduser(options.output)
462 result = _CaptureAndPullTrace(controllers, 472 result = _CaptureAndPullTrace(controllers,
463 options.time if not options.continuous else 0, 473 options.time if not options.continuous else 0,
464 options.output, 474 options.output,
465 options.compress, 475 options.compress,
466 options.json) 476 options.json)
477
478 if options.trace_memory:
Sami 2014/05/22 15:52:38 ...and this code to ChromeTracingController.StopTr
479 system_properties[_HEAP_PROFILE_MMAP_PROPERTY] = 0
480
467 if options.view: 481 if options.view:
468 if sys.platform == 'darwin': 482 if sys.platform == 'darwin':
469 os.system('/usr/bin/open %s' % os.path.abspath(result)) 483 os.system('/usr/bin/open %s' % os.path.abspath(result))
470 else: 484 else:
471 webbrowser.open(result) 485 webbrowser.open(result)
472 486
473 487
474 if __name__ == '__main__': 488 if __name__ == '__main__':
475 sys.exit(main()) 489 sys.exit(main())
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698