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

Side by Side Diff: systrace/profile_chrome/profiler.py

Issue 2276263003: Pass in custom options to Systrace agents (Closed) Base URL: https://chromium.googlesource.com/external/github.com/catapult-project/catapult.git@master
Patch Set: 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 # Copyright 2014 The Chromium Authors. All rights reserved. 1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import time 5 import time
6 6
7 from devil.android.constants import chrome 7 from devil.android.constants import chrome
8 from profile_chrome import atrace_tracing_agent
9 from profile_chrome import chrome_startup_tracing_agent
8 from profile_chrome import chrome_tracing_agent 10 from profile_chrome import chrome_tracing_agent
11 from profile_chrome import ddms_tracing_agent
12 from profile_chrome import perf_tracing_agent
9 from profile_chrome import ui 13 from profile_chrome import ui
10 from profile_chrome import util 14 from profile_chrome import util
11 from systrace import output_generator 15 from systrace import output_generator
12 16
13 17
14 def _StartTracing(agents): 18 # TODO(washingtonp): This mapping is temporarily in place because
19 # profile_chrome does not currently follow Systrace's controller API. This
20 # mapping will be removed in the CL that makes profile_chrome follow the
21 # Systrace API.
22 AGENT_TYPE_TO_MODULE = {'chrome trace': chrome_tracing_agent,
23 'Browser Startup Trace': chrome_startup_tracing_agent,
24 'ddms profile': ddms_tracing_agent,
25 'perf profile': perf_tracing_agent,
26 'atrace': atrace_tracing_agent}
27
28
29 def _StartTracing(agents, options):
15 for agent in agents: 30 for agent in agents:
16 agent.StartAgentTracing(None, None) 31 if repr(agent) == 'faketrace':
Sami 2016/08/26 15:53:43 Can we avoid hardcoding faketrace here? How about
washingtonp 2016/08/26 18:50:54 Done. We cannot remove the stub for the startup ag
32 return None
33 agent.StartAgentTracing(AGENT_TYPE_TO_MODULE[repr(agent)].
34 get_config(options))
17 35
18 36
19 def _StopTracing(agents): 37 def _StopTracing(agents):
20 for agent in agents: 38 for agent in agents:
21 agent.StopAgentTracing() 39 agent.StopAgentTracing()
22 40
23 41
24 def _GetResults(agents, output, compress, write_json, interval): 42 def _GetResults(agents, output, compress, write_json, interval):
25 ui.PrintMessage('Downloading...', eol='') 43 ui.PrintMessage('Downloading...', eol='')
26 44
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 supported_browsers = { 87 supported_browsers = {
70 'stable': chrome.PACKAGE_INFO['chrome_stable'], 88 'stable': chrome.PACKAGE_INFO['chrome_stable'],
71 'beta': chrome.PACKAGE_INFO['chrome_beta'], 89 'beta': chrome.PACKAGE_INFO['chrome_beta'],
72 'dev': chrome.PACKAGE_INFO['chrome_dev'], 90 'dev': chrome.PACKAGE_INFO['chrome_dev'],
73 'build': chrome.PACKAGE_INFO['chrome'], 91 'build': chrome.PACKAGE_INFO['chrome'],
74 } 92 }
75 supported_browsers.update(chrome.PACKAGE_INFO) 93 supported_browsers.update(chrome.PACKAGE_INFO)
76 return supported_browsers 94 return supported_browsers
77 95
78 96
79 def CaptureProfile(agents, interval, output=None, compress=False, 97 def CaptureProfile(options, agents, interval, output=None, compress=False,
80 write_json=False): 98 write_json=False):
81 """Records a profiling trace saves the result to a file. 99 """Records a profiling trace saves the result to a file.
82 100
83 Args: 101 Args:
102 options: Command line options.
84 agents: List of tracing agents. 103 agents: List of tracing agents.
85 interval: Time interval to capture in seconds. An interval of None (or 0) 104 interval: Time interval to capture in seconds. An interval of None (or 0)
86 continues tracing until stopped by the user. 105 continues tracing until stopped by the user.
87 output: Output file name or None to use an automatically generated name. 106 output: Output file name or None to use an automatically generated name.
88 compress: If True, the result will be compressed either with gzip or zip 107 compress: If True, the result will be compressed either with gzip or zip
89 depending on the number of captured subtraces. 108 depending on the number of captured subtraces.
90 write_json: If True, prefer JSON output over HTML. 109 write_json: If True, prefer JSON output over HTML.
91 110
92 Returns: 111 Returns:
93 Path to saved profile. 112 Path to saved profile.
94 """ 113 """
95 trace_type = ' + '.join(map(str, agents)) 114 trace_type = ' + '.join(map(str, agents))
96 try: 115 try:
97 _StartTracing(agents) 116 _StartTracing(agents, options)
98 if interval: 117 if interval:
99 ui.PrintMessage(('Capturing %d-second %s. Press Enter to stop early...' % 118 ui.PrintMessage(('Capturing %d-second %s. Press Enter to stop early...' %
100 (interval, trace_type)), eol='') 119 (interval, trace_type)), eol='')
101 ui.WaitForEnter(interval) 120 ui.WaitForEnter(interval)
102 else: 121 else:
103 ui.PrintMessage('Capturing %s. Press Enter to stop...' % trace_type, 122 ui.PrintMessage('Capturing %s. Press Enter to stop...' % trace_type,
104 eol='') 123 eol='')
105 raw_input() 124 raw_input()
106 finally: 125 finally:
107 _StopTracing(agents) 126 _StopTracing(agents)
108 if interval: 127 if interval:
109 ui.PrintMessage('done') 128 ui.PrintMessage('done')
110 129
111 return _GetResults(agents, output, compress, write_json, interval) 130 return _GetResults(agents, output, compress, write_json, interval)
131
132 def get_config(options):
Sami 2016/08/26 15:53:43 Is this used? If not, let's remove it.
washingtonp 2016/08/26 18:50:54 Done.
133 # pylint: disable=unused-argument
134 return None
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698