Exemple #1
0
def _write_footer():
    if _format == PROTOBUF:
        if "telemetry" in _metadata:
            telemetry_info = _metadata["telemetry"]
            perfetto_trace_writer.write_metadata(
                output=_log_file,
                benchmark_start_time_us=telemetry_info["benchmarkStart"],
                story_run_time_us=telemetry_info["traceStart"],
                benchmark_name=telemetry_info["benchmarks"][0],
                benchmark_description=telemetry_info.get(
                    "benchmarkDescriptions", ["(description missing)"])[0],
                story_name=telemetry_info["stories"][0],
                story_tags=telemetry_info["storyTags"],
                story_run_index=telemetry_info["storysetRepeats"][0],
                label=telemetry_info.get("label", None),
                had_failures=telemetry_info.get("hadFailures", None),
            )
    elif _format == JSON:
        # In JSON format we might not be the only process writing to this logfile.
        # So, we will simply close the file rather than writing the trailing ] that
        # it technically requires. The trace viewer understands this and
        # will insert a trailing ] during loading.
        pass
    elif _format == JSON_WITH_METADATA:
        _log_file.write('],\n"metadata": ')
        json.dump(_metadata, _log_file)
        _log_file.write('}')
    else:
        raise TraceException("Unknown format: %s" % _format)
Exemple #2
0
 def testWriteMetadata(self):
     result = StringIO.StringIO()
     perfetto_trace_writer.write_metadata(
         output=result,
         benchmark_start_time_us=1556716807306000,
         story_run_time_us=1556716807406000,
         benchmark_name="benchmark",
         benchmark_description="description",
         story_name="story",
         story_tags=["foo", "bar"],
         story_run_index=0,
         label="label",
     )
     expected_output = (
         '\nG\x82\x03D\x08\x90\xf6\xc2\x82\xb6\xfa\xe1'
         '\x02\x10\xb0\x83\xc9\x82\xb6\xfa\xe1\x02\x1a\tbenchmark"'
         '\x0bdescription*\x05label2\x05story:\x03foo:\x03bar@\x00')
     self.assertEqual(expected_output, result.getvalue())
Exemple #3
0
def trace_add_benchmark_metadata(
    benchmark_start_time_us,
    story_run_time_us,
    benchmark_name,
    benchmark_description,
    story_name,
    story_tags,
    story_run_index,
    label=None,
):
  """ Add benchmark metadata to be written to trace file.

  Args:
    benchmark_start_time_us: Benchmark start time in microseconds.
    story_run_time_us: Story start time in microseconds.
    benchmark_name: Name of the benchmark.
    benchmark_description: Description of the benchmark.
    story_name: Name of the story.
    story_tags: List of story tags.
    story_run_index: Index of the story run.
    label: Optional label.
    had_failures: Whether this story run failed.
  """
  global _benchmark_metadata
  if _format == PROTOBUF:
    # Write metadata immediately.
    perfetto_trace_writer.write_metadata(
        output=_log_file,
        benchmark_start_time_us=benchmark_start_time_us,
        story_run_time_us=story_run_time_us,
        benchmark_name=benchmark_name,
        benchmark_description=benchmark_description,
        story_name=story_name,
        story_tags=story_tags,
        story_run_index=story_run_index,
        label=label,
    )
    perfetto_trace_writer.write_chrome_metadata(
        output=_log_file,
        clock_domain="TELEMETRY",
    )
  elif _format == JSON_WITH_METADATA:
    # Store metadata to write it in the footer.
    telemetry_metadata_for_json = {
        "benchmarkStart": benchmark_start_time_us / 1000.0,
        "traceStart": story_run_time_us / 1000.0,
        "benchmarks": [benchmark_name],
        "benchmarkDescriptions": [benchmark_description],
        "stories": [story_name],
        "storyTags": story_tags,
        "storysetRepeats": [story_run_index],
    }
    if label:
      telemetry_metadata_for_json["labels"] = [label]

    _benchmark_metadata = {
        # TODO(crbug.com/948633): For right now, we use "TELEMETRY" as the
        # clock domain to guarantee that Telemetry is given its own clock
        # domain. Telemetry isn't really a clock domain, though: it's a
        # system that USES a clock domain like LINUX_CLOCK_MONOTONIC or
        # WIN_QPC. However, there's a chance that a Telemetry controller
        # running on Linux (using LINUX_CLOCK_MONOTONIC) is interacting
        # with an Android phone (also using LINUX_CLOCK_MONOTONIC, but
        # on a different machine). The current logic collapses clock
        # domains based solely on the clock domain string, but we really
        # should to collapse based on some (device ID, clock domain ID)
        # tuple. Giving Telemetry its own clock domain is a work-around
        # for this.
        "clock-domain": "TELEMETRY",
        "telemetry": telemetry_metadata_for_json,
    }
  elif _format == JSON:
    raise TraceException("Can't write metadata in JSON format")
  else:
    raise TraceException("Unknown format: %s" % _format)