Chromium Code Reviews| Index: tracing/tracing/results_renderer.py |
| diff --git a/tracing/tracing/results_renderer.py b/tracing/tracing/results_renderer.py |
| index 5b3605dfc58743d76d6739b1f59a04013a0d083c..1a0dd44125efe23bc06067edd61d952cc954acd7 100644 |
| --- a/tracing/tracing/results_renderer.py |
| +++ b/tracing/tracing/results_renderer.py |
| @@ -11,31 +11,29 @@ from py_vulcanize import generate |
| # If you change this, please update "Fall-back to old formats." |
| -_JSON_TAG = '<histogram-json>%s</histogram-json>' |
| +HISTOGRAM_JSON_TAG = '<histogram-json>%s</histogram-json>' |
| +CHART_JSON_TAG = '<chart-json>%s</chart-json>' |
|
eakuefner
2016/11/18 21:37:11
let's not have this and instead have telemetry pre
|
| -def ExtractJSON(results_html, json_tag=_JSON_TAG): |
| - histograms = [] |
| + |
| +def ExtractJSON(results_html, json_tag): |
| + results = [] |
| pattern = '(.*?)'.join(re.escape(part) for part in json_tag.split('%s')) |
| flags = re.MULTILINE | re.DOTALL |
| for match in re.finditer(pattern, results_html, flags): |
| try: |
| - histograms.append(json.loads(match.group(1))) |
| + results.append(json.loads(match.group(1))) |
| except ValueError: |
| logging.warn('Found existing results json, but failed to parse it.') |
| return [] |
| - return histograms |
| + return results |
| -def ReadExistingResults(results_html): |
| - if not isinstance(results_html, basestring): |
| - results_html.seek(0) |
| - results_html = results_html.read() |
| - |
| +def ReadExistingHistograms(results_html): |
| if not results_html: |
| return [] |
| - histograms = ExtractJSON(results_html) |
| + histograms = ExtractJSON(results_html, HISTOGRAM_JSON_TAG) |
| # Fall-back to old formats. |
| if not histograms: |
| @@ -52,11 +50,22 @@ def ReadExistingResults(results_html): |
| return histograms |
| -def RenderHTMLView(histograms, output_stream, reset_results=False): |
| - if not reset_results: |
| - histograms += ReadExistingResults(output_stream) |
| +def ReadExistingChartJson(results_html): |
| + if not results_html: |
| + return [] |
| + |
| + return ExtractJSON(results_html, CHART_JSON_TAG) |
| + |
| + |
| +def RenderHTMLView(histograms, charts, output_stream, reset_results=False): |
| output_stream.seek(0) |
| + if not reset_results: |
| + results_html = output_stream.read() |
| + output_stream.seek(0) |
| + histograms += ReadExistingHistograms(results_html) |
| + charts += ReadExistingChartJson(results_html) |
| + |
| vulcanizer = tracing_project.TracingProject().CreateVulcanizer() |
| load_sequence = vulcanizer.CalcLoadSequenceForModuleNames( |
| ['tracing.results2_template']) |
| @@ -64,10 +73,17 @@ def RenderHTMLView(histograms, output_stream, reset_results=False): |
| output_stream.write(html) |
| output_stream.write('<div style="display:none;">') |
| - json_tag_newline = '\n%s' % _JSON_TAG |
| + |
| + json_tag_newline = '\n%s' % CHART_JSON_TAG |
| + for chart in charts: |
| + chart_json = json.dumps(chart, separators=(',', ':')) |
| + output_stream.write(json_tag_newline % chart_json) |
| + |
| + json_tag_newline = '\n%s' % HISTOGRAM_JSON_TAG |
| for histogram in histograms: |
| hist_json = json.dumps(histogram, separators=(',', ':')) |
| output_stream.write(json_tag_newline % hist_json) |
| + |
| output_stream.write('\n</div>\n') |
| # If the output file already existed and was longer than the new contents, |