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('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 = 'gpu-tracing-overlay'; | 13 this.overlay_.className = 'tracing-overlay'; |
14 | 14 |
15 cr.ui.decorate(this.overlay_, gpu.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) { | 30 if (browserBridge.debugMode) { |
31 var tracingControllerTests = document.createElement('script'); | 31 var tracingControllerTests = document.createElement('script'); |
32 tracingControllerTests.src = | 32 tracingControllerTests.src = |
33 './gpu_internals/tracing_controller_tests.js'; | 33 './tracing/tracing_controller_tests.js'; |
34 document.body.appendChild(tracingControllerTests); | 34 document.body.appendChild(tracingControllerTests); |
35 } | 35 } |
36 | 36 |
37 this.onKeydownBoundToThis_ = this.onKeydown_.bind(this); | 37 this.onKeydownBoundToThis_ = this.onKeydown_.bind(this); |
38 this.onKeypressBoundToThis_ = this.onKeypress_.bind(this); | 38 this.onKeypressBoundToThis_ = this.onKeypress_.bind(this); |
39 } | 39 } |
40 | 40 |
41 TracingController.prototype = { | 41 TracingController.prototype = { |
42 __proto__: cr.EventTarget.prototype, | 42 __proto__: cr.EventTarget.prototype, |
43 | 43 |
(...skipping 30 matching lines...) Expand all Loading... |
74 | 74 |
75 this.tracingEnabled_ = true; | 75 this.tracingEnabled_ = true; |
76 console.log('Beginning to trace...'); | 76 console.log('Beginning to trace...'); |
77 this.statusDiv_.textContent = 'Tracing active.'; | 77 this.statusDiv_.textContent = 'Tracing active.'; |
78 | 78 |
79 this.traceEvents_ = []; | 79 this.traceEvents_ = []; |
80 if (!browserBridge.debugMode) { | 80 if (!browserBridge.debugMode) { |
81 chrome.send('beginTracing'); | 81 chrome.send('beginTracing'); |
82 this.beginRequestBufferPercentFull_(); | 82 this.beginRequestBufferPercentFull_(); |
83 } else { | 83 } else { |
84 gpu.tracingControllerTestHarness.beginTracing(); | 84 tracing.tracingControllerTestHarness.beginTracing(); |
85 } | 85 } |
86 | 86 |
87 this.tracingEnabled_ = true; | 87 this.tracingEnabled_ = true; |
88 | 88 |
89 var e = new cr.Event('traceBegun'); | 89 var e = new cr.Event('traceBegun'); |
90 e.events = this.traceEvents_; | 90 e.events = this.traceEvents_; |
91 this.dispatchEvent(e); | 91 this.dispatchEvent(e); |
92 | 92 |
93 e = new cr.Event('traceEventsChanged'); | 93 e = new cr.Event('traceEventsChanged'); |
94 e.numEvents = this.traceEvents_.length; | 94 e.numEvents = this.traceEvents_.length; |
(...skipping 23 matching lines...) Expand all Loading... |
118 | 118 |
119 /** | 119 /** |
120 * Gets the currently traced events. If tracing is active, then | 120 * Gets the currently traced events. If tracing is active, then |
121 * this can change on the fly. | 121 * this can change on the fly. |
122 */ | 122 */ |
123 get traceEvents() { | 123 get traceEvents() { |
124 return this.traceEvents_; | 124 return this.traceEvents_; |
125 }, | 125 }, |
126 | 126 |
127 /** | 127 /** |
128 * Callbed by gpu c++ code when new GPU trace data arrives. | 128 * Called by tracing c++ code when new trace data arrives. |
129 */ | 129 */ |
130 onTraceDataCollected: function(events) { | 130 onTraceDataCollected: function(events) { |
131 this.statusDiv_.textContent = 'Processing trace...'; | 131 this.statusDiv_.textContent = 'Processing trace...'; |
132 this.traceEvents_.push.apply(this.traceEvents_, events); | 132 this.traceEvents_.push.apply(this.traceEvents_, events); |
133 }, | 133 }, |
134 | 134 |
135 /** | 135 /** |
136 * Called by info_view to finish tracing and update all views. | 136 * Called by info_view to finish tracing and update all views. |
137 */ | 137 */ |
138 endTracing: function() { | 138 endTracing: function() { |
139 if (!this.tracingEnabled_) throw new Error('Tracing not begun.'); | 139 if (!this.tracingEnabled_) throw new Error('Tracing not begun.'); |
140 if (this.tracingEnding_) return; | 140 if (this.tracingEnding_) return; |
141 this.tracingEnding_ = true; | 141 this.tracingEnding_ = true; |
142 | 142 |
143 this.statusDiv_.textContent = 'Ending trace...'; | 143 this.statusDiv_.textContent = 'Ending trace...'; |
144 console.log('Finishing trace'); | 144 console.log('Finishing trace'); |
145 this.statusDiv_.textContent = 'Downloading trace data...'; | 145 this.statusDiv_.textContent = 'Downloading trace data...'; |
146 this.stopButton_.hidden = true; | 146 this.stopButton_.hidden = true; |
147 // delay sending endTracingAsync until we get a chance to | 147 // delay sending endTracingAsync until we get a chance to |
148 // update the screen... | 148 // update the screen... |
149 window.setTimeout(function() { | 149 window.setTimeout(function() { |
150 if (!browserBridge.debugMode) { | 150 if (!browserBridge.debugMode) { |
151 chrome.send('endTracingAsync'); | 151 chrome.send('endTracingAsync'); |
152 } else { | 152 } else { |
153 gpu.tracingControllerTestHarness.endTracing(); | 153 tracing.tracingControllerTestHarness.endTracing(); |
154 } | 154 } |
155 }, 100); | 155 }, 100); |
156 }, | 156 }, |
157 | 157 |
158 /** | 158 /** |
159 * Called by the browser when all processes complete tracing. | 159 * Called by the browser when all processes complete tracing. |
160 */ | 160 */ |
161 onEndTracingComplete: function() { | 161 onEndTracingComplete: function() { |
162 window.removeEventListener('keydown', this.onKeydownBoundToThis_); | 162 window.removeEventListener('keydown', this.onKeydownBoundToThis_); |
163 window.removeEventListener('keypress', this.onKeypressBoundToThis_); | 163 window.removeEventListener('keypress', this.onKeypressBoundToThis_); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 selfTest: function() { | 231 selfTest: function() { |
232 this.beginTracing(); | 232 this.beginTracing(); |
233 window.setTimeout(this.endTracing.bind(This), 500); | 233 window.setTimeout(this.endTracing.bind(This), 500); |
234 } | 234 } |
235 }; | 235 }; |
236 return { | 236 return { |
237 TracingController: TracingController | 237 TracingController: TracingController |
238 }; | 238 }; |
239 }); | 239 }); |
240 | 240 |
OLD | NEW |