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..69a3b400ed6713d4b73f7347e83dd41929dacf23 |
| --- /dev/null |
| +++ b/chrome/browser/resources/gpu_internals/tracing_controller.js |
| @@ -0,0 +1,123 @@ |
| +// 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() { |
|
arv (Not doing code reviews)
2011/02/25 00:51:29
Can you add an empty line before this?
|
| + function TracingController() { |
| + this.overlay_ = $('gpu-tracing-overlay-template').cloneNode(true); |
| + this.overlay_.removeAttribute('id'); |
|
arv (Not doing code reviews)
2011/02/25 00:51:29
Prefer DOM properties where possible
this.overlay
|
| + cr.ui.decorate(this.overlay_, gpu.Overlay); |
| + |
| + this.traceEvents_ = []; |
| + |
| + var startButton = $('gpu-tracing-start-button-template').cloneNode(true); |
| + startButton.removeAttribute('id'); |
| + document.body.appendChild(startButton); |
| + startButton.onclick = this.beginTracing.bind(this); |
| + |
| + var stopButton = this.overlay_.querySelector('.gpu-tracing-stop-button'); |
| + stopButton.onclick = this.endTracing.bind(this); |
| + } |
| + |
| + TracingController.prototype = { |
| + __proto__: cr.EventTarget.prototype, |
| + |
| + tracingEnabled_ : false, |
| + |
| + /** |
| + * Called by info_view to empty the trace buffer |
| + */ |
| + beginTracing: function() { |
| + if (this.tracingEnabled_) |
| + throw Error('Tracing already begun.'); |
| + |
| + this.overlay_.visible = true; |
| + |
| + this.tracingEnabled_ = true; |
| + console.log('Beginning to trace...'); |
| + |
| + this.traceEvents_ = []; |
| + if (!browserBridge.debugMode) |
| + chrome.send('beginTracing'); |
| + |
| + this.tracingEnabled_ = true; |
| + |
| + var e = new cr.Event('traceBegun'); |
| + e.events = this.traceEvents_; |
| + this.dispatchEvent(e); |
| + |
| + e = new cr.Event('traceEventsChanged'); |
| + e.numEvents = this.traceEvents_.length; |
| + this.dispatchEvent(e); |
| + |
| + var self; |
| + window.addEventListener('keypress', function f(e) { |
| + if(e.keyIdentifier == 'Enter') { |
|
arv (Not doing code reviews)
2011/02/25 00:51:29
ws
|
| + window.removeEventListener('keypress', f); |
| + self.endTracing(); |
| + } |
| + }); |
| + }, |
| + |
| + /** |
| + * Checks whether tracing is enabled |
| + */ |
| + get isTracingEnabled() { |
| + return this.tracingEnabled_; |
| + }, |
| + |
| + /** |
| + * Gets the currently traced events. If tracing is active, then |
| + * this can change on the fly. |
| + */ |
| + get traceEvents() { |
| + return this.traceEvents_; |
| + }, |
| + |
| + /** |
| + * Callbed by gpu c++ code when new GPU trace data arrives. |
| + */ |
| + onTraceDataCollected: 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.'); |
| + |
| + console.log('Finishing trace'); |
| + if (!browserBridge.debugMode) { |
| + chrome.send('beginToEndTracing'); |
| + } else { |
| + var events; |
| + if(window.getTimelineTestData1){ |
|
arv (Not doing code reviews)
2011/02/25 00:51:29
ws
arv (Not doing code reviews)
2011/02/25 00:51:29
or
events = window.getTimelineTestData1 ? getTime
|
| + events = getTimelineTestData1(); |
| + } else { |
| + events = []; |
| + } |
| + this.onTraceDataCollected(events); |
| + window.setTimeout(this.onEndTracingComplete.bind(this), 250); |
| + } |
| + }, |
| + /* Called by the browser when all processes ack tracing having completed. */ |
|
arv (Not doing code reviews)
2011/02/25 00:51:29
Use JSDoc
|
| + onEndTracingComplete: function() { |
| + this.overlay_.visible = false; |
| + this.tracingEnabled_ = false; |
| + console.log('onEndTracingComplete p1 with ' + |
| + this.traceEvents_.length + ' events.'); |
| + var e = new cr.Event('traceEnded'); |
| + e.events = this.traceEvents_; |
| + this.dispatchEvent(e); |
| + }, |
| + |
| + selfTest: function() { |
| + this.beginTracing(); |
| + window.setTimeout(this.endTracing.bind(This), 500); |
| + } |
| + }; |
| + return { |
| + TracingController : TracingController |
| + }; |
| +}); |
| + |