Beispiel #1
0
def _AggregateTraceWorker(artifacts):
  traces = [name for name in artifacts if name.startswith('trace/')]
  trace_files = [artifacts.pop(name)['filePath'] for name in traces]
  html_path = os.path.join(
      os.path.dirname(os.path.commonprefix(trace_files)),
      compute_metrics.HTML_TRACE_NAME)
  trace_data.SerializeAsHtml(trace_files, html_path)
  artifacts[compute_metrics.HTML_TRACE_NAME] = {
    'filePath': html_path,
    'contentType': 'text/html',
  }
Beispiel #2
0
def _SerializeHtmlTraceInPool(run):
    try:
        html_trace = run.GetArtifact(HTML_TRACE_NAME)
        if html_trace is None:
            trace_files = [
                art.local_path for art in run.IterArtifacts('trace')
            ]
            with run.CaptureArtifact(HTML_TRACE_NAME) as html_path:
                trace_data.SerializeAsHtml(trace_files, html_path)
    except Exception:  # pylint: disable=broad-except
        # logging exception here is the only way to get a stack trace since
        # multiprocessing's pool implementation does not save that data. See
        # crbug.com/953365.
        logging.exception('%s: Exception while aggregating traces',
                          run.story.name)
        raise
def _SerializeAndUploadHtmlTrace(run, label, bucket):
    html_trace = run.GetArtifact(HTML_TRACE_NAME)
    if html_trace is None:
        trace_files = [art.local_path for art in run.IterArtifacts('trace')]
        with run.CaptureArtifact(HTML_TRACE_NAME) as html_path:
            trace_data.SerializeAsHtml(trace_files, html_path)

    html_trace = run.GetArtifact(HTML_TRACE_NAME)
    if bucket is not None and html_trace.url is None:
        remote_name = _TraceCanonicalName(run, label)
        cloud_url = cloud_storage.Insert(bucket, remote_name,
                                         html_trace.local_path)
        sys.stderr.write(
            'View generated trace files online at %s for story %s\n' %
            (cloud_url, run.story.name))
        html_trace.SetUrl(cloud_url)

    return html_trace
Beispiel #4
0
def AggregateTBMv2Traces(test_result):
  """Replace individual non-proto traces with an aggregate HTML trace.

  For a test result with non-proto traces, generates an aggregate HTML trace.
  Removes all entries for individual traces and adds one entry for
  the aggregate one.
  """
  artifacts = test_result.get('outputArtifacts', {})
  traces = [name for name in artifacts if _IsTBMv2Trace(name)]
  if traces:
    trace_files = [artifacts[name]['filePath'] for name in traces]
    html_path = _BuildOutputPath(trace_files, compute_metrics.HTML_TRACE_NAME)
    trace_data.SerializeAsHtml(trace_files, html_path)
    artifacts[compute_metrics.HTML_TRACE_NAME] = {
      'filePath': html_path,
      'contentType': 'text/html',
    }
    logging.info('%s: TBMv2 traces aggregated. Sources: %s. Destination: %s.',
                 test_result['testPath'], trace_files, html_path)
  for name in traces:
    del artifacts[name]
Beispiel #5
0
def AggregateTraces(test_result):
    """Replace individual traces with an aggregate one for each test result.

  For a test run with traces, generates an aggregate HTML trace. Removes
  all entries for individual traces and adds one entry for aggregate one.
  """
    artifacts = test_result.get('outputArtifacts', {})
    traces = [name for name in artifacts if name.startswith('trace/')]
    # TODO(crbug.com/981349): Stop checking for HTML_TRACE_NAME after
    # Telemetry does not aggregate traces anymore.
    if traces and compute_metrics.HTML_TRACE_NAME not in artifacts:
        trace_files = [artifacts[name]['filePath'] for name in traces]
        html_path = os.path.join(
            os.path.dirname(os.path.commonprefix(trace_files)),
            compute_metrics.HTML_TRACE_NAME)
        trace_data.SerializeAsHtml(trace_files, html_path)
        artifacts[compute_metrics.HTML_TRACE_NAME] = {
            'filePath': html_path,
            'contentType': 'text/html',
        }
    for name in traces:
        del artifacts[name]