Bug 751034 - Support remote profiling Via Remote debugging protocol. r=past,rcampbell
authorBenoit Girard <b56girard@gmail.com>
Thu, 06 Sep 2012 16:55:55 +0300
changeset 107597 d8921aee4a5deb90e58e50335bbf20858a695bb6
parent 107596 22af72b981a08563702b5c1a062680c6a85cd01e
child 107598 f11a44846f265dea7c7fb64dd231b58218d7b037
push id82
push usershu@rfrn.org
push dateFri, 05 Oct 2012 13:20:22 +0000
reviewerspast, rcampbell
bugs751034
milestone18.0a1
Bug 751034 - Support remote profiling Via Remote debugging protocol. r=past,rcampbell
toolkit/devtools/debugger/server/dbg-profiler-actors.js
toolkit/devtools/jar.mn
new file mode 100644
--- /dev/null
+++ b/toolkit/devtools/debugger/server/dbg-profiler-actors.js
@@ -0,0 +1,78 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+/**
+ * Creates a ProfilerActor. ProfilerActor provides remote access to the
+ * built-in profiler module.
+ */
+function ProfilerActor()
+{
+  this._profiler = Cc["@mozilla.org/tools/profiler;1"].getService(Ci.nsIProfiler);
+  this._started = false;
+}
+
+ProfilerActor.prototype = {
+  actorPrefix: "profiler",
+
+  disconnect: function() {
+    if (this._profiler && this._started) {
+      this._profiler.StopProfiler();
+    }
+    this._profiler = null;
+  },
+
+  onStartProfiler: function(aRequest) {
+    this._profiler.StartProfiler(aRequest.entries, aRequest.interval,
+                           aRequest.features, aRequest.features.length);
+    this._started = true;
+    return { "msg": "profiler started" }
+  },
+  onStopProfiler: function(aRequest) {
+    this._profiler.StopProfiler();
+    this._started = false;
+    return { "msg": "profiler stopped" }
+  },
+  onGetProfileStr: function(aRequest) {
+    var profileStr = this._profiler.GetProfile();
+    return { "profileStr": profileStr }
+  },
+  onGetProfile: function(aRequest) {
+    var profile = this._profiler.getProfileData();
+    return { "profile": profile }
+  },
+  onIsActive: function(aRequest) {
+    var isActive = this._profiler.IsActive();
+    return { "isActive": isActive }
+  },
+  onGetResponsivenessTimes: function(aRequest) {
+    var times = this._profiler.GetResponsivenessTimes({});
+    return { "responsivenessTimes": times }
+  },
+  onGetFeatures: function(aRequest) {
+    var features = this._profiler.GetFeatures([]);
+    return { "features": features }
+  },
+  onGetSharedLibraryInformation: function(aRequest) {
+    var sharedLibraries = this._profiler.getSharedLibraryInformation();
+    return { "sharedLibraryInformation": sharedLibraries }
+  }
+};
+
+/**
+ * The request types this actor can handle.
+ */
+ProfilerActor.prototype.requestTypes = {
+  "startProfiler": ProfilerActor.prototype.onStartProfiler,
+  "stopProfiler": ProfilerActor.prototype.onStopProfiler,
+  "getProfileStr": ProfilerActor.prototype.onGetProfileStr,
+  "getProfile": ProfilerActor.prototype.onGetProfile,
+  "isActive": ProfilerActor.prototype.onIsActive,
+  "getResponsivenessTimes": ProfilerActor.prototype.onGetResponsivenessTimes,
+  "getFeatures": ProfilerActor.prototype.onGetFeatures,
+  "getSharedLibraryInformation": ProfilerActor.prototype.onGetSharedLibraryInformation
+};
+
+DebuggerServer.addGlobalActor(ProfilerActor, "profilerActor");
--- a/toolkit/devtools/jar.mn
+++ b/toolkit/devtools/jar.mn
@@ -2,8 +2,9 @@
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 toolkit.jar:
   content/global/devtools/dbg-transport.js        (debugger/dbg-transport.js)
   content/global/devtools/dbg-server.js        		(debugger/server/dbg-server.js)
   content/global/devtools/dbg-script-actors.js    (debugger/server/dbg-script-actors.js)
   content/global/devtools/dbg-browser-actors.js   (debugger/server/dbg-browser-actors.js)
+  content/global/devtools/dbg-profiler-actors.js  (debugger/server/dbg-profiler-actors.js)