Example #1
0
    def testIsSupportWithoutStartupTracingSupport(self):
        self.assertFalse(
            chrome_tracing_agent.ChromeTracingAgent.IsSupported(
                self.platform1))
        self.assertFalse(
            chrome_tracing_agent.ChromeTracingAgent.IsSupported(
                self.platform2))
        self.assertFalse(
            chrome_tracing_agent.ChromeTracingAgent.IsSupported(
                self.platform3))

        devtool1 = FakeDevtoolsClient(1)
        devtool2 = FakeDevtoolsClient(2)
        chrome_tracing_devtools_manager.RegisterDevToolsClient(
            devtool1, self.platform1)
        chrome_tracing_devtools_manager.RegisterDevToolsClient(
            devtool2, self.platform2)
        devtool2.is_alive = False

        # Chrome tracing is only supported on platform 1 since only platform 1 has
        # an alive devtool.
        self.assertTrue(
            chrome_tracing_agent.ChromeTracingAgent.IsSupported(
                self.platform1))
        self.assertFalse(
            chrome_tracing_agent.ChromeTracingAgent.IsSupported(
                self.platform2))
        self.assertFalse(
            chrome_tracing_agent.ChromeTracingAgent.IsSupported(
                self.platform3))
Example #2
0
  def testExceptionRaisedInStartTracing(self):
    devtool1 = FakeDevtoolsClient(1, self.platform1)
    devtool2 = FakeDevtoolsClient(2, self.platform1)
    # Register devtools 1, 2 on platform 1
    chrome_tracing_devtools_manager.RegisterDevToolsClient(devtool1)
    chrome_tracing_devtools_manager.RegisterDevToolsClient(devtool2)

    with self.assertRaises(chrome_tracing_agent.ChromeTracingStartedError):
      self.StartTracing(self.platform1, throw_exception=True)

    # Tracing is stopped on both devtools clients even if there is exception.
    self.assertFalse(devtool1.is_tracing_running)
    self.assertFalse(devtool2.is_tracing_running)

    devtool1.is_alive = False
    devtool2.is_alive = False
    # Register devtools 3 on platform 1 should not raise any exception.
    devtool3 = FakeDevtoolsClient(3, self.platform1)
    chrome_tracing_devtools_manager.RegisterDevToolsClient(devtool3)

    # Start & Stop tracing on platform 1 should work just fine.
    tracing_agent2 = self.StartTracing(self.platform1)
    self.assertTrue(devtool3.is_tracing_running)
    self.assertIsNotNone(tracing_agent2.trace_config)

    self.StopTracing(tracing_agent2)
    self.assertIsNone(tracing_agent2.trace_config)
    self.assertFalse(devtool3.is_tracing_running)
Example #3
0
    def testFlushTracing(self):
        devtool1 = FakeDevtoolsClient(1)
        devtool2 = FakeDevtoolsClient(2)
        devtool3 = FakeDevtoolsClient(3)
        devtool4 = FakeDevtoolsClient(2)

        # Register devtools 1, 2, 3 on platform1 and devtool 4 on platform 2.
        chrome_tracing_devtools_manager.RegisterDevToolsClient(
            devtool1, self.platform1)
        chrome_tracing_devtools_manager.RegisterDevToolsClient(
            devtool2, self.platform1)
        chrome_tracing_devtools_manager.RegisterDevToolsClient(
            devtool3, self.platform1)
        chrome_tracing_devtools_manager.RegisterDevToolsClient(
            devtool4, self.platform2)
        devtool2.is_alive = False

        tracing_agent1 = self.StartTracing(self.platform1)

        self.assertTrue(devtool1.is_tracing_running)
        self.assertFalse(devtool2.is_tracing_running)
        self.assertTrue(devtool3.is_tracing_running)
        # Devtool 4 shouldn't have tracing started although it has the same remote
        # port as devtool 2.
        self.assertFalse(devtool4.is_tracing_running)

        for _ in xrange(5):
            self.FlushTracing(tracing_agent1)
            self.assertTrue(devtool1.is_tracing_running)
            self.assertFalse(devtool2.is_tracing_running)
            self.assertTrue(devtool3.is_tracing_running)
            self.assertFalse(devtool4.is_tracing_running)

        self.StopTracing(tracing_agent1)
        self.assertFalse(devtool1.is_tracing_running)
        self.assertFalse(devtool2.is_tracing_running)
        self.assertFalse(devtool3.is_tracing_running)
        self.assertFalse(devtool4.is_tracing_running)

        # Test that it is ok to start, flush & stop tracing on platform1 again.
        tracing_agent1 = self.StartTracing(self.platform1)
        self.FlushTracing(tracing_agent1)
        self.StopTracing(tracing_agent1)

        tracing_agent2 = self.StartTracing(self.platform2)
        self.assertTrue(devtool4.is_tracing_running)
        self.FlushTracing(tracing_agent2)
        self.assertTrue(devtool4.is_tracing_running)
        self.StopTracing(tracing_agent2)
        self.assertFalse(devtool4.is_tracing_running)
