OLD | NEW |
(Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 function onModelLoaded() { |
| 6 viewer.globalMode = true; |
| 7 viewer.model = model; |
| 8 } |
| 9 |
| 10 function clearTimeline() { |
| 11 viewer.model = undefined; |
| 12 } |
| 13 |
| 14 function onImportFail() { |
| 15 var overlay = new tr.ui.b.Overlay(); |
| 16 overlay.textContent = tr.b.normalizeException(err).message; |
| 17 overlay.title = 'Import error'; |
| 18 overlay.visible = true; |
| 19 console.log('import failed'); |
| 20 } |
| 21 |
| 22 function updateTimeline(events) { |
| 23 model = new tr.Model(); |
| 24 var importer = new tr.importer.Import(model); |
| 25 var p = importer.importTracesWithProgressDialog([events]); |
| 26 p.then(onModelLoaded, onImportFail); |
| 27 } |
| 28 |
| 29 function registerForMessages() { |
| 30 window.addEventListener("message", onMessage, false); |
| 31 } |
| 32 |
| 33 function fetchUri(uri, onLoad, onError) { |
| 34 var xhr = new XMLHttpRequest(); |
| 35 xhr.open('GET', uri, true); |
| 36 xhr.responseType = 'text'; |
| 37 xhr.addEventListener("load", onLoad); |
| 38 xhr.addEventListener("error", onError); |
| 39 xhr.send(); |
| 40 console.log('GET ' + uri); |
| 41 } |
| 42 |
| 43 function fetchTimelineOnLoad(event) { |
| 44 var xhr = event.target; |
| 45 var response = JSON.parse(xhr.responseText); |
| 46 var result = response['result']; |
| 47 var traceEvents = result['traceEvents']; |
| 48 updateTimeline(traceEvents); |
| 49 } |
| 50 |
| 51 function fetchTimelineOnError(event) { |
| 52 } |
| 53 |
| 54 function fetchTimeline(vmAddress) { |
| 55 var parser = document.createElement('a'); |
| 56 parser.href = vmAddress; |
| 57 var requestUri = 'http://' + |
| 58 parser.hostname + |
| 59 ':' + |
| 60 parser.port + |
| 61 '/_getVMTimeline'; |
| 62 fetchUri(requestUri, fetchTimelineOnLoad, fetchTimelineOnError); |
| 63 } |
| 64 |
| 65 function onMessage(event) { |
| 66 var request = JSON.parse(event.data); |
| 67 var method = request['method']; |
| 68 var params = request['params']; |
| 69 switch (method) { |
| 70 case 'refresh': |
| 71 fetchTimeline(params['vmAddress']); |
| 72 break; |
| 73 case 'clear': |
| 74 clearTimeline(); |
| 75 break; |
| 76 default: |
| 77 console.log('Unknown method:' + method + '.'); |
| 78 } |
| 79 } |
| 80 |
| 81 document.addEventListener('DOMContentLoaded', function() { |
| 82 var container = document.createElement('track-view-container'); |
| 83 container.id = 'track_view_container'; |
| 84 viewer = document.createElement('tr-ui-timeline-view'); |
| 85 viewer.track_view_container = container; |
| 86 viewer.appendChild(container); |
| 87 viewer.id = 'trace-viewer'; |
| 88 viewer.globalMode = true; |
| 89 document.body.appendChild(viewer); |
| 90 registerForMessages(); |
| 91 }); |
| 92 |
| 93 console.log('loaded'); |
OLD | NEW |