From 0dd67c1a95ae25778111fcd7dac1617d57edc046 Mon Sep 17 00:00:00 2001 From: Jordan Santell Date: Tue, 9 Jun 2015 17:01:30 -0700 Subject: [PATCH] Bug 1172182 - Pull out memory utility logic out of the MemoryActor so other actors can consume it. r=vp --HG-- rename : toolkit/devtools/server/actors/utils/memory-bridge.js => toolkit/devtools/shared/memory.js --- toolkit/devtools/server/actors/common.js | 17 +++++ toolkit/devtools/server/actors/framerate.js | 2 +- toolkit/devtools/server/actors/memory.js | 63 +++---------------- .../server/actors/utils/actor-utils.js | 24 ------- toolkit/devtools/server/moz.build | 2 - .../memory-bridge.js => shared/memory.js} | 7 +-- toolkit/devtools/shared/moz.build | 1 + 7 files changed, 30 insertions(+), 86 deletions(-) delete mode 100644 toolkit/devtools/server/actors/utils/actor-utils.js rename toolkit/devtools/{server/actors/utils/memory-bridge.js => shared/memory.js} (98%) diff --git a/toolkit/devtools/server/actors/common.js b/toolkit/devtools/server/actors/common.js index 1dde19c68a79..2ee6bedbc829 100644 --- a/toolkit/devtools/server/actors/common.js +++ b/toolkit/devtools/server/actors/common.js @@ -7,6 +7,7 @@ "use strict"; const promise = require("promise"); +const { method } = require("devtools/server/protocol"); /** * Creates "registered" actors factory meant for creating another kind of @@ -519,3 +520,19 @@ function expectState(expectedState, method, activity) { } exports.expectState = expectState; + +/** + * Proxies a call from an actor to an underlying module, stored + * as `bridge` on the actor. This allows a module to be defined in one + * place, usable by other modules/actors on the server, but a separate + * module defining the actor/RDP definition. + * + * @see Framerate implementation: toolkit/devtools/shared/framerate.js + * @see Framerate actor definition: toolkit/devtools/server/actors/framerate.js + */ +function actorBridge (methodName, definition={}) { + return method(function () { + return this.bridge[methodName].apply(this.bridge, arguments); + }, definition); +} +exports.actorBridge = actorBridge; diff --git a/toolkit/devtools/server/actors/framerate.js b/toolkit/devtools/server/actors/framerate.js index e5c828b27b85..f0299165bc28 100644 --- a/toolkit/devtools/server/actors/framerate.js +++ b/toolkit/devtools/server/actors/framerate.js @@ -4,7 +4,7 @@ "use strict"; const protocol = require("devtools/server/protocol"); -const { actorBridge } = require("devtools/server/actors/utils/actor-utils"); +const { actorBridge } = require("devtools/server/actors/common"); const { method, custom, Arg, Option, RetVal } = protocol; const { on, once, off, emit } = require("sdk/event/core"); const { Framerate } = require("devtools/toolkit/shared/framerate"); diff --git a/toolkit/devtools/server/actors/memory.js b/toolkit/devtools/server/actors/memory.js index 95a7b21623ee..78d6b41b4835 100644 --- a/toolkit/devtools/server/actors/memory.js +++ b/toolkit/devtools/server/actors/memory.js @@ -6,8 +6,8 @@ const protocol = require("devtools/server/protocol"); const { method, RetVal, Arg, types } = protocol; -const { MemoryBridge } = require("./utils/memory-bridge"); -const { actorBridge } = require("./utils/actor-utils"); +const { Memory } = require("devtools/toolkit/shared/memory"); +const { actorBridge } = require("devtools/server/actors/common"); loader.lazyRequireGetter(this, "events", "sdk/event/core"); loader.lazyRequireGetter(this, "StackFrameCache", "devtools/server/actors/utils/stack", true); @@ -29,8 +29,13 @@ types.addDictType("AllocationsRecordingOptions", { * A tab-scoped instance of this actor will measure the memory footprint of its * parent tab. A global-scoped instance however, will measure the memory * footprint of the chrome window referenced by the root actor. + * + * This actor wraps the Memory module at toolkit/devtools/shared/memory.js + * and provides RDP definitions. + * + * @see toolkit/devtools/shared/memory.js for documentation. */ -let MemoryActor = protocol.ActorClass({ +let MemoryActor = exports.MemoryActor = protocol.ActorClass({ typeName: "memory", /** @@ -52,7 +57,7 @@ let MemoryActor = protocol.ActorClass({ protocol.Actor.prototype.initialize.call(this, conn); this._onGarbageCollection = this._onGarbageCollection.bind(this); - this.bridge = new MemoryBridge(parent, frameCache); + this.bridge = new Memory(parent, frameCache); this.bridge.on("garbage-collection", this._onGarbageCollection); }, @@ -62,13 +67,6 @@ let MemoryActor = protocol.ActorClass({ protocol.Actor.prototype.destroy.call(this); }, - /** - * Attach to this MemoryActor. - * - * This attaches the MemoryActor's Debugger instance so that you can start - * recording allocations or take a census of the heap. In addition, the - * MemoryActor will start emitting GC events. - */ attach: actorBridge("attach", { request: {}, response: { @@ -76,9 +74,6 @@ let MemoryActor = protocol.ActorClass({ } }), - /** - * Detach from this MemoryActor. - */ detach: actorBridge("detach", { request: {}, response: { @@ -86,30 +81,17 @@ let MemoryActor = protocol.ActorClass({ } }), - /** - * Gets the current MemoryActor attach/detach state. - */ getState: actorBridge("getState", { response: { state: RetVal(0, "string") } }), - /** - * Take a census of the heap. See js/src/doc/Debugger/Debugger.Memory.md for - * more information. - */ takeCensus: actorBridge("takeCensus", { request: {}, response: RetVal("json") }), - /** - * Start recording allocation sites. - * - * @param AllocationsRecordingOptions options - * See the protocol.js definition of AllocationsRecordingOptions above. - */ startRecordingAllocations: actorBridge("startRecordingAllocations", { request: { options: Arg(0, "nullable:AllocationsRecordingOptions") @@ -120,9 +102,6 @@ let MemoryActor = protocol.ActorClass({ } }), - /** - * Stop recording allocation sites. - */ stopRecordingAllocations: actorBridge("stopRecordingAllocations", { request: {}, response: { @@ -131,10 +110,6 @@ let MemoryActor = protocol.ActorClass({ } }), - /** - * Return settings used in `startRecordingAllocations` for `probability` - * and `maxLogLength`. Currently only uses in tests. - */ getAllocationsSettings: actorBridge("getAllocationsSettings", { request: {}, response: { @@ -147,30 +122,16 @@ let MemoryActor = protocol.ActorClass({ response: RetVal("json") }), - /* - * Force a browser-wide GC. - */ forceGarbageCollection: actorBridge("forceGarbageCollection", { request: {}, response: {} }), - /** - * Force an XPCOM cycle collection. For more information on XPCOM cycle - * collection, see - * https://developer.mozilla.org/en-US/docs/Interfacing_with_the_XPCOM_cycle_collector#What_the_cycle_collector_does - */ forceCycleCollection: actorBridge("forceCycleCollection", { request: {}, response: {} }), - /** - * A method that returns a detailed breakdown of the memory consumption of the - * associated window. - * - * @returns object - */ measure: actorBridge("measure", { request: {}, response: RetVal("json"), @@ -181,17 +142,11 @@ let MemoryActor = protocol.ActorClass({ response: { value: RetVal("number") } }), - /** - * Called when the underlying MemoryBridge fires a "garbage-collection" events. - * Propagates over RDP. - */ _onGarbageCollection: function (data) { events.emit(this, "garbage-collection", data); }, }); -exports.MemoryActor = MemoryActor; - exports.MemoryFront = protocol.FrontClass(MemoryActor, { initialize: function(client, form) { protocol.Front.prototype.initialize.call(this, client, form); diff --git a/toolkit/devtools/server/actors/utils/actor-utils.js b/toolkit/devtools/server/actors/utils/actor-utils.js deleted file mode 100644 index e231757b2f6d..000000000000 --- a/toolkit/devtools/server/actors/utils/actor-utils.js +++ /dev/null @@ -1,24 +0,0 @@ -/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ -/* vim: set ft=javascript ts=2 et sw=2 tw=80: */ -/* 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"; - -const { method } = require("devtools/server/protocol"); - -/** - * Proxies a call from an actor to an underlying module, stored - * as `bridge` on the actor. This allows a module to be defined in one - * place, usable by other modules/actors on the server, but a separate - * module defining the actor/RDP definition. - * - * @see Framerate implementation: toolkit/devtools/shared/framerate.js - * @see Framerate actor definition: toolkit/devtools/server/actors/framerate.js - */ -exports.actorBridge = function actorBridge (methodName, definition={}) { - return method(function () { - return this.bridge[methodName].apply(this.bridge, arguments); - }, definition); -} diff --git a/toolkit/devtools/server/moz.build b/toolkit/devtools/server/moz.build index cbf3d4b2ed21..5762aa57093b 100644 --- a/toolkit/devtools/server/moz.build +++ b/toolkit/devtools/server/moz.build @@ -98,12 +98,10 @@ EXTRA_JS_MODULES.devtools.server.actors += [ EXTRA_JS_MODULES.devtools.server.actors.utils += [ 'actors/utils/actor-registry-utils.js', - 'actors/utils/actor-utils.js', 'actors/utils/audionodes.json', 'actors/utils/automation-timeline.js', 'actors/utils/make-debugger.js', 'actors/utils/map-uri-to-addon-id.js', - 'actors/utils/memory-bridge.js', 'actors/utils/ScriptStore.js', 'actors/utils/stack.js', 'actors/utils/TabSources.js' diff --git a/toolkit/devtools/server/actors/utils/memory-bridge.js b/toolkit/devtools/shared/memory.js similarity index 98% rename from toolkit/devtools/server/actors/utils/memory-bridge.js rename to toolkit/devtools/shared/memory.js index d4b5af5cdbeb..4409617925bf 100644 --- a/toolkit/devtools/server/actors/utils/memory-bridge.js +++ b/toolkit/devtools/shared/memory.js @@ -12,18 +12,17 @@ loader.lazyRequireGetter(this, "events", "sdk/event/core"); loader.lazyRequireGetter(this, "EventTarget", "sdk/event/target", true); loader.lazyRequireGetter(this, "StackFrameCache", "devtools/server/actors/utils/stack", true); - /** * A class that returns memory data for a parent actor's window. * Using a tab-scoped actor with this instance will measure the memory footprint of its * parent tab. Using a global-scoped actor instance however, will measure the memory * footprint of the chrome window referenced by its root actor. * - * To be consumed by actor's, like MemoryActor using MemoryBridge to + * To be consumed by actor's, like MemoryActor using this module to * send information over RDP, and TimelineActor for using more light-weight * utilities like GC events and measuring memory consumption. */ -let MemoryBridge = Class({ +let Memory = exports.Memory = Class({ extends: EventTarget, /** @@ -335,5 +334,3 @@ let MemoryBridge = Class({ return this._mgr.residentUnique; } }); - -exports.MemoryBridge = MemoryBridge; diff --git a/toolkit/devtools/shared/moz.build b/toolkit/devtools/shared/moz.build index 6eb5aefdb8f1..74df470b5002 100644 --- a/toolkit/devtools/shared/moz.build +++ b/toolkit/devtools/shared/moz.build @@ -9,6 +9,7 @@ BROWSER_CHROME_MANIFESTS += ['tests/browser/browser.ini'] EXTRA_JS_MODULES.devtools.shared += [ 'async-storage.js', 'framerate.js', + 'memory.js', 'worker-helper.js', 'worker.js' ]