Example #4
0
  def testStartAndStopTracing(self):
    devtool1 = FakeDevtoolsClient(1)
    devtool2 = FakeDevtoolsClient(2)
    devtool3 = FakeDevtoolsClient(3)
    devtool4 = FakeDevtoolsClient(2)
    # Register devtools 1, 2, 3 on platform1 and devtool 4 on platform 2
    chrome_tracing_devtools_manager.RegisterDevToolsClient(
        devtool1, self.platform1)
    chrome_tracing_devtools_manager.RegisterDevToolsClient(
        devtool2, self.platform1)
    chrome_tracing_devtools_manager.RegisterDevToolsClient(
        devtool3, self.platform1)
    chrome_tracing_devtools_manager.RegisterDevToolsClient(
        devtool4, self.platform2)
    devtool2.is_alive = False

    tracing_agent1 = self.StartTracing(self.platform1)
    with self.assertRaises(chrome_tracing_agent.ChromeTracingStartedError):
      self.StartTracing(self.platform1)

    self.assertTrue(devtool1.is_tracing_running)
    self.assertFalse(devtool2.is_tracing_running)
    self.assertTrue(devtool3.is_tracing_running)
    # Devtool 4 shouldn't have tracing started although it has the same remote
    # port as devtool 2
    self.assertFalse(devtool4.is_tracing_running)


    self.assertFalse(devtool1.collected)
    self.StopTracing(tracing_agent1)
    self.assertTrue(devtool1.collected)
    self.assertFalse(devtool1.is_tracing_running)
    self.assertFalse(devtool2.is_tracing_running)
    self.assertFalse(devtool3.is_tracing_running)
    self.assertFalse(devtool4.is_tracing_running)

    # Test that it should be ok to start & stop tracing on platform1 again.
    tracing_agent1 = self.StartTracing(self.platform1)
    self.StopTracing(tracing_agent1)

    tracing_agent2 = self.StartTracing(self.platform2)
    self.assertTrue(devtool4.is_tracing_running)
    self.assertFalse(devtool4.collected)
    self.StopTracing(tracing_agent2)
    self.assertFalse(devtool4.is_tracing_running)
    self.assertTrue(devtool4.collected)
Example #5
0
  def testIsSupportOnDesktopPlatform(self):
    # Chrome tracing is always supported on desktop platforms because of startup
    # tracing.
    desktop_platform = FakeDesktopPlatformBackend()
    self.assertTrue(
        chrome_tracing_agent.ChromeTracingAgent.IsSupported(desktop_platform))

    devtool = FakeDevtoolsClient(1)
    chrome_tracing_devtools_manager.RegisterDevToolsClient(
        devtool, desktop_platform)
    self.assertTrue(
        chrome_tracing_agent.ChromeTracingAgent.IsSupported(desktop_platform))
Example #6
0
  def testExceptionRaisedInClockSync(self):
    devtool1 = FakeDevtoolsClient(1, self.platform1)
    # Register devtools 1 on platform 1
    chrome_tracing_devtools_manager.RegisterDevToolsClient(devtool1)
    tracing_agent1 = self.StartTracing(self.platform1)

    self.assertTrue(devtool1.is_tracing_running)

    devtool1.will_raise_exception_in_clock_sync = True
    with self.assertRaises(chrome_tracing_agent.ChromeClockSyncError):
      self.StopTracing(tracing_agent1)

    devtool1.is_alive = False
    # Register devtools 2 on platform 1 should not raise any exception.
    devtool2 = FakeDevtoolsClient(2, self.platform1)
    chrome_tracing_devtools_manager.RegisterDevToolsClient(devtool2)

    # Start & Stop tracing on platform 1 should work just fine.
    tracing_agent2 = self.StartTracing(self.platform1)
    self.StopTracing(tracing_agent2)
    self.assertIsNone(tracing_agent2.trace_config)
    self.assertFalse(devtool2.is_tracing_running)
