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

Side by Side Diff: tools/android/loading/devtools_monitor.py

Issue 2496563002: tools: Add a tool to load pages on a device, and pull the predictor database. (Closed)
Patch Set: lint. Created 4 years, 1 month 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 (c) 2016 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2016 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 """Library handling DevTools websocket interaction. 5 """Library handling DevTools websocket interaction.
6 """ 6 """
7 7
8 import datetime 8 import datetime
9 import httplib 9 import httplib
10 import json 10 import json
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 def MonitorUrl(self, url, timeout_seconds=DEFAULT_TIMEOUT_SECONDS, 228 def MonitorUrl(self, url, timeout_seconds=DEFAULT_TIMEOUT_SECONDS,
229 stop_delay_multiplier=0): 229 stop_delay_multiplier=0):
230 """Navigate to url and dispatch monitoring loop. 230 """Navigate to url and dispatch monitoring loop.
231 231
232 Unless you have registered a listener that will call StopMonitoring, this 232 Unless you have registered a listener that will call StopMonitoring, this
233 will run until timeout from chrome. 233 will run until timeout from chrome.
234 234
235 Args: 235 Args:
236 url: (str) a URL to navigate to before starting monitoring loop. 236 url: (str) a URL to navigate to before starting monitoring loop.
237 timeout_seconds: timeout in seconds for monitoring loop. 237 timeout_seconds: timeout in seconds for monitoring loop.
238 stop_delay_multiplier: How long to wait after page load completed before 238 stop_delay_multiplier: (float) How long to wait after page load completed
239 tearing down, relative to the time it took to reach the page load to 239 before tearing down, relative to the time it took to reach the page load
240 complete. 240 to complete.
241 """ 241 """
242 for domain in self._domains_to_enable: 242 for domain in self._domains_to_enable:
243 self._ws.RegisterDomain(domain, self._OnDataReceived) 243 self._ws.RegisterDomain(domain, self._OnDataReceived)
244 if domain != self.TRACING_DOMAIN: 244 if domain != self.TRACING_DOMAIN:
245 self.SyncRequestNoResponse('%s.enable' % domain) 245 self.SyncRequestNoResponse('%s.enable' % domain)
246 # Tracing setup must be done by the tracing track to control filtering 246 # Tracing setup must be done by the tracing track to control filtering
247 # and output. 247 # and output.
248 for scoped_state in self._scoped_states: 248 for scoped_state in self._scoped_states:
249 self.SyncRequestNoResponse(scoped_state, 249 self.SyncRequestNoResponse(scoped_state,
250 self._scoped_states[scoped_state][0]) 250 self._scoped_states[scoped_state][0])
(...skipping 13 matching lines...) Expand all
264 264
265 Args: 265 Args:
266 address_delayed_stop: Whether the MonitorUrl()'s stop_delay_multiplier 266 address_delayed_stop: Whether the MonitorUrl()'s stop_delay_multiplier
267 should be addressed or not. 267 should be addressed or not.
268 """ 268 """
269 if self._stop_delay_multiplier == 0: 269 if self._stop_delay_multiplier == 0:
270 self._StopMonitoringImmediately() 270 self._StopMonitoringImmediately()
271 elif self._monitoring_stop_timestamp is None: 271 elif self._monitoring_stop_timestamp is None:
272 assert self._monitoring_start_timestamp is not None 272 assert self._monitoring_start_timestamp is not None
273 current_time = datetime.datetime.now() 273 current_time = datetime.datetime.now()
274 stop_delay_duration = self._stop_delay_multiplier * ( 274 stop_delay_duration_seconds = self._stop_delay_multiplier * (
275 current_time - self._monitoring_start_timestamp) 275 current_time - self._monitoring_start_timestamp).seconds
pasko 2016/11/14 13:21:27 was it also assuming seconds before or something m
Benoit L 2016/11/14 13:26:19 It was seconds as well, but couldn't handle non-in
276 logging.info('Delaying monitoring stop for %ds', 276 logging.info('Delaying monitoring stop for %.1fs',
277 stop_delay_duration.total_seconds()) 277 stop_delay_duration_seconds)
278 self._monitoring_stop_timestamp = current_time + stop_delay_duration 278 self._monitoring_stop_timestamp = (
279 current_time + datetime.timedelta(
280 seconds=stop_delay_duration_seconds))
279 281
280 def ExecuteJavaScript(self, expression): 282 def ExecuteJavaScript(self, expression):
281 """Run JavaScript expression. 283 """Run JavaScript expression.
282 284
283 Args: 285 Args:
284 expression: JavaScript expression to run. 286 expression: JavaScript expression to run.
285 287
286 Returns: 288 Returns:
287 The return value from the JavaScript expression. 289 The return value from the JavaScript expression.
288 """ 290 """
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 json_data: (dict) Parsed from a JSON file using the json module. 480 json_data: (dict) Parsed from a JSON file using the json module.
479 481
480 Returns: 482 Returns:
481 a Track instance. 483 a Track instance.
482 """ 484 """
483 # There is no sensible way to deserialize this abstract class, but 485 # There is no sensible way to deserialize this abstract class, but
484 # subclasses are not required to define a deserialization method. For 486 # subclasses are not required to define a deserialization method. For
485 # example, for testing we have a FakeRequestTrack which is never 487 # example, for testing we have a FakeRequestTrack which is never
486 # deserialized; instead fake instances are deserialized as RequestTracks. 488 # deserialized; instead fake instances are deserialized as RequestTracks.
487 assert False 489 assert False
OLDNEW
« no previous file with comments | « tools/android/loading/controller.py ('k') | tools/resource_prefetch_predictor/generate_database.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698