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): |
94 tracing_agents.TracingConfig.__init__(self) | 97 tracing_agents.TracingConfig.__init__(self) |
| 98 self.device = device |
| 99 self.package_info = package_info |
| 100 self.cold = cold |
| 101 self.url = url |
| 102 self.chrome_categories = chrome_categories |
95 | 103 |
96 | 104 |
| 105 def try_create_agent(config): |
| 106 return ChromeStartupTracingAgent(config.device, config.package_info, |
| 107 config.cold, config.url) |
| 108 |
97 def add_options(parser): | 109 def add_options(parser): |
98 options = optparse.OptionGroup(parser, 'Chrome startup tracing') | 110 options = optparse.OptionGroup(parser, 'Chrome startup tracing') |
99 options.add_option('--url', help='URL to visit on startup. Default: ' | 111 options.add_option('--url', help='URL to visit on startup. Default: ' |
100 'https://www.google.com. An empty URL launches Chrome ' | 112 'https://www.google.com. An empty URL launches Chrome ' |
101 'with a MAIN action instead of VIEW.', | 113 'with a MAIN action instead of VIEW.', |
102 default='https://www.google.com', metavar='URL') | 114 default='https://www.google.com', metavar='URL') |
103 options.add_option('--cold', help='Flush the OS page cache before starting ' | 115 options.add_option('--cold', help='Flush the OS page cache before starting ' |
104 'the browser. Note that this require a device with root ' | 116 'the browser. Note that this require a device with root ' |
105 'access.', default=False, action='store_true') | 117 'access.', default=False, action='store_true') |
106 return options | 118 return options |
107 | 119 |
108 def get_config(options): | 120 def get_config(options): |
109 # pylint: disable=unused-argument | 121 return ChromeStartupConfig(options.device, options.package_info, |
110 return ChromeStartupConfig() | 122 options.cold, options.url, |
| 123 options.chrome_categories) |
OLD | NEW |