Example #7
0
    def __init__(self, devtools_port, browser_target, remote_devtools_port,
                 app_backend):
        """Creates a new DevToolsClientBackend.

    A DevTools agent must exist on the given devtools_port.

    Args:
      devtools_port: The port to use to connect to DevTools agent.
      remote_devtools_port: In some cases (e.g., app running on
          Android device, devtools_port is the forwarded port on the
          host platform. We also need to know the remote_devtools_port
          so that we can uniquely identify the DevTools agent.
      app_backend: For the app that contains the DevTools agent.
    """
        self._devtools_port = devtools_port
        self._browser_target = browser_target or '/devtools/browser'
        self._remote_devtools_port = remote_devtools_port
        self._devtools_http = devtools_http.DevToolsHttp(devtools_port)
        self._browser_inspector_websocket = None
        self._tracing_backend = None
        self._memory_backend = None
        self._system_info_backend = None
        self._app_backend = app_backend
        self._wm_backend = None
        self._devtools_context_map_backend = _DevToolsContextMapBackend(
            self._app_backend, self)

        self._tab_ids = None

        if not self.supports_tracing:
            return
        chrome_tracing_devtools_manager.RegisterDevToolsClient(
            self, self._app_backend.platform_backend)

        # Telemetry has started Chrome tracing if there is trace config, so start
        # tracing on this newly created devtools client if needed.
        trace_config = (self._app_backend.platform_backend.
                        tracing_controller_backend.GetChromeTraceConfig())
        if not trace_config:
            self._CreateTracingBackendIfNeeded(is_tracing_running=False)
            return

        if self.support_startup_tracing:
            self._CreateTracingBackendIfNeeded(is_tracing_running=True)
            return

        self._CreateTracingBackendIfNeeded(is_tracing_running=False)
        self.StartChromeTracing(trace_config)
Example #8
0
    def _Connect(self, devtools_port, browser_target):
        """Attempt to connect to the DevTools client.

    Args:
      devtools_port: The devtools_port uniquely identifies the DevTools agent.
      browser_target: An optional string to override the default path used to
        establish a websocket connection with the browser inspector.

    Raises:
      Any of _DEVTOOLS_CONNECTION_ERRORS if failed to establish the connection.
    """
        self._browser_target = browser_target or '/devtools/browser'
        self._forwarder = self.platform_backend.forwarder_factory.Create(
            local_port=None,  # Forwarder will choose an available port.
            remote_port=devtools_port,
            reverse=True)
        self._local_port = self._forwarder._local_port
        self._remote_port = self._forwarder._remote_port

        self._devtools_http = devtools_http.DevToolsHttp(self.local_port)
        # If the agent is not alive and ready, trying to get the branch number will
        # raise a devtools_http.DevToolsClientConnectionError.
        branch_number = self.GetChromeBranchNumber()
        if branch_number < MIN_SUPPORTED_BRANCH_NUMBER:
            raise UnsupportedVersionError(
                'Chrome branch number %d is no longer supported' %
                branch_number)

        # Ensure that the inspector websocket is ready. This may raise a
        # inspector_websocket.WebSocketException or socket.error if not ready.
        self._browser_websocket = inspector_websocket.InspectorWebsocket()
        self._browser_websocket.Connect(self.browser_target_url, timeout=10)

        chrome_tracing_devtools_manager.RegisterDevToolsClient(self)

        # If there is a trace_config it means that Telemetry has already started
        # Chrome tracing via a startup config. The TracingBackend also needs needs
        # this config to initialize itself correctly.
        trace_config = (self.platform_backend.tracing_controller_backend.
                        GetChromeTraceConfig())
        self._tracing_backend = tracing_backend.TracingBackend(
            self._browser_websocket, trace_config)
    def __init__(self, devtools_config):
        """Creates a new DevToolsClientBackend.

    Clients should consider using DevToolsClientConfig.WaitForAndCreate rather
    than directly instantiating this class.

    Args:
      devtools_config: A DevToolsClientConfig instance.
    """
        self._devtools_config = devtools_config
        self._browser_inspector_websocket = None
        self._tracing_backend = None
        self._memory_backend = None
        self._system_info_backend = None
        self._wm_backend = None
        self._tab_ids = None

        self._devtools_http = devtools_http.DevToolsHttp(
            self._devtools_config.local_port)
        self._devtools_context_map_backend = _DevToolsContextMapBackend(
            self._devtools_config.app_backend, self)

        if not self.supports_tracing:
            return

        chrome_tracing_devtools_manager.RegisterDevToolsClient(
            self, self._devtools_config.app_backend.platform_backend)

        # Telemetry has started Chrome tracing if there is trace config, so start
        # tracing on this newly created devtools client if needed.
        trace_config = (self._devtools_config.app_backend.platform_backend.
                        tracing_controller_backend.GetChromeTraceConfig())
        if not trace_config:
            self._CreateTracingBackendIfNeeded(is_tracing_running=False)
            return

        if self.support_startup_tracing:
            self._CreateTracingBackendIfNeeded(is_tracing_running=True)
            return

        self._CreateTracingBackendIfNeeded(is_tracing_running=False)
        self.StartChromeTracing(trace_config)
