2013-12-03 11:41:02 +00:00
|
|
|
/* 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";
|
|
|
|
|
2016-05-06 07:19:00 +00:00
|
|
|
const protocol = require("devtools/shared/protocol");
|
2015-10-07 21:08:55 +00:00
|
|
|
const { Memory } = require("devtools/server/performance/memory");
|
2016-06-10 20:28:15 +00:00
|
|
|
const { actorBridgeWithSpec } = require("devtools/server/actors/common");
|
|
|
|
const { memorySpec } = require("devtools/shared/specs/memory");
|
2014-12-29 10:32:00 +00:00
|
|
|
loader.lazyRequireGetter(this, "StackFrameCache",
|
|
|
|
"devtools/server/actors/utils/stack", true);
|
2014-09-23 10:29:00 +00:00
|
|
|
|
2013-12-03 11:41:02 +00:00
|
|
|
/**
|
|
|
|
* An actor that returns memory usage data for its parent actor's window.
|
|
|
|
* 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.
|
2015-07-17 19:21:45 +00:00
|
|
|
*
|
2015-10-07 21:08:55 +00:00
|
|
|
* This actor wraps the Memory module at devtools/server/performance/memory.js
|
2015-06-10 00:01:30 +00:00
|
|
|
* and provides RDP definitions.
|
|
|
|
*
|
2015-10-07 21:08:55 +00:00
|
|
|
* @see devtools/server/performance/memory.js for documentation.
|
2013-12-03 11:41:02 +00:00
|
|
|
*/
|
2016-08-22 14:25:57 +00:00
|
|
|
exports.MemoryActor = protocol.ActorClassWithSpec(memorySpec, {
|
2016-05-17 18:25:54 +00:00
|
|
|
initialize: function (conn, parent, frameCache = new StackFrameCache()) {
|
2013-12-03 11:41:02 +00:00
|
|
|
protocol.Actor.prototype.initialize.call(this, conn);
|
2014-09-17 08:41:00 +00:00
|
|
|
|
2015-04-28 17:32:32 +00:00
|
|
|
this._onGarbageCollection = this._onGarbageCollection.bind(this);
|
2015-07-17 19:21:45 +00:00
|
|
|
this._onAllocations = this._onAllocations.bind(this);
|
2015-06-10 00:01:30 +00:00
|
|
|
this.bridge = new Memory(parent, frameCache);
|
2015-04-28 17:32:32 +00:00
|
|
|
this.bridge.on("garbage-collection", this._onGarbageCollection);
|
2015-07-17 19:21:45 +00:00
|
|
|
this.bridge.on("allocations", this._onAllocations);
|
2013-12-03 11:41:02 +00:00
|
|
|
},
|
|
|
|
|
2016-05-17 18:25:54 +00:00
|
|
|
destroy: function () {
|
2015-04-28 17:32:32 +00:00
|
|
|
this.bridge.off("garbage-collection", this._onGarbageCollection);
|
2015-07-17 19:21:45 +00:00
|
|
|
this.bridge.off("allocations", this._onAllocations);
|
2015-04-28 17:32:32 +00:00
|
|
|
this.bridge.destroy();
|
2013-12-03 11:41:02 +00:00
|
|
|
protocol.Actor.prototype.destroy.call(this);
|
|
|
|
},
|
|
|
|
|
2016-06-10 20:28:15 +00:00
|
|
|
attach: actorBridgeWithSpec("attach"),
|
2014-07-30 09:47:00 +00:00
|
|
|
|
2016-06-10 20:28:15 +00:00
|
|
|
detach: actorBridgeWithSpec("detach"),
|
2014-07-30 09:47:00 +00:00
|
|
|
|
2016-06-10 20:28:15 +00:00
|
|
|
getState: actorBridgeWithSpec("getState"),
|
2015-03-05 17:19:57 +00:00
|
|
|
|
Bug 1261869 - Fix leaks in devtools; r=ejpbruel
There are two leaks addressed in this commit:
1. The thread actor's `_debuggerSourcesSeen` set was never cleared. This set
exists only as a performance optimization to speed up `_addSource` in cases
where we've already added the source. Unfortunately, this set wasn't getting
cleared when we cleared debuggees out and it ended up keeping the
`Debugger.Source`, its referent, and transitively its referent's global alive. I
figured it was simpler to make it a `WeakSet` than to add it as a special case
in `ThreadActor.prototype._clearDebuggees` and manage the lifetimes by hand. I
think this fits well with its intended use as an ephemeral performance
optimization.
2. Due to a logic error, we were not clearing debuggees in the memory actor's
`Debugger` instance on navigations. This isn't really a "proper" leak, in that
if you forced a GC, the old debuggees would go away as `Debugger` holds them
weakly, however if there was no GC between navigations, then you could still see
the old windows (and everything they "retained") as roots in the snapshot. This
issue is straightforward to fix once identified: ensure that `_clearDebuggees`
is actually called on navigation.
Finally, this commit adds a test that we don't leak Window objects when devtools
are open and we keep refreshing a tab. When it fails, it prints out the leaking
window's retaining paths.
2016-07-06 15:37:57 +00:00
|
|
|
saveHeapSnapshot: function (boundaries) {
|
|
|
|
return this.bridge.saveHeapSnapshot(boundaries);
|
2016-06-10 20:28:15 +00:00
|
|
|
},
|
2014-09-17 08:41:00 +00:00
|
|
|
|
2016-06-10 20:28:15 +00:00
|
|
|
takeCensus: actorBridgeWithSpec("takeCensus"),
|
2014-09-17 08:41:00 +00:00
|
|
|
|
2016-06-10 20:28:15 +00:00
|
|
|
startRecordingAllocations: actorBridgeWithSpec("startRecordingAllocations"),
|
2015-03-10 17:24:48 +00:00
|
|
|
|
2016-06-10 20:28:15 +00:00
|
|
|
stopRecordingAllocations: actorBridgeWithSpec("stopRecordingAllocations"),
|
2014-09-17 08:41:00 +00:00
|
|
|
|
2016-06-10 20:28:15 +00:00
|
|
|
getAllocationsSettings: actorBridgeWithSpec("getAllocationsSettings"),
|
2014-09-17 08:41:00 +00:00
|
|
|
|
2016-06-10 20:28:15 +00:00
|
|
|
getAllocations: actorBridgeWithSpec("getAllocations"),
|
2014-09-17 08:41:00 +00:00
|
|
|
|
2016-06-10 20:28:15 +00:00
|
|
|
forceGarbageCollection: actorBridgeWithSpec("forceGarbageCollection"),
|
2014-06-13 04:38:00 +00:00
|
|
|
|
2016-06-10 20:28:15 +00:00
|
|
|
forceCycleCollection: actorBridgeWithSpec("forceCycleCollection"),
|
|
|
|
|
|
|
|
measure: actorBridgeWithSpec("measure"),
|
|
|
|
|
|
|
|
residentUnique: actorBridgeWithSpec("residentUnique"),
|
2015-04-28 17:32:32 +00:00
|
|
|
|
|
|
|
_onGarbageCollection: function (data) {
|
2015-09-05 01:36:52 +00:00
|
|
|
if (this.conn.transport) {
|
2017-08-18 15:05:04 +00:00
|
|
|
this.emit("garbage-collection", data);
|
2015-09-05 01:36:52 +00:00
|
|
|
}
|
2015-04-28 17:32:32 +00:00
|
|
|
},
|
2015-07-17 19:21:45 +00:00
|
|
|
|
|
|
|
_onAllocations: function (data) {
|
2015-09-05 01:36:52 +00:00
|
|
|
if (this.conn.transport) {
|
2017-08-18 15:05:04 +00:00
|
|
|
this.emit("allocations", data);
|
2015-09-05 01:36:52 +00:00
|
|
|
}
|
2015-07-17 19:21:45 +00:00
|
|
|
},
|
2013-12-03 11:41:02 +00:00
|
|
|
});
|