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

Side by Side Diff: runtime/observatory/web/timeline.js

Issue 1722373002: Add ability to save and load timelines from Observatory (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 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 unified diff | Download patch
« no previous file with comments | « runtime/observatory/lib/src/elements/timeline_page.html ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 function onModelLoaded() { 5 function onModelLoaded() {
6 viewer.globalMode = true; 6 viewer.globalMode = true;
7 viewer.model = model; 7 viewer.model = model;
8 } 8 }
9 9
10 function clearTimeline() { 10 function clearTimeline() {
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 var requestUri = 'http://' + 98 var requestUri = 'http://' +
99 parser.hostname + 99 parser.hostname +
100 ':' + 100 ':' +
101 parser.port + 101 parser.port +
102 '/_getCpuProfileTimeline?tags=VMUser&isolateId=' + 102 '/_getCpuProfileTimeline?tags=VMUser&isolateId=' +
103 isolateId; 103 isolateId;
104 fetchUri(requestUri, fetchTimelineOnLoad, fetchTimelineOnError); 104 fetchUri(requestUri, fetchTimelineOnLoad, fetchTimelineOnError);
105 } 105 }
106 } 106 }
107 107
108 function saveTimeline() {
109 if (pendingRequests > 0) {
110 var overlay = new tr.ui.b.Overlay();
111 overlay.textContent = 'Cannot save timeline while fetching one.';
112 overlay.title = 'Save error';
113 overlay.visible = true;
114 console.log('cannot save timeline while fetching one.');
115 return;
116 }
117 if (!traceObject ||
118 !traceObject.traceEvents ||
119 (traceObject.traceEvents.length == 0)) {
120 var overlay = new tr.ui.b.Overlay();
121 overlay.textContent = 'Cannot save an empty timeline.';
122 overlay.title = 'Save error';
123 overlay.visible = true;
124 console.log('Cannot save an empty timeline.');
125 return;
126 }
127 var blob = new Blob([JSON.stringify(traceObject)],
128 {type: 'application/json'});
129 var blobUrl = URL.createObjectURL(blob);
130 var link = document.createElementNS('http://www.w3.org/1999/xhtml', 'a');
131 link.href = blobUrl;
132 var now = new Date();
133 var defaultFilename = "dart-timeline-" +
134 now.getFullYear() +
135 "-" +
136 now.getMonth() +
137 "-" +
138 now.getDate() +
139 ".json";
140 var filename = window.prompt('Save as', defaultFilename);
141 if (filename) {
142 link.download = filename;
143 link.click();
144 }
145 }
146
147 function loadTimeline() {
148 if (pendingRequests > 0) {
149 var overlay = new tr.ui.b.Overlay();
150 overlay.textContent = 'Cannot load timeline while fetching one.';
151 overlay.title = 'Save error';
152 overlay.visible = true;
153 console.log('Cannot load timeline while fetching one.');
154 return;
155 }
156 var inputElement = document.createElement('input');
157 inputElement.type = 'file';
158 inputElement.multiple = false;
159
160 var changeFired = false;
161 inputElement.addEventListener('change', function(e) {
162 if (changeFired)
163 return;
164 changeFired = true;
165
166 var file = inputElement.files[0];
167 var reader = new FileReader();
168 reader.onload = function(event) {
169 try {
170 traceObject = JSON.parse(event.target.result);
171 updateTimeline(traceObject);
172 } catch (error) {
173 tr.ui.b.Overlay.showError('Error while loading file: ' + error);
174 }
175 };
176 reader.onerror = function(event) {
177 tr.ui.b.Overlay.showError('Error while loading file: ' + event);
178 };
179 reader.onabort = function(event) {
180 tr.ui.b.Overlay.showError('Error while loading file: ' + event);
181 }
182 reader.readAsText(file);
183 });
184 inputElement.click();
185 }
186
108 function onMessage(event) { 187 function onMessage(event) {
109 var request = JSON.parse(event.data); 188 var request = JSON.parse(event.data);
110 var method = request['method']; 189 var method = request['method'];
111 var params = request['params']; 190 var params = request['params'];
112 switch (method) { 191 switch (method) {
113 case 'refresh': 192 case 'refresh':
114 fetchTimeline(params['vmAddress'], params['isolateIds']); 193 fetchTimeline(params['vmAddress'], params['isolateIds']);
115 break; 194 break;
116 case 'clear': 195 case 'clear':
117 clearTimeline(); 196 clearTimeline();
118 break; 197 break;
198 case 'save':
199 saveTimeline();
200 break;
201 case 'load':
202 loadTimeline();
203 break;
119 default: 204 default:
120 console.log('Unknown method:' + method + '.'); 205 console.log('Unknown method:' + method + '.');
121 } 206 }
122 } 207 }
123 208
124 document.addEventListener('DOMContentLoaded', function() { 209 document.addEventListener('DOMContentLoaded', function() {
125 var container = document.createElement('track-view-container'); 210 var container = document.createElement('track-view-container');
126 container.id = 'track_view_container'; 211 container.id = 'track_view_container';
127 viewer = document.createElement('tr-ui-timeline-view'); 212 viewer = document.createElement('tr-ui-timeline-view');
128 viewer.track_view_container = container; 213 viewer.track_view_container = container;
129 viewer.appendChild(container); 214 viewer.appendChild(container);
130 viewer.id = 'trace-viewer'; 215 viewer.id = 'trace-viewer';
131 viewer.globalMode = true; 216 viewer.globalMode = true;
132 document.body.appendChild(viewer); 217 document.body.appendChild(viewer);
133 registerForMessages(); 218 registerForMessages();
134 }); 219 });
135 220
136 console.log('loaded'); 221 console.log('loaded');
OLDNEW
« no previous file with comments | « runtime/observatory/lib/src/elements/timeline_page.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698