Example #10
0
  def testRegisterDevtoolsClient(self):
    chrome_tracing_devtools_manager.RegisterDevToolsClient(
        FakeDevtoolsClient(1, self.platform1))
    chrome_tracing_devtools_manager.RegisterDevToolsClient(
        FakeDevtoolsClient(2, self.platform1))
    chrome_tracing_devtools_manager.RegisterDevToolsClient(
        FakeDevtoolsClient(3, self.platform1))

    tracing_agent_of_platform1 = self.StartTracing(self.platform1)

    chrome_tracing_devtools_manager.RegisterDevToolsClient(
        FakeDevtoolsClient(4, self.platform1))
    chrome_tracing_devtools_manager.RegisterDevToolsClient(
        FakeDevtoolsClient(5, self.platform2))

    self.StopTracing(tracing_agent_of_platform1)
    chrome_tracing_devtools_manager.RegisterDevToolsClient(
        FakeDevtoolsClient(6, self.platform1))
Example #11
0
    def testRegisterDevtoolsClient(self):
        chrome_tracing_devtools_manager.RegisterDevToolsClient(
            FakeDevtoolsClient(1), self.platform1)
        chrome_tracing_devtools_manager.RegisterDevToolsClient(
            FakeDevtoolsClient(2), self.platform1)
        chrome_tracing_devtools_manager.RegisterDevToolsClient(
            FakeDevtoolsClient(3), self.platform1)

        tracing_agent_of_platform1 = self.StartTracing(self.platform1)

        chrome_tracing_devtools_manager.RegisterDevToolsClient(
            FakeDevtoolsClient(4), self.platform1)
        chrome_tracing_devtools_manager.RegisterDevToolsClient(
            FakeDevtoolsClient(5), self.platform2)

        self.StopTracing(tracing_agent_of_platform1)
        chrome_tracing_devtools_manager.RegisterDevToolsClient(
            FakeDevtoolsClient(6), self.platform1)
  def _Connect(self, devtools_port, browser_target):
    """Attempt to connect to the DevTools client.

    Args:
      devtools_port: The devtools_port uniquely identifies the DevTools agent.
      browser_target: An optional string to override the default path used to
        establish a websocket connection with the browser inspector.

    Raises:
      Any of _DEVTOOLS_CONNECTION_ERRORS if failed to establish the connection.
    """
    self._browser_target = browser_target or '/devtools/browser'
    self._forwarder = self.platform_backend.forwarder_factory.Create(
        local_port=None,  # Forwarder will choose an available port.
        remote_port=devtools_port, reverse=True)
    self._local_port = self._forwarder._local_port
    self._remote_port = self._forwarder._remote_port

    self._devtools_http = devtools_http.DevToolsHttp(self.local_port)
    # If the agent is not alive and ready, this will raise a
    # devtools_http.DevToolsClientConnectionError.
    self.GetVersion()

    # Ensure that the inspector websocket is ready. This may raise a
    # inspector_websocket.WebSocketException or socket.error if not ready.
    self._browser_websocket = inspector_websocket.InspectorWebsocket()
    self._browser_websocket.Connect(self.browser_target_url, timeout=10)

    chrome_tracing_devtools_manager.RegisterDevToolsClient(self)

    # Telemetry has started Chrome tracing if there is a trace config, we use
    # this info to create the TracingBackend in the correct state.
    is_tracing_running = bool(
        self.platform_backend.tracing_controller_backend.GetChromeTraceConfig())
    self._tracing_backend = tracing_backend.TracingBackend(
        self._browser_websocket, is_tracing_running)