Index: tools/telemetry/telemetry/value/chart_json.py |
diff --git a/tools/telemetry/telemetry/value/chart_json.py b/tools/telemetry/telemetry/value/chart_json.py |
new file mode 100644 |
index 0000000000000000000000000000000000000000..9d3434df647f314c54d69554a1cc3b818ea62c8c |
--- /dev/null |
+++ b/tools/telemetry/telemetry/value/chart_json.py |
@@ -0,0 +1,94 @@ |
+# Copyright 2014 The Chromium Authors. All rights reserved. |
+# Use of this source code is governed by a BSD-style license that can be |
+# found in the LICENSE file. |
+ |
+from telemetry.value import summary as summary_module |
+ |
+def ResultsAsChartDict(page_specific_values, summary_values, metadata): |
chrishenry - DO NOT USE
2014/08/13 05:12:01
s/metadata/benchmark_metadata/ (metadata is too ge
chrishenry - DO NOT USE
2014/08/13 05:12:01
This isn't really a "value" but more a summary of
chrishenry - DO NOT USE
2014/08/13 05:12:01
Why does this take page_specific_values and summar
eakuefner
2014/08/15 22:47:31
You're right that there isn't a really clear conce
eakuefner
2014/08/15 22:47:32
We leave that up to the caller; this makes testing
eakuefner
2014/08/15 22:47:32
Done.
chrishenry
2014/08/19 17:36:21
If you need a unit test equivalent, please create
eakuefner
2014/08/21 01:11:17
Eventually we want to make Chart JSON actually a t
|
+ """Produces a dict for serialization to Chart JSON format from raw values. |
+ |
+ Chart JSON is a transformation of the basic Telemetry JSON format that |
chrishenry - DO NOT USE
2014/08/13 05:12:02
This should doc the schema as well or point to doc
eakuefner
2014/08/15 22:47:32
Done.
|
+ removes the page map, summarizes the raw values, and organizes the results |
+ by chart and trace name. This function takes the key pieces of data needed to |
+ perform this transformation (namely, lists of values and a benchmark metadata |
+ object) and processes them into a dict which can be serialized using the json |
+ module. |
+ |
+ page_specific_values: list of all values with an associated page |
+ summary_values: list of all values without an associated page |
+ metadata: a benchmark.BenchmarkMetadata object |
+ """ |
nednguyen
2014/08/13 02:17:03
Assert summary_values contains "all values without
eakuefner
2014/08/15 22:47:31
We want this invariant to be enforced higher up th
|
+# had_failures = len(page_test_results.failures) > 0 |
nduca
2014/08/13 00:55:39
funky?
eakuefner
2014/08/13 01:03:43
Will decide on failure handling best effort & fix
|
+ had_failures = False |
+ summary = summary_module.Summary(page_specific_values, had_failures) |
+ charts = {} |
+ |
+ _HandleComputedValues(summary, charts) |
+ _HandleSummaryValues(summary_values, charts) |
+ |
+ result_dict = { |
+ 'format_version': '0.1', |
+ 'test_name': metadata.name, |
+ 'charts': charts |
+ } |
+ |
+ return result_dict |
+ |
+def _HandleComputedValues(summary, charts): |
chrishenry - DO NOT USE
2014/08/13 05:12:01
Best if we can have this yield chart_name, chart_c
eakuefner
2014/08/15 22:47:32
This style matches the way we are handling results
|
+ """Organizes computed per-page and summary values into a charts dict. |
+ |
+ summary: summary.Summary object containing computed values |
+ charts: dict into which chartified values will be inserted |
+ """ |
+ |
+ for value in summary.interleaved_computed_per_page_values_and_summaries: |
+ if value.page: |
+ chart_name, trace_name = ( |
+ value.GetChartAndTraceNameForPerPageResult()) |
+ else: |
+ chart_name, trace_name = ( |
+ value.GetChartAndTraceNameForComputedSummaryResult( |
+ None)) |
chrishenry - DO NOT USE
2014/08/13 05:12:01
nit: can fit in 80-col?
eakuefner
2014/08/15 22:47:31
Done.
|
+ if chart_name == trace_name: |
+ if chart_name in charts: |
+ assert 'summary' not in charts[chart_name] |
+ trace_name = 'summary' |
+ |
+ if chart_name in charts: |
+ charts[chart_name]['traces'][trace_name] = value |
chrishenry - DO NOT USE
2014/08/13 05:12:01
A little odd, can you document this briefly? Do al
eakuefner
2014/08/15 22:47:31
Added a couple comments to attempt to explain -- t
|
+ else: |
+ charts[chart_name] = { |
+ 'traces': {trace_name: value.AsDict()} |
+ } |
+ |
+def _HandleSummaryValues(summary_values, charts): |
+ """Organizes summary values into a charts dict. |
+ |
+ While summary values can be created by a Summary object, they can also be |
+ added directly during the course of a page run. Those values are not subject |
+ to summarization and thus we handle them directly in this routine. |
+ |
+ page_test_results: a PageTestResults object containing overall values |
chrishenry - DO NOT USE
2014/08/13 05:12:01
Outdated doc.
eakuefner
2014/08/15 22:47:32
Done.
|
+ charts: dict into which chartified values will be inserted |
+ """ |
+ |
+ # If any pages failed, we want to invalidate the overall results |
+ # TODO(eakuefner): figure out how to handle this correctly |
+ had_failures = False |
+ if had_failures: |
+ return |
+ |
+ for value in summary_values: |
+ chart_name, trace_name = ( |
+ value.GetChartAndTraceNameForComputedSummaryResult( |
+ None)) |
+ if chart_name == trace_name: |
+ trace_name = 'summary' |
+ if chart_name in charts: |
+ assert trace_name not in charts[chart_name] |
+ charts[chart_name][trace_name] = value |
chrishenry - DO NOT USE
2014/08/13 05:12:01
value.AsDict()?
eakuefner
2014/08/15 22:47:32
Done.
|
+ else: |
+ charts[chart_name] = { |
+ 'units': value.units, |
+ 'traces': {trace_name: value.AsDict()} |
+ } |