Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1430)

Unified Diff: Source/devtools/front_end/sdk/TracingManager.js

Issue 563463003: DevTools: extract TracingManager from TracingModel, step 2 (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/devtools/front_end/inspector.html ('k') | Source/devtools/front_end/sdk/TracingModel.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/devtools/front_end/sdk/TracingManager.js
diff --git a/Source/devtools/front_end/sdk/TracingManager.js b/Source/devtools/front_end/sdk/TracingManager.js
new file mode 100644
index 0000000000000000000000000000000000000000..6471cb0449ab328258de54a17327ccfbd98b1011
--- /dev/null
+++ b/Source/devtools/front_end/sdk/TracingManager.js
@@ -0,0 +1,168 @@
+/*
+ * Copyright 2014 The Chromium Authors. All rights reserved.
yurys 2014/09/11 06:49:23 nit: I guess we use // -style comments for license
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+/**
+ * @constructor
+ * @extends {WebInspector.Object}
+ * @implements {WebInspector.TargetManager.Observer}
+ */
+WebInspector.TracingManager = function()
+{
+ WebInspector.Object.call(this);
+ this._active = false;
+ WebInspector.targetManager.observeTargets(this);
+}
+
+WebInspector.TracingManager.Events = {
+ "BufferUsage": "BufferUsage",
+ "TracingStarted": "TracingStarted",
+ "EventsCollected": "EventsCollected",
+ "TracingStopped": "TracingStopped",
+ "TracingComplete": "TracingComplete"
+}
+
+/** @typedef {!{
+ cat: string,
+ pid: number,
+ tid: number,
+ ts: number,
+ ph: string,
+ name: string,
+ args: !Object,
+ dur: number,
+ id: number,
+ s: string
+ }}
+ */
+WebInspector.TracingManager.EventPayload;
+
+WebInspector.TracingManager.prototype = {
+ /**
+ * @param {!WebInspector.Target} target
+ */
+ targetAdded: function(target)
+ {
+ if (this._target)
+ return;
+ this._target = target;
+ InspectorBackend.registerTracingDispatcher(new WebInspector.TracingDispatcher(this));
+ },
+
+ /**
+ * @param {!WebInspector.Target} target
+ */
+ targetRemoved: function(target)
+ {
+ if (this._target !== target)
+ return;
+ delete this._target;
+ },
+
+ /**
+ * @param {number} usage
+ */
+ _bufferUsage: function(usage)
+ {
+ this.dispatchEventToListeners(WebInspector.TracingManager.Events.BufferUsage, usage);
+ },
+
+ /**
+ * @param {!Array.<!WebInspector.TracingManager.EventPayload>} events
+ */
+ _eventsCollected: function(events)
+ {
+ this.dispatchEventToListeners(WebInspector.TracingManager.Events.EventsCollected, events);
+ },
+
+ _tracingComplete: function()
+ {
+ this.dispatchEventToListeners(WebInspector.TracingManager.Events.TracingComplete);
+ },
+
+ _tracingStarted: function()
+ {
+ if (this._active)
+ return;
+ this._active = true;
+ this.dispatchEventToListeners(WebInspector.TracingManager.Events.TracingStarted);
+ },
+
+ /**
+ * @param {string} categoryFilter
+ * @param {string} options
+ * @param {function(?string)=} callback
+ */
+ start: function(categoryFilter, options, callback)
+ {
+ if (this._active)
+ return;
+ WebInspector.profilingLock().acquire();
+ this._shouldReleaseLock = true;
+ var bufferUsageReportingIntervalMs = 500;
+ TracingAgent.start(categoryFilter, options, bufferUsageReportingIntervalMs, callback);
+ this._tracingStarted();
+ this._active = true;
+ },
+
+ stop: function()
+ {
+ if (!this._active)
+ return;
+ TracingAgent.end(this._onStop.bind(this));
+ if (this._shouldReleaseLock) {
+ this._shouldReleaseLock = false;
+ WebInspector.profilingLock().release();
+ }
+ },
+
+ _onStop: function()
+ {
+ if (!this._active)
+ return;
+ this.dispatchEventToListeners(WebInspector.TracingManager.Events.TracingStopped);
+ this._active = false;
+ },
+
+ __proto__: WebInspector.Object.prototype
+}
+
+/**
+ * @constructor
+ * @implements {TracingAgent.Dispatcher}
+ * @param {!WebInspector.TracingManager} tracingManager
+ */
+WebInspector.TracingDispatcher = function(tracingManager)
+{
+ this._tracingManager = tracingManager;
+}
+
+WebInspector.TracingDispatcher.prototype = {
+ /**
+ * @param {number} usage
+ */
+ bufferUsage: function(usage)
+ {
+ this._tracingManager._bufferUsage(usage);
+ },
+
+ /**
+ * @param {!Array.<!WebInspector.TracingManager.EventPayload>} data
+ */
+ dataCollected: function(data)
+ {
+ this._tracingManager._eventsCollected(data);
+ },
+
+ tracingComplete: function()
+ {
+ this._tracingManager._tracingComplete();
+ },
+
+ started: function()
+ {
+ this._tracingManager._tracingStarted();
+ }
+}
« no previous file with comments | « Source/devtools/front_end/inspector.html ('k') | Source/devtools/front_end/sdk/TracingModel.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698