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

Unified Diff: tools/telemetry/telemetry/components/viewer.py

Issue 169283004: Introduce telemetry.web_components and a simple component-based Results object (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added HTML output, ready for review Created 6 years, 10 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
Index: tools/telemetry/telemetry/components/viewer.py
diff --git a/tools/telemetry/telemetry/components/viewer.py b/tools/telemetry/telemetry/components/viewer.py
new file mode 100644
index 0000000000000000000000000000000000000000..9abaebeda1f5569e7ad9dd5be898e60ece486b04
--- /dev/null
+++ b/tools/telemetry/telemetry/components/viewer.py
@@ -0,0 +1,67 @@
+# Copyright (c) 2014 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.
+from telemetry.components import components_project
+from tvcm import generate
+
+class Viewer(object):
+ """An HTML-based viewer of data, built out of telemetry components.
+
+ A viewer is used to visualize complex data that is produced from a telemtry
+ benchmark. A viewer is backed by a .js file that contains a telemetry
+ component. Python-side, it knows enough to instantiate that component and pass
+ it its data. Viewers are typically written to HTML files in order to be
+ displayed.
+
+ Python-side, a viewer class can be anything, as long as it implements the
+ WriteDataToFileAsJSON. The data written here is passed to the
slamm 2014/02/19 17:10:51 WriteDataToFileAsJson
+ data_binding_property of the JS-side class specified during the viewer's
+ construction.
+
+ """
+ def __init__(self, tvcm_module_name, js_class_name, data_binding_property):
+ self._tvcm_module_name = tvcm_module_name
+ self._js_class_name = js_class_name
+ self._data_binding_property = data_binding_property
+
+ def WriteDataToFileAsJSON(self, f):
slamm 2014/02/19 17:10:51 WriteDataToFileAsJson
+ raise NotImplementedError()
+
+ def WriteViewerToFile(self, f):
+ project = components_project.ComponentsProject()
+ load_sequence = project.CalcLoadSequenceForModuleNames(
+ [self._tvcm_module_name])
+
+ bootstrap_script = generate.ExtraScript(text_content="""
tonyg 2014/02/19 16:44:32 Is this long enough to warrant moving to a .js fil
+ 'use strict';
+
+ var g_results;
+ document.addEventListener('DOMContentLoaded', function() {
+ var viewerDataScript = document.querySelector('#viewer-data');
+ var data;
+ try {
+ data = JSON.parse(viewerDataScript.textContent);
+ } catch(e) {
+ tvcm.showPanic('Could not load data', e.stack || e);
+ }
+ g_results = new %s();
+ g_results.%s = data;
+ document.body.appendChild(g_results);
+ });
+ """ % (self._js_class_name, self._data_binding_property))
+
+ class ViewerDataScript(generate.ExtraScript):
+ def __init__(self, results_component):
+ super(ViewerDataScript, self).__init__()
+ self._results_component = results_component
+
+ def WriteToFile(self, output_file):
+ output_file.write('<script id="viewer-data" type="application/json">\n')
+ self._results_component.WriteDataToFileAsJSON(output_file)
+ output_file.write('</script>\n')
+
+
+ generate.GenerateStandaloneHTMLToFile(
+ f, load_sequence,
+ title='Telemetry results',
+ extra_scripts=[bootstrap_script, ViewerDataScript(self)])

Powered by Google App Engine
This is Rietveld 408576698