Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(536)

Unified Diff: telemetry/telemetry/internal/results/html2_output_formatter.py

Issue 1964663003: [telemetry] Add Html2OutputFormatter for generating results2.html (Closed) Base URL: https://github.com/catapult-project/catapult.git@master
Patch Set: comments Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | telemetry/telemetry/internal/results/page_test_results.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: telemetry/telemetry/internal/results/html2_output_formatter.py
diff --git a/telemetry/telemetry/internal/results/html2_output_formatter.py b/telemetry/telemetry/internal/results/html2_output_formatter.py
new file mode 100644
index 0000000000000000000000000000000000000000..adf9089ff5cc29bd16140444adcf7ac89b2227ee
--- /dev/null
+++ b/telemetry/telemetry/internal/results/html2_output_formatter.py
@@ -0,0 +1,67 @@
+# Copyright 2016 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.
+
+import datetime
+import json
+import logging
+import os
+
+from catapult_base import cloud_storage
+
+from telemetry.internal.results import output_formatter
+
+import tracing_project
+
+from py_vulcanize import generate
+
+
+class Html2OutputFormatter(output_formatter.OutputFormatter):
+ def __init__(self, output_stream, reset_results, upload_results):
+ super(Html2OutputFormatter, self).__init__(output_stream)
+ self._upload_results = upload_results
+
+ # Format() needs to append to output_stream, which is easiest to do by
+ # re-opening in 'a' mode, which requires the filename instead of the file
+ # object handle, and closing the file so that it can be re-opened in
+ # Format().
+ self._output_filename = output_stream.name
+
+ # If the results should be reset or is empty, then write the prefix.
+ stat = os.stat(self._output_filename)
+ if reset_results or stat.st_size == 0:
+ output_stream.write(self._GetHtmlPrefix())
+ output_stream.close()
+
+ def _GetHtmlPrefix(self):
+ project = tracing_project.TracingProject()
+ vulcanizer = project.CreateVulcanizer()
+ modules = ['tracing.results2_template']
+ load_sequence = vulcanizer.CalcLoadSequenceForModuleNames(modules)
+ return generate.GenerateStandaloneHTMLAsString(load_sequence)
+
+ def Format(self, page_test_results):
+ with file(self._output_filename, 'a') as f:
+ f.write('\n'.join([
+ '',
+ '<script>',
+ 'values.addValueDicts(%s);' % json.dumps(page_test_results.value_set),
+ '</script>',
+ '']))
+
+ if self._upload_results:
+ file_path = os.path.abspath(self._output_stream.name)
+ file_name = 'html-results/results-%s' % datetime.datetime.now().strftime(
+ '%Y-%m-%d_%H-%M-%S')
+ try:
+ cloud_storage.Insert(cloud_storage.PUBLIC_BUCKET, file_name, file_path)
+ print
+ print ('View online at '
+ 'http://storage.googleapis.com/chromium-telemetry/%s'
+ % file_name)
+ except cloud_storage.PermissionError as e:
+ logging.error('Cannot upload profiling files to cloud storage due to '
+ ' permission error: %s' % e.message)
+ print
+ print 'View result at file://%s' % os.path.abspath(
+ self._output_stream.name)
« no previous file with comments | « no previous file | telemetry/telemetry/internal/results/page_test_results.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698