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

Unified Diff: runtime/observatory/web/timeline.js

Issue 1406413006: Timeline service protocol support with Observatory UI (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 1 month 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 | « runtime/observatory/web/timeline.html ('k') | runtime/vm/dart.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/observatory/web/timeline.js
diff --git a/runtime/observatory/web/timeline.js b/runtime/observatory/web/timeline.js
new file mode 100644
index 0000000000000000000000000000000000000000..155d010b2a42f27b216485882e80c69220215c5e
--- /dev/null
+++ b/runtime/observatory/web/timeline.js
@@ -0,0 +1,93 @@
+// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+function onModelLoaded() {
+ viewer.globalMode = true;
+ viewer.model = model;
+}
+
+function clearTimeline() {
+ viewer.model = undefined;
+}
+
+function onImportFail() {
+ var overlay = new tr.ui.b.Overlay();
+ overlay.textContent = tr.b.normalizeException(err).message;
+ overlay.title = 'Import error';
+ overlay.visible = true;
+ console.log('import failed');
+}
+
+function updateTimeline(events) {
+ model = new tr.Model();
+ var importer = new tr.importer.Import(model);
+ var p = importer.importTracesWithProgressDialog([events]);
+ p.then(onModelLoaded, onImportFail);
+}
+
+function registerForMessages() {
+ window.addEventListener("message", onMessage, false);
+}
+
+function fetchUri(uri, onLoad, onError) {
+ var xhr = new XMLHttpRequest();
+ xhr.open('GET', uri, true);
+ xhr.responseType = 'text';
+ xhr.addEventListener("load", onLoad);
+ xhr.addEventListener("error", onError);
+ xhr.send();
+ console.log('GET ' + uri);
+}
+
+function fetchTimelineOnLoad(event) {
+ var xhr = event.target;
+ var response = JSON.parse(xhr.responseText);
+ var result = response['result'];
+ var traceEvents = result['traceEvents'];
+ updateTimeline(traceEvents);
+}
+
+function fetchTimelineOnError(event) {
+}
+
+function fetchTimeline(vmAddress) {
+ var parser = document.createElement('a');
+ parser.href = vmAddress;
+ var requestUri = 'http://' +
+ parser.hostname +
+ ':' +
+ parser.port +
+ '/_getVMTimeline';
+ fetchUri(requestUri, fetchTimelineOnLoad, fetchTimelineOnError);
+}
+
+function onMessage(event) {
+ var request = JSON.parse(event.data);
+ var method = request['method'];
+ var params = request['params'];
+ switch (method) {
+ case 'refresh':
+ fetchTimeline(params['vmAddress']);
+ break;
+ case 'clear':
+ clearTimeline();
+ break;
+ default:
+ console.log('Unknown method:' + method + '.');
+ }
+}
+
+document.addEventListener('DOMContentLoaded', function() {
+ var container = document.createElement('track-view-container');
+ container.id = 'track_view_container';
+ viewer = document.createElement('tr-ui-timeline-view');
+ viewer.track_view_container = container;
+ viewer.appendChild(container);
+ viewer.id = 'trace-viewer';
+ viewer.globalMode = true;
+ document.body.appendChild(viewer);
+ registerForMessages();
+});
+
+console.log('loaded');
« no previous file with comments | « runtime/observatory/web/timeline.html ('k') | runtime/vm/dart.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698