Index: tracing/tracing/results_renderer.py |
diff --git a/tracing/tracing/results_renderer.py b/tracing/tracing/results_renderer.py |
index 345d31515f409a20a458a1ed11188386ab12f756..ff953091cc15162000839e3a6b8493211dba20a0 100644 |
--- a/tracing/tracing/results_renderer.py |
+++ b/tracing/tracing/results_renderer.py |
@@ -11,27 +11,25 @@ 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>' |
-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): |
- histograms.append(json.loads(match.group(1))) |
- return histograms |
+ results.append(json.loads(match.group(1))) |
+ 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: |
@@ -48,11 +46,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): |
nednguyen
2016/11/03 21:10:24
I would split this to two different function, one
benjhayden
2016/11/09 23:48:55
Sorry, I don't see how that would work?
This funct
|
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']) |
@@ -60,10 +69,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, |