Index: tools/telemetry/telemetry/results/json_output_formatter.py |
diff --git a/tools/telemetry/telemetry/results/json_output_formatter.py b/tools/telemetry/telemetry/results/json_output_formatter.py |
index bf23ede9b8452d039c828b6e99720b65c74370b9..6517c46b6a82c2e6be41d7bd0a26044239e3d881 100644 |
--- a/tools/telemetry/telemetry/results/json_output_formatter.py |
+++ b/tools/telemetry/telemetry/results/json_output_formatter.py |
@@ -3,6 +3,7 @@ |
# found in the LICENSE file. |
import json |
+import os |
from telemetry.results import output_formatter |
@@ -15,18 +16,32 @@ def ResultsAsDict(page_test_results, benchmark_metadata): |
name). |
Args: |
- page_test_results: a PageTestResults object |
- benchmark_metadata: a benchmark.BenchmarkMetadata object |
+ page_test_results: A PageTestResults object. |
+ benchmark_metadata: A benchmark.BenchmarkMetadata object. |
""" |
result_dict = { |
'format_version': '0.2', |
'benchmark_name': benchmark_metadata.name, |
- 'summary_values': [v.AsDict() for v in |
- page_test_results.all_summary_values], |
- 'per_page_values': [v.AsDict() for v in |
- page_test_results.all_page_specific_values], |
- 'pages': {p.id: p.AsDict() for p in _GetAllPages(page_test_results)} |
+ 'pages': {p.id: p.AsDict() for p in _GetAllPages(page_test_results)}, |
} |
+ paths = page_test_results.all_paths |
+ if paths: |
+ paths_to_ids = {path: path_id for path_id, path in |
+ enumerate(page_test_results.all_paths)} |
+ ids_to_paths = {path_id: path for path, path_id |
+ in paths_to_ids.iteritems()} |
+ result_dict['paths'] = ids_to_paths |
+ result_dict['summary_values'] = ( |
+ [_UpdatePaths(v.AsDict(), paths_to_ids) |
+ for v in page_test_results.all_summary_values]) |
+ result_dict['per_page_values'] = ( |
+ [_UpdatePaths(v.AsDict(), paths_to_ids) |
+ for v in page_test_results.all_page_specific_values]) |
+ else: |
nednguyen
2014/09/08 18:45:24
You can just keep the initialization of results_di
|
+ result_dict['summary_values'] = [v.AsDict() for v in |
+ page_test_results.all_summary_values] |
+ result_dict['per_page_values'] = ( |
+ [v.AsDict() for v in page_test_results.all_page_specific_values]) |
return result_dict |
@@ -35,6 +50,31 @@ def _GetAllPages(page_test_results): |
page_test_results.all_page_runs) |
return pages |
+def _UpdatePaths(value_dict, paths_to_ids): |
+ """Takes a value dict and converts its paths to IDs. |
+ |
+ Values hold an optional list of file paths, as strings, until they need to be |
+ serialized. At serialization time, we figure out a canonical mapping of IDs |
+ to absolute paths, and correct the list for each value here. |
+ |
+ Args: |
+ value_dict: A value dict having an optional paths field. |
+ paths_to_ids: A dict mapping path strings to IDs. |
+ |
+ Returns: |
+ A value dict with a list of path IDs in the paths field. |
+ """ |
+ |
+ paths = value_dict.get('paths', None) |
+ if paths: |
+ new_dict = value_dict.copy() |
+ new_paths = [paths_to_ids[os.path.normcase(os.path.realpath(path))] |
+ for path in paths] |
+ new_dict['paths'] = new_paths |
nednguyen
2014/09/08 18:45:24
I think 'path_ids' is the right term. You can just
|
+ return new_dict |
+ else: |
+ return value_dict |
+ |
class JsonOutputFormatter(output_formatter.OutputFormatter): |
def __init__(self, output_stream, benchmark_metadata): |
super(JsonOutputFormatter, self).__init__(output_stream) |