mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-19 16:25:38 +00:00
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
This commit is contained in:
parent
41e334cea0
commit
0dd67c1a95
@ -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;
|
||||
|
@ -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");
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
}
|
@ -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'
|
||||
|
@ -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;
|
@ -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'
|
||||
]
|
||||
|
Loading…
Reference in New Issue
Block a user