| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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('tracing', function() { | 9 cr.define('tracing', function() { |
| 10 | 10 |
| 11 function TracingController() { | 11 function TracingController() { |
| 12 this.overlay_ = document.createElement('div'); | 12 this.overlay_ = document.createElement('div'); |
| 13 this.overlay_.className = 'tracing-overlay'; | 13 this.overlay_.className = 'tracing-overlay'; |
| 14 | 14 |
| 15 cr.ui.decorate(this.overlay_, tracing.Overlay); | 15 cr.ui.decorate(this.overlay_, tracing.Overlay); |
| 16 | 16 |
| 17 this.statusDiv_ = document.createElement('div'); | 17 this.statusDiv_ = document.createElement('div'); |
| 18 this.overlay_.appendChild(this.statusDiv_); | 18 this.overlay_.appendChild(this.statusDiv_); |
| 19 | 19 |
| 20 this.bufferPercentDiv_ = document.createElement('div'); | 20 this.bufferPercentDiv_ = document.createElement('div'); |
| 21 this.overlay_.appendChild(this.bufferPercentDiv_); | 21 this.overlay_.appendChild(this.bufferPercentDiv_); |
| 22 | 22 |
| 23 this.stopButton_ = document.createElement('button'); | 23 this.stopButton_ = document.createElement('button'); |
| 24 this.stopButton_.onclick = this.endTracing.bind(this); | 24 this.stopButton_.onclick = this.endTracing.bind(this); |
| 25 this.stopButton_.textContent = 'Stop tracing'; | 25 this.stopButton_.textContent = 'Stop tracing'; |
| 26 this.overlay_.appendChild(this.stopButton_); | 26 this.overlay_.appendChild(this.stopButton_); |
| 27 | 27 |
| 28 this.traceEvents_ = []; | 28 this.traceEvents_ = []; |
| 29 | 29 |
| 30 if (browserBridge.debugMode) { | |
| 31 var tracingControllerTests = document.createElement('script'); | |
| 32 tracingControllerTests.src = | |
| 33 './tracing/tracing_controller_tests.js'; | |
| 34 document.body.appendChild(tracingControllerTests); | |
| 35 } | |
| 36 | |
| 37 this.onKeydownBoundToThis_ = this.onKeydown_.bind(this); | 30 this.onKeydownBoundToThis_ = this.onKeydown_.bind(this); |
| 38 this.onKeypressBoundToThis_ = this.onKeypress_.bind(this); | 31 this.onKeypressBoundToThis_ = this.onKeypress_.bind(this); |
| 39 | 32 |
| 40 chrome.send('tracingControllerInitialized'); | 33 chrome.send('tracingControllerInitialized'); |
| 41 } | 34 } |
| 42 | 35 |
| 43 TracingController.prototype = { | 36 TracingController.prototype = { |
| 44 __proto__: cr.EventTarget.prototype, | 37 __proto__: cr.EventTarget.prototype, |
| 45 | 38 |
| 46 gpuInfo_: undefined, | 39 gpuInfo_: undefined, |
| (...skipping 27 matching lines...) Expand all Loading... |
| 74 | 67 |
| 75 this.stopButton_.hidden = false; | 68 this.stopButton_.hidden = false; |
| 76 this.statusDiv_.textContent = 'Tracing active.'; | 69 this.statusDiv_.textContent = 'Tracing active.'; |
| 77 this.overlay_.visible = true; | 70 this.overlay_.visible = true; |
| 78 | 71 |
| 79 this.tracingEnabled_ = true; | 72 this.tracingEnabled_ = true; |
| 80 console.log('Beginning to trace...'); | 73 console.log('Beginning to trace...'); |
| 81 this.statusDiv_.textContent = 'Tracing active.'; | 74 this.statusDiv_.textContent = 'Tracing active.'; |
| 82 | 75 |
| 83 this.traceEvents_ = []; | 76 this.traceEvents_ = []; |
| 84 if (!browserBridge.debugMode) { | 77 chrome.send('beginTracing'); |
| 85 chrome.send('beginTracing'); | 78 this.beginRequestBufferPercentFull_(); |
| 86 this.beginRequestBufferPercentFull_(); | |
| 87 } else { | |
| 88 tracing.tracingControllerTestHarness.beginTracing(); | |
| 89 } | |
| 90 | 79 |
| 91 this.tracingEnabled_ = true; | 80 this.tracingEnabled_ = true; |
| 92 | 81 |
| 93 var e = new cr.Event('traceBegun'); | 82 var e = new cr.Event('traceBegun'); |
| 94 e.events = this.traceEvents_; | 83 e.events = this.traceEvents_; |
| 95 this.dispatchEvent(e); | 84 this.dispatchEvent(e); |
| 96 | 85 |
| 97 e = new cr.Event('traceEventsChanged'); | 86 e = new cr.Event('traceEventsChanged'); |
| 98 e.numEvents = this.traceEvents_.length; | 87 e.numEvents = this.traceEvents_.length; |
| 99 this.dispatchEvent(e); | 88 this.dispatchEvent(e); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 if (this.tracingEnding_) return; | 148 if (this.tracingEnding_) return; |
| 160 this.tracingEnding_ = true; | 149 this.tracingEnding_ = true; |
| 161 | 150 |
| 162 this.statusDiv_.textContent = 'Ending trace...'; | 151 this.statusDiv_.textContent = 'Ending trace...'; |
| 163 console.log('Finishing trace'); | 152 console.log('Finishing trace'); |
| 164 this.statusDiv_.textContent = 'Downloading trace data...'; | 153 this.statusDiv_.textContent = 'Downloading trace data...'; |
| 165 this.stopButton_.hidden = true; | 154 this.stopButton_.hidden = true; |
| 166 // delay sending endTracingAsync until we get a chance to | 155 // delay sending endTracingAsync until we get a chance to |
| 167 // update the screen... | 156 // update the screen... |
| 168 window.setTimeout(function() { | 157 window.setTimeout(function() { |
| 169 if (!browserBridge.debugMode) { | 158 chrome.send('endTracingAsync'); |
| 170 chrome.send('endTracingAsync'); | |
| 171 } else { | |
| 172 tracing.tracingControllerTestHarness.endTracing(); | |
| 173 } | |
| 174 }, 100); | 159 }, 100); |
| 175 }, | 160 }, |
| 176 | 161 |
| 177 /** | 162 /** |
| 178 * Called by the browser when all processes complete tracing. | 163 * Called by the browser when all processes complete tracing. |
| 179 */ | 164 */ |
| 180 onEndTracingComplete: function() { | 165 onEndTracingComplete: function() { |
| 181 window.removeEventListener('keydown', this.onKeydownBoundToThis_); | 166 window.removeEventListener('keydown', this.onKeydownBoundToThis_); |
| 182 window.removeEventListener('keypress', this.onKeypressBoundToThis_); | 167 window.removeEventListener('keypress', this.onKeypressBoundToThis_); |
| 183 this.overlay_.visible = false; | 168 this.overlay_.visible = false; |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 selfTest: function() { | 235 selfTest: function() { |
| 251 this.beginTracing(); | 236 this.beginTracing(); |
| 252 window.setTimeout(this.endTracing.bind(This), 500); | 237 window.setTimeout(this.endTracing.bind(This), 500); |
| 253 } | 238 } |
| 254 }; | 239 }; |
| 255 return { | 240 return { |
| 256 TracingController: TracingController | 241 TracingController: TracingController |
| 257 }; | 242 }; |
| 258 }); | 243 }); |
| 259 | 244 |
| OLD | NEW |