def RecordUrlNavigation( cls, url, connection, chrome_metadata, additional_categories=None, timeout_seconds=devtools_monitor.DEFAULT_TIMEOUT_SECONDS): """Create a loading trace by using controller to fetch url. Args: url: (str) url to fetch. connection: An opened devtools connection. chrome_metadata: Dictionary of chrome metadata. additional_categories: ([str] or None) TracingTrack additional categories to capture. timeout_seconds: monitoring connection timeout in seconds. Returns: LoadingTrace instance. """ page = page_track.PageTrack(connection) request = request_track.RequestTrack(connection) trace = tracing.TracingTrack( connection, additional_categories=additional_categories) start_date_str = datetime.datetime.utcnow().isoformat() seconds_since_epoch=time.time() connection.MonitorUrl(url, timeout_seconds=timeout_seconds) trace = cls(url, chrome_metadata, page, request, trace) trace.metadata.update(date=start_date_str, seconds_since_epoch=seconds_since_epoch) return trace
def _EventsFromRawEvents(cls, raw_events): tracing_track = tracing.TracingTrack(None) tracing_track.Handle('Tracing.dataCollected', {'params': { 'value': raw_events }}) return tracing_track.GetEvents()
def MonitorUrl(connection, url, clear_cache=False, categories=tracing.DEFAULT_CATEGORIES, timeout=devtools_monitor.DEFAULT_TIMEOUT): """Monitor a URL via a trace recorder. Args: connection: A devtools_monitor.DevToolsConnection instance. url: url to navigate to as string. clear_cache: boolean indicating if cache should be cleared before loading. categories: List of tracing event categories to record. timeout: Websocket timeout. Returns: loading_trace.LoadingTrace. """ page = page_track.PageTrack(connection) request = request_track.RequestTrack(connection) trace = tracing.TracingTrack(connection, categories=categories) connection.SetUpMonitoring() if clear_cache: connection.ClearCache() connection.SendAndIgnoreResponse('Page.navigate', {'url': url}) connection.StartMonitoring(timeout=timeout) metadata = { 'date': datetime.datetime.utcnow().isoformat(), 'seconds_since_epoch': time.time() } return loading_trace.LoadingTrace(url, metadata, page, request, trace)
def RecordUrlNavigation( cls, url, connection, chrome_metadata, categories, timeout_seconds=devtools_monitor.DEFAULT_TIMEOUT_SECONDS, stop_delay_multiplier=0): """Create a loading trace by using controller to fetch url. Args: url: (str) url to fetch. connection: An opened devtools connection. chrome_metadata: Dictionary of chrome metadata. categories: as in tracing.TracingTrack timeout_seconds: monitoring connection timeout in seconds. stop_delay_multiplier: How long to wait after page load completed before tearing down, relative to the time it took to reach the page load to complete. Returns: LoadingTrace instance. """ page = page_track.PageTrack(connection) request = request_track.RequestTrack(connection) trace = tracing.TracingTrack(connection, categories) start_date_str = datetime.datetime.utcnow().isoformat() seconds_since_epoch = time.time() connection.MonitorUrl(url, timeout_seconds=timeout_seconds, stop_delay_multiplier=stop_delay_multiplier) trace = cls(url, chrome_metadata, page, request, trace) trace.metadata.update(date=start_date_str, seconds_since_epoch=seconds_since_epoch) return trace
def RecordUrlNavigation( cls, url, connection, chrome_metadata, categories=None, timeout_seconds=devtools_monitor.DEFAULT_TIMEOUT_SECONDS): """Create a loading trace by using controller to fetch url. Args: url: (str) url to fetch. connection: An opened devtools connection. chrome_metadata: Dictionary of chrome metadata. categories: TracingTrack categories to capture. timeout_seconds: monitoring connection timeout in seconds. Returns: LoadingTrace instance. """ page = page_track.PageTrack(connection) request = request_track.RequestTrack(connection) trace = tracing.TracingTrack( connection, categories=(tracing.DEFAULT_CATEGORIES if categories is None else categories)) connection.MonitorUrl(url, timeout_seconds=timeout_seconds) return cls(url, chrome_metadata, page, request, trace)
def _EventsFromRawEvents(cls, raw_events): tracing_track = tracing.TracingTrack( None, clovis_constants.DEFAULT_CATEGORIES) tracing_track.Handle('Tracing.dataCollected', {'params': { 'value': raw_events }}) return tracing_track.GetEvents()
def LoadingTraceFromEvents(requests, page_events=None, trace_events=None): """Returns a LoadingTrace instance from a list of requests and page events.""" request = FakeRequestTrack(requests) page_event_track = FakePageTrack(page_events if page_events else []) if trace_events: tracing_track = tracing.TracingTrack(None) tracing_track.Handle('Tracing.dataCollected', {'params': {'value': [e for e in trace_events]}}) else: tracing_track = None return loading_trace.LoadingTrace( None, None, page_event_track, request, tracing_track)
def LoadingTraceFromEvents(requests, page_events=None, trace_events=None): """Returns a LoadingTrace instance from various events.""" request = FakeRequestTrack(requests) page_event_track = FakePageTrack(page_events if page_events else []) if trace_events is not None: tracing_track = tracing.TracingTrack( None, clovis_constants.DEFAULT_CATEGORIES) tracing_track.Handle('Tracing.dataCollected', {'params': { 'value': [e for e in trace_events] }}) else: tracing_track = None return loading_trace.LoadingTrace(None, None, page_event_track, request, tracing_track)
def setUp(self): self.tracing_track = tracing.TracingTrack(None)
def setUp(self): self.tracing_track = tracing.TracingTrack( None, clovis_constants.DEFAULT_CATEGORIES)