tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

memory.js (2855B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 "use strict";
      6 
      7 const { Actor } = require("resource://devtools/shared/protocol.js");
      8 const { memorySpec } = require("resource://devtools/shared/specs/memory.js");
      9 
     10 const { Memory } = require("resource://devtools/server/performance/memory.js");
     11 const {
     12  actorBridgeWithSpec,
     13 } = require("resource://devtools/server/actors/common.js");
     14 
     15 loader.lazyRequireGetter(
     16  this,
     17  "StackFrameCache",
     18  "resource://devtools/server/actors/utils/stack.js",
     19  true
     20 );
     21 
     22 /**
     23 * An actor that returns memory usage data for its parent actor's window.
     24 * A target-scoped instance of this actor will measure the memory footprint of
     25 * the target, such as a tab. A global-scoped instance however, will measure the memory
     26 * footprint of the chrome window referenced by the root actor.
     27 *
     28 * This actor wraps the Memory module at devtools/server/performance/memory.js
     29 * and provides RDP definitions.
     30 *
     31 * @see devtools/server/performance/memory.js for documentation.
     32 */
     33 exports.MemoryActor = class MemoryActor extends Actor {
     34  constructor(conn, parent, frameCache = new StackFrameCache()) {
     35    super(conn, memorySpec);
     36 
     37    this._onGarbageCollection = this._onGarbageCollection.bind(this);
     38    this._onAllocations = this._onAllocations.bind(this);
     39    this.bridge = new Memory(parent, frameCache);
     40    this.bridge.on("garbage-collection", this._onGarbageCollection);
     41    this.bridge.on("allocations", this._onAllocations);
     42  }
     43 
     44  destroy() {
     45    this.bridge.off("garbage-collection", this._onGarbageCollection);
     46    this.bridge.off("allocations", this._onAllocations);
     47    this.bridge.destroy();
     48    super.destroy();
     49  }
     50 
     51  attach = actorBridgeWithSpec("attach");
     52 
     53  detach = actorBridgeWithSpec("detach");
     54 
     55  getState = actorBridgeWithSpec("getState");
     56 
     57  saveHeapSnapshot(boundaries) {
     58    return this.bridge.saveHeapSnapshot(boundaries);
     59  }
     60 
     61  takeCensus = actorBridgeWithSpec("takeCensus");
     62 
     63  startRecordingAllocations = actorBridgeWithSpec("startRecordingAllocations");
     64 
     65  stopRecordingAllocations = actorBridgeWithSpec("stopRecordingAllocations");
     66 
     67  getAllocationsSettings = actorBridgeWithSpec("getAllocationsSettings");
     68 
     69  getAllocations = actorBridgeWithSpec("getAllocations");
     70 
     71  forceGarbageCollection = actorBridgeWithSpec("forceGarbageCollection");
     72 
     73  forceCycleCollection = actorBridgeWithSpec("forceCycleCollection");
     74 
     75  measure = actorBridgeWithSpec("measure");
     76 
     77  residentUnique = actorBridgeWithSpec("residentUnique");
     78 
     79  _onGarbageCollection(data) {
     80    if (this.conn.transport) {
     81      this.emit("garbage-collection", data);
     82    }
     83  }
     84 
     85  _onAllocations(data) {
     86    if (this.conn.transport) {
     87      this.emit("allocations", data);
     88    }
     89  }
     90 };