Commit c504a9b6 authored by Mikhail Khokhlov's avatar Mikhail Khokhlov Committed by Commit Bot

[tools/perf] Implement html_output result formatter

Bug: 981349
Change-Id: Ib8cfacc94bf3b65e199761646433ed8bd46bdaf9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1821898
Commit-Queue: Mikhail Khokhlov <khokhlov@google.com>
Reviewed-by: default avatarJuan Antonio Navarro Pérez <perezju@chromium.org>
Cr-Commit-Position: refs/heads/master@{#700202}
parent 369690e4
# Copyright 2019 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.
"""Output formatter for HTML Results format."""
import codecs
import os
from core.results_processor import histograms_output
from tracing_build import vulcanize_histograms_viewer
OUTPUT_FILENAME = 'results.html'
def Process(intermediate_results, options):
"""Process intermediate results and write output in output_dir."""
histogram_dicts = histograms_output.Convert(intermediate_results,
options.results_label)
output_file = os.path.join(options.output_dir, OUTPUT_FILENAME)
open(output_file, 'a').close() # Create file if it doesn't exist.
with codecs.open(output_file, mode='r+', encoding='utf-8') as output_stream:
vulcanize_histograms_viewer.VulcanizeAndRenderHistogramsViewer(
histogram_dicts, output_stream, options.reset_results)
...@@ -14,6 +14,7 @@ import os ...@@ -14,6 +14,7 @@ import os
from core.results_processor import command_line from core.results_processor import command_line
from core.results_processor import json3_output from core.results_processor import json3_output
from core.results_processor import histograms_output from core.results_processor import histograms_output
from core.results_processor import html_output
HTML_TRACE_NAME = 'trace.html' HTML_TRACE_NAME = 'trace.html'
...@@ -21,6 +22,7 @@ TELEMETRY_RESULTS = '_telemetry_results.jsonl' ...@@ -21,6 +22,7 @@ TELEMETRY_RESULTS = '_telemetry_results.jsonl'
FORMATTERS = { FORMATTERS = {
'json-test-results': json3_output, 'json-test-results': json3_output,
'histograms': histograms_output, 'histograms': histograms_output,
'html': html_output,
} }
......
...@@ -19,11 +19,13 @@ import mock ...@@ -19,11 +19,13 @@ import mock
from core.results_processor import json3_output from core.results_processor import json3_output
from core.results_processor import histograms_output from core.results_processor import histograms_output
from core.results_processor import html_output
from core.results_processor import processor from core.results_processor import processor
from core.results_processor import testing from core.results_processor import testing
from tracing.value import histogram from tracing.value import histogram
from tracing.value import histogram_set from tracing.value import histogram_set
from tracing_build import render_histograms_viewer
class ResultsProcessorIntegrationTests(unittest.TestCase): class ResultsProcessorIntegrationTests(unittest.TestCase):
...@@ -240,3 +242,115 @@ class ResultsProcessorIntegrationTests(unittest.TestCase): ...@@ -240,3 +242,115 @@ class ResultsProcessorIntegrationTests(unittest.TestCase):
diag_values = [list(v) for v in out_histograms.shared_diagnostics] diag_values = [list(v) for v in out_histograms.shared_diagnostics]
self.assertIn(['label1'], diag_values) self.assertIn(['label1'], diag_values)
self.assertIn(['label2'], diag_values) self.assertIn(['label2'], diag_values)
# TODO(crbug.com/981349): Remove this mock when html format
# is enabled in results_processor.
@mock.patch('core.results_processor.command_line.SUPPORTED_FORMATS',
['html'])
def testHtmlOutput(self):
hist_file = os.path.join(self.output_dir,
histograms_output.HISTOGRAM_DICTS_NAME)
with open(hist_file, 'w') as f:
json.dump([histogram.Histogram('a', 'unitless').AsDict()], f)
self.SerializeIntermediateResults(
test_results=[
testing.TestResult(
'benchmark/story',
artifacts={'histogram_dicts.json': testing.Artifact(hist_file)},
),
],
diagnostics={
'benchmarks': ['benchmark'],
'osNames': ['linux'],
'documentationUrls': [['documentation', 'url']],
},
start_time='2009-02-13T23:31:30.987000Z',
)
processor.main([
'--output-format', 'html',
'--output-dir', self.output_dir,
'--intermediate-dir', self.intermediate_dir,
'--results-label', 'label',
])
with open(os.path.join(
self.output_dir, html_output.OUTPUT_FILENAME)) as f:
results = render_histograms_viewer.ReadExistingResults(f.read())
out_histograms = histogram_set.HistogramSet()
out_histograms.ImportDicts(results)
self.assertEqual(len(out_histograms), 1)
self.assertEqual(out_histograms.GetFirstHistogram().name, 'a')
self.assertEqual(out_histograms.GetFirstHistogram().unit, 'unitless')
diag_values = [list(v) for v in out_histograms.shared_diagnostics]
self.assertEqual(len(diag_values), 4)
self.assertIn(['benchmark'], diag_values)
self.assertIn(['linux'], diag_values)
self.assertIn([['documentation', 'url']], diag_values)
self.assertIn(['label'], diag_values)
# TODO(crbug.com/981349): Remove this mock when html format
# is enabled in results_processor.
@mock.patch('core.results_processor.command_line.SUPPORTED_FORMATS',
['html'])
def testHtmlOutputResetResults(self):
self.SerializeIntermediateResults([])
processor.main([
'--output-format', 'html',
'--output-dir', self.output_dir,
'--intermediate-dir', self.intermediate_dir,
'--results-label', 'label1',
])
processor.main([
'--output-format', 'html',
'--output-dir', self.output_dir,
'--intermediate-dir', self.intermediate_dir,
'--results-label', 'label2',
'--reset-results',
])
with open(os.path.join(
self.output_dir, html_output.OUTPUT_FILENAME)) as f:
results = render_histograms_viewer.ReadExistingResults(f.read())
out_histograms = histogram_set.HistogramSet()
out_histograms.ImportDicts(results)
diag_values = [list(v) for v in out_histograms.shared_diagnostics]
self.assertNotIn(['label1'], diag_values)
self.assertIn(['label2'], diag_values)
# TODO(crbug.com/981349): Remove this mock when html format
# is enabled in results_processor.
@mock.patch('core.results_processor.command_line.SUPPORTED_FORMATS',
['html'])
def testHtmlOutputAppendResults(self):
self.SerializeIntermediateResults([])
processor.main([
'--output-format', 'html',
'--output-dir', self.output_dir,
'--intermediate-dir', self.intermediate_dir,
'--results-label', 'label1',
])
processor.main([
'--output-format', 'html',
'--output-dir', self.output_dir,
'--intermediate-dir', self.intermediate_dir,
'--results-label', 'label2',
])
with open(os.path.join(
self.output_dir, html_output.OUTPUT_FILENAME)) as f:
results = render_histograms_viewer.ReadExistingResults(f.read())
out_histograms = histogram_set.HistogramSet()
out_histograms.ImportDicts(results)
diag_values = [list(v) for v in out_histograms.shared_diagnostics]
self.assertIn(['label1'], diag_values)
self.assertIn(['label2'], diag_values)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment