def StopTracing(self):
        assert self.is_tracing_running, 'Can only stop tracing when tracing is on.'
        self._IssueClockSyncMarker()
        builder = self._current_state.builder

        raised_exception_messages = []
        for agent in self._active_agents_instances + [self]:
            try:
                with trace_event.trace('StopAgentTracing',
                                       agent=str(agent.__class__.__name__)):
                    agent.StopAgentTracing()
            except Exception:  # pylint: disable=broad-except
                raised_exception_messages.append(''.join(
                    traceback.format_exception(*sys.exc_info())))

        for agent in self._active_agents_instances + [self]:
            try:
                with trace_event.trace('CollectAgentTraceData',
                                       agent=str(agent.__class__.__name__)):
                    agent.CollectAgentTraceData(builder)
            except Exception:  # pylint: disable=broad-except
                raised_exception_messages.append(''.join(
                    traceback.format_exception(*sys.exc_info())))

        self._telemetry_info = None
        self._active_agents_instances = []
        self._current_state = None

        if raised_exception_messages:
            raise exceptions.TracingException(
                'Exceptions raised when trying to stop tracing:\n' +
                '\n'.join(raised_exception_messages))

        return builder.AsData()
  def FlushTracing(self, discard_current=False):
    assert self.is_tracing_running, 'Can only flush tracing when tracing is on.'
    self._IssueClockSyncMarker()

    raised_exception_messages = []

    # pylint: disable=redefined-variable-type
    # See: https://github.com/PyCQA/pylint/issues/710
    if discard_current:
      trace_builder = _TraceDataDiscarder()
    else:
      trace_builder = self._current_state.builder

    # Flushing the controller's pytrace is not supported.
    for agent in self._active_agents_instances:
      try:
        if agent.SupportsFlushingAgentTracing():
          with trace_event.trace('FlushAgentTracing',
                                 agent=str(agent.__class__.__name__)):
            with self._CollectNonfatalException('FlushAgentTracing'):
              agent.FlushAgentTracing(self._current_state.config,
                                      self._current_state.timeout,
                                      trace_builder)
      except Exception: # pylint: disable=broad-except
        raised_exception_messages.append(
            ''.join(traceback.format_exception(*sys.exc_info())))

    if raised_exception_messages:
      raise exceptions.TracingException(
          'Exceptions raised when trying to flush tracing:\n' +
          '\n'.join(raised_exception_messages))
  def StopTracing(self):
    assert self.is_tracing_running, 'Can only stop tracing when tracing is on.'
    self._IssueClockSyncMarker()
    builder = self._current_state.builder

    raised_exception_messages = []
    for agent in reversed(self._active_agents_instances):
      try:
        agent.StopAgentTracing()
      except Exception: # pylint: disable=broad-except
        raised_exception_messages.append(
            ''.join(traceback.format_exception(*sys.exc_info())))

    for agent in self._active_agents_instances:
      try:
        agent.CollectAgentTraceData(builder)
      except Exception: # pylint: disable=broad-except
        raised_exception_messages.append(
            ''.join(traceback.format_exception(*sys.exc_info())))

    self._active_agents_instances = []
    self._current_state = None

    if raised_exception_messages:
      raise exceptions.TracingException(
          'Exceptions raised when trying to stop tracing:\n' +
          '\n'.join(raised_exception_messages))

    return builder.Freeze()
Esempio n. 4
0
    def FlushTracing(self):
        assert self.is_tracing_running, 'Can only flush tracing when tracing is on.'
        self._IssueClockSyncMarker()

        raised_exception_messages = []
        # Flushing the controller's pytrace is not supported.
        for agent in self._active_agents_instances:
            try:
                if agent.SupportsFlushingAgentTracing():
                    with trace_event.trace('FlushAgentTracing',
                                           agent=str(
                                               agent.__class__.__name__)):
                        with self._CollectNonfatalException(
                                'FlushAgentTracing'):
                            agent.FlushAgentTracing(
                                self._current_state.config,
                                self._current_state.timeout,
                                self._current_state.builder)
            except Exception:  # pylint: disable=broad-except
                raised_exception_messages.append(''.join(
                    traceback.format_exception(*sys.exc_info())))

        if raised_exception_messages:
            raise exceptions.TracingException(
                'Exceptions raised when trying to flush tracing:\n' +
                '\n'.join(raised_exception_messages))
Esempio n. 5
0
  def FlushTracing(self, discard_current=False):
    assert self.is_tracing_running, 'Can only flush tracing when tracing is on.'
    self._IssueClockSyncMarker()

    raised_exception_messages = []

    # pylint: disable=redefined-variable-type
    # See: https://github.com/PyCQA/pylint/issues/710
    if discard_current:
      trace_builder = _TraceDataDiscarder()
    else:
      trace_builder = self._current_state.builder

    # The _current_state.timeout records the timeout value that was used on the
    # call to StartTracing. In practice, however, FlushTracing takes a bit
    # longer and using the same timeout lead to flakes (crbug.com/954229). Thus
    # we expand the value a bit here.
    timeout = int(self._current_state.timeout * 1.5)

    for agent in self._active_agents_instances:
      try:
        if agent.SupportsFlushingAgentTracing():
          agent.FlushAgentTracing(self._current_state.config,
                                  timeout, trace_builder)
      except Exception: # pylint: disable=broad-except
        raised_exception_messages.append(
            ''.join(traceback.format_exception(*sys.exc_info())))

    if raised_exception_messages:
      raise exceptions.TracingException(
          'Exceptions raised when trying to flush tracing:\n' +
          '\n'.join(raised_exception_messages))