| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 | 5 |
| 6 /** | 6 /** |
| 7 * @fileoverview State and UI for trace data collection. | 7 * @fileoverview State and UI for trace data collection. |
| 8 */ | 8 */ |
| 9 cr.define('gpu', function() { | 9 cr.define('gpu', function() { |
| 10 |
| 10 function TracingController() { | 11 function TracingController() { |
| 11 this.overlay_ = $('gpu-tracing-overlay-template').cloneNode(true); | 12 this.startButton_ = document.createElement('div'); |
| 12 this.overlay_.removeAttribute('id'); | 13 this.startButton_.className = 'gpu-tracing-start-button'; |
| 14 this.startButton_.textContent = 'Start tracing'; |
| 15 this.startButton_.onclick = this.beginTracing.bind(this); |
| 16 document.body.appendChild(this.startButton_); |
| 17 |
| 18 this.overlay_ = document.createElement('div'); |
| 19 this.overlay_.className = 'gpu-tracing-overlay'; |
| 20 |
| 13 cr.ui.decorate(this.overlay_, gpu.Overlay); | 21 cr.ui.decorate(this.overlay_, gpu.Overlay); |
| 14 | 22 |
| 23 var statusDiv = document.createElement('div'); |
| 24 statusDiv.textContent = 'Tracing active.'; |
| 25 this.overlay_.appendChild(statusDiv); |
| 26 |
| 27 var stopButton = document.createElement('button'); |
| 28 stopButton.onclick = this.endTracing.bind(this); |
| 29 stopButton.innerText = 'Stop tracing'; |
| 30 this.overlay_.appendChild(stopButton); |
| 31 |
| 15 this.traceEvents_ = []; | 32 this.traceEvents_ = []; |
| 16 | |
| 17 var startButton = $('gpu-tracing-start-button-template').cloneNode(true); | |
| 18 startButton.removeAttribute('id'); | |
| 19 document.body.appendChild(startButton); | |
| 20 startButton.onclick = this.beginTracing.bind(this); | |
| 21 | |
| 22 var stopButton = this.overlay_.querySelector('.gpu-tracing-stop-button'); | |
| 23 stopButton.onclick = this.endTracing.bind(this); | |
| 24 } | 33 } |
| 25 | 34 |
| 26 TracingController.prototype = { | 35 TracingController.prototype = { |
| 27 __proto__: cr.EventTarget.prototype, | 36 __proto__: cr.EventTarget.prototype, |
| 28 | 37 |
| 29 tracingEnabled_: false, | 38 tracingEnabled_: false, |
| 30 | 39 |
| 31 /** | 40 /** |
| 32 * Called by info_view to empty the trace buffer | 41 * Called by info_view to empty the trace buffer |
| 33 */ | 42 */ |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 }, | 95 }, |
| 87 | 96 |
| 88 /** | 97 /** |
| 89 * Called by info_view to finish tracing and update all views. | 98 * Called by info_view to finish tracing and update all views. |
| 90 */ | 99 */ |
| 91 endTracing: function() { | 100 endTracing: function() { |
| 92 if (!this.tracingEnabled_) throw new Error('Tracing not begun.'); | 101 if (!this.tracingEnabled_) throw new Error('Tracing not begun.'); |
| 93 | 102 |
| 94 console.log('Finishing trace'); | 103 console.log('Finishing trace'); |
| 95 if (!browserBridge.debugMode) { | 104 if (!browserBridge.debugMode) { |
| 96 chrome.send('beginToEndTracing'); | 105 chrome.send('endTracingAsync'); |
| 97 } else { | 106 } else { |
| 98 var events = getTimelineTestData1(); | 107 var events = window.getTimelineTestData1 ? |
| 108 getTimelineTestData1() : []; |
| 99 this.onTraceDataCollected(events); | 109 this.onTraceDataCollected(events); |
| 100 window.setTimeout(this.onEndTracingComplete.bind(this), 250); | 110 window.setTimeout(this.onEndTracingComplete.bind(this), 250); |
| 101 } | 111 } |
| 102 }, | 112 }, |
| 103 | 113 |
| 114 |
| 104 /** | 115 /** |
| 105 * Called by the browser when all processes ack tracing | 116 * Called by the browser when all processes complete tracing. |
| 106 * having completed. | |
| 107 */ | 117 */ |
| 108 onEndTracingComplete: function() { | 118 onEndTracingComplete: function() { |
| 109 this.overlay_.visible = false; | 119 this.overlay_.visible = false; |
| 110 this.tracingEnabled_ = false; | 120 this.tracingEnabled_ = false; |
| 111 console.log('onEndTracingComplete p1 with ' + | 121 console.log('onEndTracingComplete p1 with ' + |
| 112 this.traceEvents_.length + ' events.'); | 122 this.traceEvents_.length + ' events.'); |
| 113 var e = new cr.Event('traceEnded'); | 123 var e = new cr.Event('traceEnded'); |
| 114 e.events = this.traceEvents_; | 124 e.events = this.traceEvents_; |
| 115 this.dispatchEvent(e); | 125 this.dispatchEvent(e); |
| 116 }, | 126 }, |
| 117 | 127 |
| 118 selfTest: function() { | 128 selfTest: function() { |
| 119 this.beginTracing(); | 129 this.beginTracing(); |
| 120 window.setTimeout(this.endTracing.bind(This), 500); | 130 window.setTimeout(this.endTracing.bind(This), 500); |
| 121 } | 131 } |
| 122 }; | 132 }; |
| 123 return { | 133 return { |
| 124 TracingController: TracingController | 134 TracingController: TracingController |
| 125 }; | 135 }; |
| 126 }); | 136 }); |
| 127 | 137 |
| OLD | NEW |