| OLD | NEW |
| 1 // Copyright (c) 2010 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 |
| 11 function TracingController() { | 11 function TracingController() { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 23 var statusDiv = document.createElement('div'); | 23 var statusDiv = document.createElement('div'); |
| 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 |
| 34 this.onKeydownBoundToThis_ = this.onKeydown_.bind(this); |
| 35 this.onKeypressBoundToThis_ = this.onKeypress_.bind(this); |
| 33 } | 36 } |
| 34 | 37 |
| 35 TracingController.prototype = { | 38 TracingController.prototype = { |
| 36 __proto__: cr.EventTarget.prototype, | 39 __proto__: cr.EventTarget.prototype, |
| 37 | 40 |
| 38 tracingEnabled_: false, | 41 tracingEnabled_: false, |
| 39 | 42 |
| 40 /** | 43 /** |
| 41 * Called by info_view to empty the trace buffer | 44 * Called by info_view to empty the trace buffer |
| 42 */ | 45 */ |
| (...skipping 13 matching lines...) Expand all Loading... |
| 56 this.tracingEnabled_ = true; | 59 this.tracingEnabled_ = true; |
| 57 | 60 |
| 58 var e = new cr.Event('traceBegun'); | 61 var e = new cr.Event('traceBegun'); |
| 59 e.events = this.traceEvents_; | 62 e.events = this.traceEvents_; |
| 60 this.dispatchEvent(e); | 63 this.dispatchEvent(e); |
| 61 | 64 |
| 62 e = new cr.Event('traceEventsChanged'); | 65 e = new cr.Event('traceEventsChanged'); |
| 63 e.numEvents = this.traceEvents_.length; | 66 e.numEvents = this.traceEvents_.length; |
| 64 this.dispatchEvent(e); | 67 this.dispatchEvent(e); |
| 65 | 68 |
| 66 var self = this; | 69 window.addEventListener('keypress', this.onKeypressBoundToThis_); |
| 67 window.addEventListener('keypress', function f(e) { | 70 window.addEventListener('keydown', this.onKeydownBoundToThis_); |
| 68 if (e.keyIdentifier == 'Enter') { | |
| 69 window.removeEventListener('keypress', f); | |
| 70 self.endTracing(); | |
| 71 } | |
| 72 }); | |
| 73 }, | 71 }, |
| 74 | 72 |
| 73 onKeydown_: function(e) { |
| 74 if (e.keyCode == 27) { |
| 75 this.endTracing(); |
| 76 } |
| 77 }, |
| 78 |
| 79 onKeypress_: function(e) { |
| 80 if (e.keyIdentifier == 'Enter') { |
| 81 this.endTracing(); |
| 82 } |
| 83 }, |
| 75 /** | 84 /** |
| 76 * Checks whether tracing is enabled | 85 * Checks whether tracing is enabled |
| 77 */ | 86 */ |
| 78 get isTracingEnabled() { | 87 get isTracingEnabled() { |
| 79 return this.tracingEnabled_; | 88 return this.tracingEnabled_; |
| 80 }, | 89 }, |
| 81 | 90 |
| 82 /** | 91 /** |
| 83 * Gets the currently traced events. If tracing is active, then | 92 * Gets the currently traced events. If tracing is active, then |
| 84 * this can change on the fly. | 93 * this can change on the fly. |
| 85 */ | 94 */ |
| 86 get traceEvents() { | 95 get traceEvents() { |
| 87 return this.traceEvents_; | 96 return this.traceEvents_; |
| 88 }, | 97 }, |
| 89 | 98 |
| 90 /** | 99 /** |
| 91 * Callbed by gpu c++ code when new GPU trace data arrives. | 100 * Callbed by gpu c++ code when new GPU trace data arrives. |
| 92 */ | 101 */ |
| 93 onTraceDataCollected: function(events) { | 102 onTraceDataCollected: function(events) { |
| 94 this.traceEvents_.push.apply(this.traceEvents_, events); | 103 this.traceEvents_.push.apply(this.traceEvents_, events); |
| 95 }, | 104 }, |
| 96 | 105 |
| 97 /** | 106 /** |
| 98 * Called by info_view to finish tracing and update all views. | 107 * Called by info_view to finish tracing and update all views. |
| 99 */ | 108 */ |
| 100 endTracing: function() { | 109 endTracing: function() { |
| 101 if (!this.tracingEnabled_) throw new Error('Tracing not begun.'); | 110 if (!this.tracingEnabled_) throw new Error('Tracing not begun.'); |
| 102 | 111 |
| 112 window.removeEventListener('keydown', this.onKeydownBoundToThis_); |
| 113 window.removeEventListener('keypress', this.onKeypressBoundToThis_); |
| 114 |
| 103 console.log('Finishing trace'); | 115 console.log('Finishing trace'); |
| 104 if (!browserBridge.debugMode) { | 116 if (!browserBridge.debugMode) { |
| 105 chrome.send('endTracingAsync'); | 117 chrome.send('endTracingAsync'); |
| 106 } else { | 118 } else { |
| 107 var events = window.getTimelineTestData1 ? | 119 var events = window.getTimelineTestData1 ? |
| 108 getTimelineTestData1() : []; | 120 getTimelineTestData1() : []; |
| 109 this.onTraceDataCollected(events); | 121 this.onTraceDataCollected(events); |
| 110 window.setTimeout(this.onEndTracingComplete.bind(this), 250); | 122 window.setTimeout(this.onEndTracingComplete.bind(this), 250); |
| 111 } | 123 } |
| 112 }, | 124 }, |
| 113 | 125 |
| 114 | 126 |
| 115 /** | 127 /** |
| 116 * Called by the browser when all processes complete tracing. | 128 * Called by the browser when all processes complete tracing. |
| 117 */ | 129 */ |
| 118 onEndTracingComplete: function() { | 130 onEndTracingComplete: function() { |
| 119 this.overlay_.visible = false; | 131 this.overlay_.visible = false; |
| 120 this.tracingEnabled_ = false; | 132 this.tracingEnabled_ = false; |
| 121 console.log('onEndTracingComplete p1 with ' + | 133 console.log('onEndTracingComplete p1 with ' + |
| 122 this.traceEvents_.length + ' events.'); | 134 this.traceEvents_.length + ' events.'); |
| 123 var e = new cr.Event('traceEnded'); | 135 var e = new cr.Event('traceEnded'); |
| 124 e.events = this.traceEvents_; | 136 e.events = this.traceEvents_; |
| 125 this.dispatchEvent(e); | 137 this.dispatchEvent(e); |
| 126 }, | 138 }, |
| 127 | 139 |
| 128 selfTest: function() { | 140 selfTest: function() { |
| 129 this.beginTracing(); | 141 this.beginTracing(); |
| 130 window.setTimeout(this.endTracing.bind(This), 500); | 142 window.setTimeout(this.endTracing.bind(This), 500); |
| 131 } | 143 } |
| 132 }; | 144 }; |
| 133 return { | 145 return { |
| 134 TracingController: TracingController | 146 TracingController: TracingController |
| 135 }; | 147 }; |
| 136 }); | 148 }); |
| 137 | 149 |
| OLD | NEW |