| 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('gpu', function() { | 9 cr.define('gpu', function() { |
| 10 | 10 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 statusDiv.textContent = 'Tracing active.'; | 24 statusDiv.textContent = 'Tracing active.'; |
| 25 this.overlay_.appendChild(statusDiv); | 25 this.overlay_.appendChild(statusDiv); |
| 26 | 26 |
| 27 var stopButton = document.createElement('button'); | 27 var stopButton = document.createElement('button'); |
| 28 stopButton.onclick = this.endTracing.bind(this); | 28 stopButton.onclick = this.endTracing.bind(this); |
| 29 stopButton.innerText = 'Stop tracing'; | 29 stopButton.innerText = 'Stop tracing'; |
| 30 this.overlay_.appendChild(stopButton); | 30 this.overlay_.appendChild(stopButton); |
| 31 | 31 |
| 32 this.traceEvents_ = []; | 32 this.traceEvents_ = []; |
| 33 | 33 |
| 34 if (browserBridge.debugMode) { |
| 35 var tracingControllerTests = document.createElement('script'); |
| 36 tracingControllerTests.src = |
| 37 './gpu_internals/tracing_controller_tests.js'; |
| 38 document.body.appendChild(tracingControllerTests); |
| 39 } |
| 40 |
| 34 this.onKeydownBoundToThis_ = this.onKeydown_.bind(this); | 41 this.onKeydownBoundToThis_ = this.onKeydown_.bind(this); |
| 35 this.onKeypressBoundToThis_ = this.onKeypress_.bind(this); | 42 this.onKeypressBoundToThis_ = this.onKeypress_.bind(this); |
| 36 } | 43 } |
| 37 | 44 |
| 38 TracingController.prototype = { | 45 TracingController.prototype = { |
| 39 __proto__: cr.EventTarget.prototype, | 46 __proto__: cr.EventTarget.prototype, |
| 40 | 47 |
| 41 tracingEnabled_: false, | 48 tracingEnabled_: false, |
| 42 | 49 |
| 43 /** | 50 /** |
| (...skipping 17 matching lines...) Expand all Loading... |
| 61 var e = new cr.Event('traceBegun'); | 68 var e = new cr.Event('traceBegun'); |
| 62 e.events = this.traceEvents_; | 69 e.events = this.traceEvents_; |
| 63 this.dispatchEvent(e); | 70 this.dispatchEvent(e); |
| 64 | 71 |
| 65 e = new cr.Event('traceEventsChanged'); | 72 e = new cr.Event('traceEventsChanged'); |
| 66 e.numEvents = this.traceEvents_.length; | 73 e.numEvents = this.traceEvents_.length; |
| 67 this.dispatchEvent(e); | 74 this.dispatchEvent(e); |
| 68 | 75 |
| 69 window.addEventListener('keypress', this.onKeypressBoundToThis_); | 76 window.addEventListener('keypress', this.onKeypressBoundToThis_); |
| 70 window.addEventListener('keydown', this.onKeydownBoundToThis_); | 77 window.addEventListener('keydown', this.onKeydownBoundToThis_); |
| 78 |
| 79 // In debug mode, stop tracing automatically |
| 80 if (browserBridge.debugMode) |
| 81 window.setTimeout(this.endTracing.bind(this), 100); |
| 71 }, | 82 }, |
| 72 | 83 |
| 73 onKeydown_: function(e) { | 84 onKeydown_: function(e) { |
| 74 if (e.keyCode == 27) { | 85 if (e.keyCode == 27) { |
| 75 this.endTracing(); | 86 this.endTracing(); |
| 76 } | 87 } |
| 77 }, | 88 }, |
| 78 | 89 |
| 79 onKeypress_: function(e) { | 90 onKeypress_: function(e) { |
| 80 if (e.keyIdentifier == 'Enter') { | 91 if (e.keyIdentifier == 'Enter') { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 109 endTracing: function() { | 120 endTracing: function() { |
| 110 if (!this.tracingEnabled_) throw new Error('Tracing not begun.'); | 121 if (!this.tracingEnabled_) throw new Error('Tracing not begun.'); |
| 111 | 122 |
| 112 window.removeEventListener('keydown', this.onKeydownBoundToThis_); | 123 window.removeEventListener('keydown', this.onKeydownBoundToThis_); |
| 113 window.removeEventListener('keypress', this.onKeypressBoundToThis_); | 124 window.removeEventListener('keypress', this.onKeypressBoundToThis_); |
| 114 | 125 |
| 115 console.log('Finishing trace'); | 126 console.log('Finishing trace'); |
| 116 if (!browserBridge.debugMode) { | 127 if (!browserBridge.debugMode) { |
| 117 chrome.send('endTracingAsync'); | 128 chrome.send('endTracingAsync'); |
| 118 } else { | 129 } else { |
| 119 var events = window.getTimelineTestData1 ? | 130 var events = tracingControllerTestEvents; |
| 120 getTimelineTestData1() : []; | |
| 121 this.onTraceDataCollected(events); | 131 this.onTraceDataCollected(events); |
| 122 window.setTimeout(this.onEndTracingComplete.bind(this), 250); | 132 window.setTimeout(this.onEndTracingComplete.bind(this), 250); |
| 123 } | 133 } |
| 124 }, | 134 }, |
| 125 | 135 |
| 126 | 136 |
| 127 /** | 137 /** |
| 128 * Called by the browser when all processes complete tracing. | 138 * Called by the browser when all processes complete tracing. |
| 129 */ | 139 */ |
| 130 onEndTracingComplete: function() { | 140 onEndTracingComplete: function() { |
| 131 this.overlay_.visible = false; | 141 this.overlay_.visible = false; |
| 132 this.tracingEnabled_ = false; | 142 this.tracingEnabled_ = false; |
| 133 console.log('onEndTracingComplete p1 with ' + | 143 console.log('onEndTracingComplete p1 with ' + |
| 134 this.traceEvents_.length + ' events.'); | 144 this.traceEvents_.length + ' events.'); |
| 135 var e = new cr.Event('traceEnded'); | 145 var e = new cr.Event('traceEnded'); |
| 136 e.events = this.traceEvents_; | 146 e.events = this.traceEvents_; |
| 137 this.dispatchEvent(e); | 147 this.dispatchEvent(e); |
| 138 }, | 148 }, |
| 139 | 149 |
| 140 selfTest: function() { | 150 selfTest: function() { |
| 141 this.beginTracing(); | 151 this.beginTracing(); |
| 142 window.setTimeout(this.endTracing.bind(This), 500); | 152 window.setTimeout(this.endTracing.bind(This), 500); |
| 143 } | 153 } |
| 144 }; | 154 }; |
| 145 return { | 155 return { |
| 146 TracingController: TracingController | 156 TracingController: TracingController |
| 147 }; | 157 }; |
| 148 }); | 158 }); |
| 149 | 159 |
| OLD | NEW |