| OLD | NEW |
| (Empty) |
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 # Use of this source code is governed by a BSD-style license that can be | |
| 3 # found in the LICENSE file. | |
| 4 | |
| 5 import collections | |
| 6 import itertools | |
| 7 | |
| 8 from telemetry.value import summary as summary_module | |
| 9 | |
| 10 def ResultsAsChartDict(benchmark_metadata, page_specific_values, | |
| 11 summary_values): | |
| 12 """Produces a dict for serialization to Chart JSON format from raw values. | |
| 13 | |
| 14 Chart JSON is a transformation of the basic Telemetry JSON format that | |
| 15 removes the page map, summarizes the raw values, and organizes the results | |
| 16 by chart and trace name. This function takes the key pieces of data needed to | |
| 17 perform this transformation (namely, lists of values and a benchmark metadata | |
| 18 object) and processes them into a dict which can be serialized using the json | |
| 19 module. | |
| 20 | |
| 21 Design doc for schema: http://goo.gl/kOtf1Y | |
| 22 | |
| 23 Args: | |
| 24 page_specific_values: list of page-specific values | |
| 25 summary_values: list of summary values | |
| 26 benchmark_metadata: a benchmark.BenchmarkMetadata object | |
| 27 | |
| 28 Returns: | |
| 29 A Chart JSON dict corresponding to the given data. | |
| 30 """ | |
| 31 summary = summary_module.Summary(page_specific_values) | |
| 32 values = itertools.chain( | |
| 33 summary.interleaved_computed_per_page_values_and_summaries, | |
| 34 summary_values) | |
| 35 charts = collections.defaultdict(dict) | |
| 36 | |
| 37 for value in values: | |
| 38 if value.page: | |
| 39 chart_name, trace_name = ( | |
| 40 value.GetChartAndTraceNameForPerPageResult()) | |
| 41 else: | |
| 42 chart_name, trace_name = ( | |
| 43 value.GetChartAndTraceNameForComputedSummaryResult(None)) | |
| 44 if chart_name == trace_name: | |
| 45 trace_name = 'summary' | |
| 46 | |
| 47 assert trace_name not in charts[chart_name] | |
| 48 | |
| 49 charts[chart_name][trace_name] = value.AsDict() | |
| 50 | |
| 51 result_dict = { | |
| 52 'format_version': '0.1', | |
| 53 'benchmark_name': benchmark_metadata.name, | |
| 54 'charts': charts | |
| 55 } | |
| 56 | |
| 57 return result_dict | |
| OLD | NEW |