From 36d22d82aa202bb199967e9512281e9a53db42c9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 21:33:14 +0200 Subject: Adding upstream version 115.7.0esr. Signed-off-by: Daniel Baumann --- devtools/server/actors/memory.js | 90 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 devtools/server/actors/memory.js (limited to 'devtools/server/actors/memory.js') diff --git a/devtools/server/actors/memory.js b/devtools/server/actors/memory.js new file mode 100644 index 0000000000..482596ed4a --- /dev/null +++ b/devtools/server/actors/memory.js @@ -0,0 +1,90 @@ +/* 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 { Actor } = require("resource://devtools/shared/protocol.js"); +const { memorySpec } = require("resource://devtools/shared/specs/memory.js"); + +const { Memory } = require("resource://devtools/server/performance/memory.js"); +const { + actorBridgeWithSpec, +} = require("resource://devtools/server/actors/common.js"); + +loader.lazyRequireGetter( + this, + "StackFrameCache", + "resource://devtools/server/actors/utils/stack.js", + true +); + +/** + * An actor that returns memory usage data for its parent actor's window. + * A target-scoped instance of this actor will measure the memory footprint of + * the target, such as a 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 devtools/server/performance/memory.js + * and provides RDP definitions. + * + * @see devtools/server/performance/memory.js for documentation. + */ +exports.MemoryActor = class MemoryActor extends Actor { + constructor(conn, parent, frameCache = new StackFrameCache()) { + super(conn, memorySpec); + + this._onGarbageCollection = this._onGarbageCollection.bind(this); + this._onAllocations = this._onAllocations.bind(this); + this.bridge = new Memory(parent, frameCache); + this.bridge.on("garbage-collection", this._onGarbageCollection); + this.bridge.on("allocations", this._onAllocations); + } + + destroy() { + this.bridge.off("garbage-collection", this._onGarbageCollection); + this.bridge.off("allocations", this._onAllocations); + this.bridge.destroy(); + super.destroy(); + } + + attach = actorBridgeWithSpec("attach"); + + detach = actorBridgeWithSpec("detach"); + + getState = actorBridgeWithSpec("getState"); + + saveHeapSnapshot(boundaries) { + return this.bridge.saveHeapSnapshot(boundaries); + } + + takeCensus = actorBridgeWithSpec("takeCensus"); + + startRecordingAllocations = actorBridgeWithSpec("startRecordingAllocations"); + + stopRecordingAllocations = actorBridgeWithSpec("stopRecordingAllocations"); + + getAllocationsSettings = actorBridgeWithSpec("getAllocationsSettings"); + + getAllocations = actorBridgeWithSpec("getAllocations"); + + forceGarbageCollection = actorBridgeWithSpec("forceGarbageCollection"); + + forceCycleCollection = actorBridgeWithSpec("forceCycleCollection"); + + measure = actorBridgeWithSpec("measure"); + + residentUnique = actorBridgeWithSpec("residentUnique"); + + _onGarbageCollection(data) { + if (this.conn.transport) { + this.emit("garbage-collection", data); + } + } + + _onAllocations(data) { + if (this.conn.transport) { + this.emit("allocations", data); + } + } +}; -- cgit v1.2.3