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 logging | 5 import logging |
6 import socket | 6 import socket |
7 | 7 |
8 import infra_libs | 8 import infra_libs |
9 from infra_libs.event_mon.protos.chrome_infra_log_pb2 import ( | 9 from infra_libs.event_mon.protos.chrome_infra_log_pb2 import ( |
10 ChromeInfraEvent, ServiceEvent) | 10 ChromeInfraEvent, ServiceEvent) |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 _router = ev_router._TextStreamRouter() | 158 _router = ev_router._TextStreamRouter() |
159 elif run_type == 'file': | 159 elif run_type == 'file': |
160 _router = ev_router._LocalFileRouter(output_file, | 160 _router = ev_router._LocalFileRouter(output_file, |
161 dry_run=dry_run) | 161 dry_run=dry_run) |
162 else: | 162 else: |
163 _router = ev_router._HttpRouter(_cache, | 163 _router = ev_router._HttpRouter(_cache, |
164 ENDPOINTS.get(run_type), | 164 ENDPOINTS.get(run_type), |
165 dry_run=dry_run) | 165 dry_run=dry_run) |
166 | 166 |
167 | 167 |
| 168 def get_default_event(): |
| 169 """Returns a copy of the default event.""" |
| 170 |
| 171 # We return a copy here to tell people not to modify the event directly. |
| 172 ret = ChromeInfraEvent() |
| 173 ret.CopyFrom(_cache['default_event']) |
| 174 return ret |
| 175 |
| 176 |
168 def set_default_event(event): | 177 def set_default_event(event): |
169 """Change the default ChromeInfraEvent used to compute all events. | 178 """Change the default ChromeInfraEvent used to compute all events. |
170 | 179 |
171 Args: | 180 Args: |
172 event (ChromeInfraEvent): default event | 181 event (ChromeInfraEvent): default event |
173 """ | 182 """ |
174 # Here we raise an exception because failing to set the default event | 183 # Here we raise an exception because failing to set the default event |
175 # could lead to invalid data in the database. | 184 # could lead to invalid data in the database. |
176 if not isinstance(event, ChromeInfraEvent): | 185 if not isinstance(event, ChromeInfraEvent): |
177 msg = ('A ChromeInfraEvent is required as the default event. Got %s' % | 186 msg = ('A ChromeInfraEvent is required as the default event. Got %s' % |
178 type(event)) | 187 type(event)) |
179 logging.error(msg) | 188 logging.error(msg) |
180 raise TypeError(msg) | 189 raise TypeError(msg) |
181 | 190 |
182 _cache['default_event'] = event | 191 _cache['default_event'] = event |
183 | 192 |
184 | 193 |
185 def close(): | 194 def close(): |
186 """Reset the state. | 195 """Reset the state. |
187 | 196 |
188 Call this right before exiting the program. | 197 Call this right before exiting the program. |
189 | 198 |
190 Returns: | 199 Returns: |
191 success (bool): False if an error occured | 200 success (bool): False if an error occured |
192 """ | 201 """ |
193 global _router, _cache | 202 global _router, _cache |
194 _router = None | 203 _router = None |
195 _cache = {} | 204 _cache = {} |
196 return True | 205 return True |
OLD | NEW |