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

Side by Side Diff: systrace/bin/adb_profile_chrome_startup

Issue 2297403003: Use Systrace tracing controller in profile_chrome (Closed) Base URL: https://chromium.googlesource.com/external/github.com/catapult-project/catapult.git@master
Patch Set: Added property method for tracing controller's child agents Created 4 years, 3 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 2015 The Chromium Authors. All rights reserved. 3 # Copyright 2015 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 logging 7 import logging
8 import optparse 8 import optparse
9 import os 9 import os
10 import sys 10 import sys
11 import webbrowser 11 import webbrowser
12 12
13 _SYSTRACE_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), '..')) 13 _SYSTRACE_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
14 sys.path.append(_SYSTRACE_DIR) 14 sys.path.append(_SYSTRACE_DIR)
15 15
16 from profile_chrome import atrace_tracing_agent 16 from profile_chrome import atrace_tracing_agent
17 from profile_chrome import chrome_startup_tracing_agent 17 from profile_chrome import chrome_startup_tracing_agent
18 from profile_chrome import flags 18 from profile_chrome import flags
19 from profile_chrome import profiler 19 from profile_chrome import profiler
20 from profile_chrome import ui 20 from profile_chrome import ui
21 21
22 _CATAPULT_DIR = os.path.join( 22 _CATAPULT_DIR = os.path.join(
23 os.path.dirname(os.path.abspath(__file__)), '..', '..') 23 os.path.dirname(os.path.abspath(__file__)), '..', '..')
24 sys.path.append(os.path.join(_CATAPULT_DIR, 'devil')) 24 sys.path.append(os.path.join(_CATAPULT_DIR, 'devil'))
25 25
26 from devil.android import device_utils 26 from devil.android import device_utils
27 27
28 28
29 _CHROME_STARTUP_MODULES = [atrace_tracing_agent,
30 chrome_startup_tracing_agent]
31 _DEFAULT_CHROME_CATEGORIES = '_DEFAULT_CHROME_CATEGORIES'
32
33
29 def _CreateOptionParser(): 34 def _CreateOptionParser():
30 parser = optparse.OptionParser(description='Record about://tracing profiles ' 35 parser = optparse.OptionParser(description='Record about://tracing profiles '
31 'from Android browsers startup, combined with ' 36 'from Android browsers startup, combined with '
32 'Android systrace. See http://dev.chromium.org' 37 'Android systrace. See http://dev.chromium.org'
33 '/developers/how-tos/trace-event-profiling-' 38 '/developers/how-tos/trace-event-profiling-'
34 'tool for detailed instructions for ' 39 'tool for detailed instructions for '
35 'profiling.') 40 'profiling.')
36 41
37 browsers = sorted(profiler.GetSupportedBrowsers().keys()) 42 browsers = sorted(profiler.GetSupportedBrowsers().keys())
38 parser.add_option('-b', '--browser', help='Select among installed browsers. ' 43 parser.add_option('-b', '--browser', help='Select among installed browsers. '
39 'One of ' + ', '.join(browsers) + ', "stable" is used by ' 44 'One of ' + ', '.join(browsers) + ', "stable" is used by '
40 'default.', type='choice', choices=browsers, 45 'default.', type='choice', choices=browsers,
41 default='stable') 46 default='stable')
42 parser.add_option('-v', '--verbose', help='Verbose logging.', 47 parser.add_option('-v', '--verbose', help='Verbose logging.',
43 action='store_true') 48 action='store_true')
44 parser.add_option('-z', '--compress', help='Compress the resulting trace ' 49 parser.add_option('-z', '--compress', help='Compress the resulting trace '
45 'with gzip. ', action='store_true') 50 'with gzip. ', action='store_true')
46 parser.add_option('-t', '--time', help='Stops tracing after N seconds, 0 to ' 51 parser.add_option('-t', '--time', help='Stops tracing after N seconds, 0 to '
47 'manually stop (startup trace ends after at most 5s).', 52 'manually stop (startup trace ends after at most 5s).',
48 default=5, metavar='N', type='int') 53 default=5, metavar='N', type='int', dest='trace_time')
49 54
50 parser.add_option_group(chrome_startup_tracing_agent.add_options(parser)) 55 parser.add_option_group(chrome_startup_tracing_agent.add_options(parser))
51 parser.add_option_group(atrace_tracing_agent.add_options(parser)) 56 parser.add_option_group(atrace_tracing_agent.add_options(parser))
52 parser.add_option_group(flags.OutputOptions(parser)) 57 parser.add_option_group(flags.OutputOptions(parser))
53 58
54 return parser 59 return parser
55 60
56 61
57 def main(): 62 def main():
58 parser = _CreateOptionParser() 63 parser = _CreateOptionParser()
59 options, _ = parser.parse_args() 64 options, _ = parser.parse_args()
60 65
61 if options.verbose: 66 if options.verbose:
62 logging.getLogger().setLevel(logging.DEBUG) 67 logging.getLogger().setLevel(logging.DEBUG)
63 68
64 devices = device_utils.DeviceUtils.HealthyDevices() 69 devices = device_utils.DeviceUtils.HealthyDevices()
65 if len(devices) != 1: 70 if len(devices) != 1:
66 logging.error('Exactly 1 device must be attached.') 71 logging.error('Exactly 1 device must be attached.')
67 return 1 72 return 1
68 device = devices[0] 73 device = devices[0]
69 package_info = profiler.GetSupportedBrowsers()[options.browser] 74 package_info = profiler.GetSupportedBrowsers()[options.browser]
70 75
76 options.device = device
77 options.package_info = package_info
78
79 # TODO(washingtonp): Once Systrace uses all of the profile_chrome agents,
80 # manually setting these options will no longer be necessary and should be
81 # removed.
82 options.ring_buffer = False
83 options.trace_memory = False
84 options.chrome_categories = _DEFAULT_CHROME_CATEGORIES
85
71 if options.atrace_categories in ['list', 'help']: 86 if options.atrace_categories in ['list', 'help']:
72 ui.PrintMessage('\n'.join( 87 ui.PrintMessage('\n'.join(
73 atrace_tracing_agent.AtraceAgent.GetCategories(device))) 88 atrace_tracing_agent.AtraceAgent.GetCategories(device)))
74 return 0 89 return 0
75 atrace_categories = (options.atrace_categories.split(',')
76 if options.atrace_categories else [])
77 enabled_agents = []
78 # Enable the atrace and chrome agents. The atrace agent should go
79 # first because otherwise the resulting traces miss early atrace data.
80 if atrace_categories:
81 enabled_agents.append(atrace_tracing_agent.AtraceAgent(
82 device, atrace_categories, False))
83 enabled_agents.append(
84 chrome_startup_tracing_agent.ChromeStartupTracingAgent(
85 device, package_info, options.cold, options.url))
86 if options.output:
87 options.output = os.path.expanduser(options.output)
88 result = profiler.CaptureProfile(options, 90 result = profiler.CaptureProfile(options,
89 enabled_agents, 91 options.trace_time,
90 options.time, 92 _CHROME_STARTUP_MODULES,
91 output=options.output, 93 output=options.output_file,
92 compress=options.compress, 94 compress=options.compress,
93 write_json=options.json) 95 write_json=options.write_json)
94 if options.view: 96 if options.view:
95 if sys.platform == 'darwin': 97 if sys.platform == 'darwin':
96 os.system('/usr/bin/open %s' % os.path.abspath(result)) 98 os.system('/usr/bin/open %s' % os.path.abspath(result))
97 else: 99 else:
98 webbrowser.open(result) 100 webbrowser.open(result)
99 101
100 102
101 if __name__ == '__main__': 103 if __name__ == '__main__':
102 sys.exit(main()) 104 sys.exit(main())
OLDNEW
« no previous file with comments | « no previous file | systrace/profile_chrome/atrace_tracing_agent.py » ('j') | systrace/systrace/tracing_controller.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698