OLD | NEW |
---|---|
1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 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 optparse | 5 import optparse |
6 import os | 6 import os |
7 import py_utils | 7 import py_utils |
8 import re | 8 import re |
9 | 9 |
10 from devil.android import flag_changer | 10 from devil.android import flag_changer |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
53 extras={'create_new_tab': True}) | 53 extras={'create_new_tab': True}) |
54 self._device.StartActivity(launch_intent, blocking=True) | 54 self._device.StartActivity(launch_intent, blocking=True) |
55 | 55 |
56 def _TearDownTracing(self): | 56 def _TearDownTracing(self): |
57 self._flag_changer.Restore() | 57 self._flag_changer.Restore() |
58 | 58 |
59 @py_utils.Timeout(tracing_agents.START_STOP_TIMEOUT) | 59 @py_utils.Timeout(tracing_agents.START_STOP_TIMEOUT) |
60 def StartAgentTracing(self, config, timeout=None): | 60 def StartAgentTracing(self, config, timeout=None): |
61 self._SetupTracing() | 61 self._SetupTracing() |
62 self._logcat_monitor.Start() | 62 self._logcat_monitor.Start() |
63 return True | |
63 | 64 |
64 @py_utils.Timeout(tracing_agents.START_STOP_TIMEOUT) | 65 @py_utils.Timeout(tracing_agents.START_STOP_TIMEOUT) |
65 def StopAgentTracing(self, timeout=None): | 66 def StopAgentTracing(self, timeout=None): |
66 try: | 67 try: |
67 self._trace_file = self._logcat_monitor.WaitFor( | 68 self._trace_file = self._logcat_monitor.WaitFor( |
68 self._trace_finish_re).group(1) | 69 self._trace_finish_re).group(1) |
69 finally: | 70 finally: |
70 self._TearDownTracing() | 71 self._TearDownTracing() |
72 return True | |
71 | 73 |
72 @py_utils.Timeout(tracing_agents.GET_RESULTS_TIMEOUT) | 74 @py_utils.Timeout(tracing_agents.GET_RESULTS_TIMEOUT) |
73 def GetResults(self, timeout=None): | 75 def GetResults(self, timeout=None): |
74 with open(self._PullTrace(), 'r') as f: | 76 with open(self._PullTrace(), 'r') as f: |
75 trace_data = f.read() | 77 trace_data = f.read() |
76 return trace_result.TraceResult('traceEvents', trace_data) | 78 return trace_result.TraceResult('traceEvents', trace_data) |
77 | 79 |
78 def _PullTrace(self): | 80 def _PullTrace(self): |
79 trace_file = self._trace_file.replace('/storage/emulated/0/', '/sdcard/') | 81 trace_file = self._trace_file.replace('/storage/emulated/0/', '/sdcard/') |
80 host_file = os.path.join(os.path.curdir, os.path.basename(trace_file)) | 82 host_file = os.path.join(os.path.curdir, os.path.basename(trace_file)) |
81 self._device.PullFile(trace_file, host_file) | 83 self._device.PullFile(trace_file, host_file) |
82 return host_file | 84 return host_file |
83 | 85 |
84 def SupportsExplicitClockSync(self): | 86 def SupportsExplicitClockSync(self): |
85 return False | 87 return False |
86 | 88 |
87 def RecordClockSyncMarker(self, sync_id, did_record_sync_marker_callback): | 89 def RecordClockSyncMarker(self, sync_id, did_record_sync_marker_callback): |
90 # pylint: disable=unused-argument | |
88 assert self.SupportsExplicitClockSync(), ('Clock sync marker cannot be ' | 91 assert self.SupportsExplicitClockSync(), ('Clock sync marker cannot be ' |
89 'recorded since explicit clock sync is not supported.') | 92 'recorded since explicit clock sync is not supported.') |
90 | 93 |
91 | 94 |
92 class ChromeStartupConfig(tracing_agents.TracingConfig): | 95 class ChromeStartupConfig(tracing_agents.TracingConfig): |
93 def __init__(self): | 96 def __init__(self, device, package_info, cold, url, chrome_categories, |
97 chrome_startup): | |
94 tracing_agents.TracingConfig.__init__(self) | 98 tracing_agents.TracingConfig.__init__(self) |
99 self.device = device | |
100 self.package_info = package_info | |
101 self.cold = cold | |
102 self.url = url | |
103 self.chrome_categories = chrome_categories | |
104 self.chrome_startup = chrome_startup | |
95 | 105 |
96 | 106 |
107 def try_create_agent(config): | |
108 if config.chrome_startup: | |
109 return ChromeStartupTracingAgent(config.device, config.package_info, | |
110 config.cold, config.url) | |
111 return False | |
Sami
2016/09/01 12:15:59
I think it would be more pythonic to either return
washingtonp
2016/09/01 17:44:41
Done.
| |
112 | |
97 def add_options(parser): | 113 def add_options(parser): |
98 options = optparse.OptionGroup(parser, 'Chrome startup tracing') | 114 options = optparse.OptionGroup(parser, 'Chrome startup tracing') |
99 options.add_option('--url', help='URL to visit on startup. Default: ' | 115 options.add_option('--url', help='URL to visit on startup. Default: ' |
100 'https://www.google.com. An empty URL launches Chrome ' | 116 'https://www.google.com. An empty URL launches Chrome ' |
101 'with a MAIN action instead of VIEW.', | 117 'with a MAIN action instead of VIEW.', |
102 default='https://www.google.com', metavar='URL') | 118 default='https://www.google.com', metavar='URL') |
103 options.add_option('--cold', help='Flush the OS page cache before starting ' | 119 options.add_option('--cold', help='Flush the OS page cache before starting ' |
104 'the browser. Note that this require a device with root ' | 120 'the browser. Note that this require a device with root ' |
105 'access.', default=False, action='store_true') | 121 'access.', default=False, action='store_true') |
122 options.chrome_startup = True | |
Sami
2016/09/01 12:15:59
I wouldn't expect a function called add_options to
washingtonp
2016/09/01 17:44:41
Done.
| |
106 return options | 123 return options |
107 | 124 |
108 def get_config(options): | 125 def get_config(options): |
109 # pylint: disable=unused-argument | 126 return ChromeStartupConfig(options.device, options.package_info, |
110 return ChromeStartupConfig() | 127 options.cold, options.url, |
128 options.chrome_categories, options.chrome_startup) | |
OLD | NEW |