Bug 1224077 - Scope the boundaries of full runtime heap snapshots taken from the MemoryActor properly; r=jsantell

This commit is contained in:
Nick Fitzgerald 2015-11-13 11:46:07 -08:00
parent 3d9c03a346
commit bce6b70d39
4 changed files with 66 additions and 1 deletions

View File

@ -17,6 +17,10 @@ loader.lazyRequireGetter(this, "StackFrameCache",
loader.lazyRequireGetter(this, "ThreadSafeChromeUtils");
loader.lazyRequireGetter(this, "HeapSnapshotFileUtils",
"devtools/shared/heapsnapshot/HeapSnapshotFileUtils");
loader.lazyRequireGetter(this, "ChromeActor", "devtools/server/actors/chrome",
true);
loader.lazyRequireGetter(this, "ChildProcessActor",
"devtools/server/actors/child-process", true);
/**
* A class that returns memory data for a parent actor's window.
@ -139,7 +143,12 @@ var Memory = exports.Memory = Class({
* @returns {String} The snapshot id.
*/
saveHeapSnapshot: expectState("attached", function () {
const path = ThreadSafeChromeUtils.saveHeapSnapshot({ debugger: this.dbg });
// If we are observing the whole process, then scope the snapshot
// accordingly. Otherwise, use the debugger's debuggees.
const opts = this.parent instanceof ChromeActor || this.parent instanceof ChildProcessActor
? { runtime: true }
: { debugger: this.dbg };
const path = ThreadSafeChromeUtils.saveHeapSnapshot(opts);
return HeapSnapshotFileUtils.getSnapshotIdFromPath(path);
}, "saveHeapSnapshot"),

View File

@ -82,6 +82,45 @@ function makeMemoryActorTest(testGeneratorFunction) {
};
}
/**
* Save as makeMemoryActorTest but attaches the MemoryFront to the MemoryActor
* scoped to the full runtime rather than to a tab.
*/
function makeFullRuntimeMemoryActorTest(testGeneratorFunction) {
return function run_test() {
do_test_pending();
startTestDebuggerServer("test_MemoryActor").then(client => {
DebuggerServer.registerModule("devtools/server/actors/heap-snapshot-file", {
prefix: "heapSnapshotFile",
constructor: "HeapSnapshotFileActor",
type: { global: true }
});
getChromeActors(client).then(function (form) {
if (!form) {
ok(false, "Could not attach to chrome actors");
return;
}
Task.spawn(function* () {
try {
const rootForm = yield listTabs(client);
const memoryFront = new MemoryFront(client, form, rootForm);
yield memoryFront.attach();
yield* testGeneratorFunction(client, memoryFront);
yield memoryFront.detach();
} catch(err) {
DevToolsUtils.reportException("makeMemoryActorTest", err);
ok(false, "Got an error: " + err);
}
finishClient(client);
});
});
});
};
}
function createTestGlobal(name) {
let sandbox = Cu.Sandbox(
Cc["@mozilla.org/systemprincipal;1"].createInstance(Ci.nsIPrincipal)

View File

@ -0,0 +1,16 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
// Test that we can save full runtime heap snapshots when attached to the
// ChromeActor or a ChildProcessActor.
Cu.import("resource://gre/modules/osfile.jsm");
const run_test = makeFullRuntimeMemoryActorTest(function* (client, memoryFront) {
const snapshotFilePath = yield memoryFront.saveHeapSnapshot();
ok(!!(yield OS.File.stat(snapshotFilePath)),
"Should have the heap snapshot file");
const snapshot = ThreadSafeChromeUtils.readHeapSnapshot(snapshotFilePath);
ok(snapshot instanceof HeapSnapshot,
"And we should be able to read a HeapSnapshot instance from the file");
});

View File

@ -47,6 +47,7 @@ support-files =
[test_attach.js]
[test_MemoryActor_saveHeapSnapshot_01.js]
[test_MemoryActor_saveHeapSnapshot_02.js]
[test_MemoryActor_saveHeapSnapshot_03.js]
[test_reattach-thread.js]
[test_blackboxing-01.js]
[test_blackboxing-02.js]