Chromium Code Reviews| Index: chrome/browser/resources/gpu_internals/tracing_controller.js |
| diff --git a/chrome/browser/resources/gpu_internals/tracing_controller.js b/chrome/browser/resources/gpu_internals/tracing_controller.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..ed88bb0c70abd54fff07819c549764acd93cdee3 |
| --- /dev/null |
| +++ b/chrome/browser/resources/gpu_internals/tracing_controller.js |
| @@ -0,0 +1,129 @@ |
| +// Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| +cr.define('gpu', function() { |
| + function TracingController() { |
| + this.overlay_ = $('gpu-tracing-overlay'); |
|
arv (Not doing code reviews)
2011/02/23 17:51:25
I know we do this a lot in the options code but us
nduca
2011/02/23 23:34:13
I agree, it smells bad. I think there are two 'wro
|
| + cr.ui.decorate(this.overlay_, gpu.Overlay); |
| + |
| + this.tracingEnabled_ = false; |
|
arv (Not doing code reviews)
2011/02/23 17:51:25
I would move this to the prototype.
nduca
2011/02/23 23:34:13
Done.
|
| + this.traceEvents_ = []; |
| + } |
| + TracingController.prototype = { |
| + __proto__: cr.EventTarget.prototype, |
| + |
| + initUI : function(mainTabs) { |
|
arv (Not doing code reviews)
2011/02/23 17:51:25
no ws before :
nduca
2011/02/23 23:34:13
Done.
|
| + var startButton = $('gpu-tracing-start-button'); |
| + var stopButton = $('gpu-tracing-stop-button'); |
| + mainTabs.addCustomWidget(startButton); |
| + |
| + startButton.onclick = function() { |
|
arv (Not doing code reviews)
2011/02/23 17:51:25
startButton.onclick = this.beginTracing.bind(this)
nduca
2011/02/23 23:34:13
Done.
|
| + this.beginTracing(); |
| + }.bind(this); |
| + stopButton.onclick = function() { |
| + this.endTracing(); |
| + }.bind(this); |
| + this.onclick = function() { |
| + this.endTracing(); |
| + }.bind(this); |
| + }, |
| + |
| + /** |
| + * Called by info_view to empty the trace buffer |
| + */ |
| + beginTracing : function() { |
| + if(this.tracingEnabled_) throw new Error("Tracing already begun."); |
|
arv (Not doing code reviews)
2011/02/23 17:51:25
line break
arv (Not doing code reviews)
2011/02/23 17:51:25
new is not needed here
nduca
2011/02/23 23:34:13
Done.
|
| + |
| + this.overlay_.show(); |
| + |
| + this.tracingEnabled_ = true; |
| + console.log("Beginning to trace..."); |
|
arv (Not doing code reviews)
2011/02/23 17:51:25
Use single quotes
|
| + |
| + this.traceEvents_ = []; |
| + if(!browserBridge.debugMode) |
| + chrome.send('beginTracing'); |
| + |
| + this.tracingEnabled_ = true; |
| + |
| + var e = new cr.Event('gpuTraceBegun'); |
| + e.events = this.traceEvents_; |
| + this.dispatchEvent(e); |
| + |
| + e = new cr.Event('gpuTraceEventsChanged'); |
| + e.numEvents = this.traceEvents_.length; |
| + this.dispatchEvent(e); |
| + |
| + this.currentlyBoundKeypressListener_ = this.onOverlayKeyPress_.bind(this); |
|
arv (Not doing code reviews)
2011/02/23 17:51:25
I'm not sure this is cleaner but this can also be
nduca
2011/02/23 23:34:13
Thats pretty neat. I dislike that less than I woul
|
| + window.addEventListener('keypress', this.currentlyBoundKeypressListener_); |
| + }, |
| + |
| + onOverlayKeyPress_ : function(e) { |
| + console.log(e); |
| + if(e.charCode == 13) { // enter |
|
arv (Not doing code reviews)
2011/02/23 17:51:25
if (e.keyIdentifier == 'Enter')
arv (Not doing code reviews)
2011/02/23 17:51:25
Whitespace after if
nduca
2011/02/23 23:34:13
Done.
|
| + this.endTracing(); |
| + } |
| + }, |
| + |
| + /** |
| + * Checks whether gpu tracing is enabled |
| + */ |
| + isGpuTracingEnabled : function() { |
|
arv (Not doing code reviews)
2011/02/23 17:51:25
Maybe use a getter?
nduca
2011/02/23 23:34:13
Done.
|
| + return this.tracingEnabled_; |
| + }, |
| + |
| + /** |
| + * Gets the currently traced events. If tracing is active, then |
| + * this can change on the fly. |
| + */ |
| + getGpuTraceEvents : function() { |
|
arv (Not doing code reviews)
2011/02/23 17:51:25
getter?
nduca
2011/02/23 23:34:13
Done.
|
| + return this.traceEvents_; |
| + }, |
| + |
| + /** |
| + * Callbed by gpu c++ code when new GPU trace data arrives. |
| + */ |
| + onGpuTraceDataCollected: function(events) { |
| + this.traceEvents_.push.apply(this.traceEvents_, events); |
| + }, |
| + |
| + /** |
| + * Called by info_view to finish tracing and update all views. |
| + */ |
| + endTracing : function() { |
| + if(!this.tracingEnabled_) throw new Error("Tracing not begun."); |
| + |
| + window.removeEventListener('keypress', |
| + this.currentlyBoundKeypressListener_); |
| + |
| + console.log("Finishing trace"); |
| + if(!browserBridge.debugMode) |
|
arv (Not doing code reviews)
2011/02/23 17:51:25
If else has curly braces then if should too
nduca
2011/02/23 23:34:13
Done.
|
| + chrome.send('beginToEndTracing'); |
| + else { |
| + var events = getTimelineTestData1(); |
| + this.onGpuTraceDataCollected(events); |
| + window.setTimeout(this.onEndTracingComplete.bind(this), 250); |
| + } |
| + }, |
| + /* Called by the browser when all processes ack tracing having completed. */ |
| + onEndTracingComplete : function() { |
| + this.overlay_.hide(); |
| + this.tracingEnabled_ = false; |
| + console.log("onEndTracingComplete p1 with " + |
| + this.traceEvents_.length + " events."); |
| + var e = new cr.Event('gpuTraceEnded'); |
| + e.events = this.traceEvents_; |
| + this.dispatchEvent(e); |
| + }, |
| + |
| + selfTest : function() { |
| + this.beginTracing(); |
| + window.setTimeout(function() { |
| + this.endTracing(); |
|
arv (Not doing code reviews)
2011/02/23 17:51:25
this.endTracing.bind(this)
nduca
2011/02/23 23:34:13
Done.
|
| + }.bind(this),500); |
| + } |
| + }; |
| + return { |
| + TracingController : TracingController |
| + }; |
| +}); |
| + |