Bug 1215955 - Add deleteSnapshot to HeapAnalysisWorker. r=fitzgen

This commit is contained in:
Julian Descottes 2016-01-12 10:41:17 +01:00
Родитель f7fa21edc4
Коммит eea767427d
6 изменённых файлов: 175 добавлений и 0 удалений

Просмотреть файл

@ -51,6 +51,17 @@ HeapAnalysesClient.prototype.readHeapSnapshot = function (snapshotFilePath) {
return this._worker.performTask("readHeapSnapshot", { snapshotFilePath });
};
/**
* Tell the worker to delete all references to the snapshot and dominator trees
* linked to the provided snapshot file path.
*
* @param {String} snapshotFilePath
* @return Promise<undefined>
*/
HeapAnalysesClient.prototype.deleteHeapSnapshot = function (snapshotFilePath) {
return this._worker.performTask("deleteHeapSnapshot", { snapshotFilePath });
};
/**
* Request the creation time given a snapshot file path. Returns `null`
* if snapshot does not exist.

Просмотреть файл

@ -32,6 +32,24 @@ workerHelper.createTask(self, "readHeapSnapshot", ({ snapshotFilePath }) => {
return true;
});
/**
* @see HeapAnalysesClient.prototype.deleteHeapSnapshot
*/
workerHelper.createTask(self, "deleteHeapSnapshot", ({ snapshotFilePath }) => {
let snapshot = snapshots[snapshotFilePath];
if (!snapshot) {
throw new Error(`No known heap snapshot for '${snapshotFilePath}'`);
}
snapshots[snapshotFilePath] = undefined;
let dominatorTreeId = dominatorTreeSnapshots.indexOf(snapshot);
if (dominatorTreeId != -1) {
dominatorTreeSnapshots[dominatorTreeId] = undefined;
dominatorTrees[dominatorTreeId] = undefined;
}
});
/**
* @see HeapAnalysesClient.prototype.takeCensus
*/

Просмотреть файл

@ -0,0 +1,59 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
// Test that the HeapAnalyses{Client,Worker} can delete heap snapshots.
function run_test() {
run_next_test();
}
const breakdown = {
by: "coarseType",
objects: { by: "count", count: true, bytes: true },
scripts: { by: "count", count: true, bytes: true },
strings: { by: "count", count: true, bytes: true },
other: { by: "count", count: true, bytes: true },
};
add_task(function* () {
const client = new HeapAnalysesClient();
const snapshotFilePath = saveNewHeapSnapshot();
yield client.readHeapSnapshot(snapshotFilePath);
ok(true, "Should have read the heap snapshot");
let dominatorTreeId = yield client.computeDominatorTree(snapshotFilePath);
ok(true, "Should have computed the dominator tree");
yield client.deleteHeapSnapshot(snapshotFilePath);
ok(true, "Should have deleted the snapshot");
let threw = false;
try {
yield client.getDominatorTree({
dominatorTreeId: dominatorTreeId,
breakdown
});
} catch (_) {
threw = true;
}
ok(threw, "getDominatorTree on deleted tree should throw an error");
threw = false;
try {
yield client.computeDominatorTree(snapshotFilePath);
} catch (_) {
threw = true;
}
ok(threw, "computeDominatorTree on deleted snapshot should throw an error");
threw = false;
try {
yield client.takeCensus(snapshotFilePath);
} catch (_) {
threw = true;
}
ok(threw, "takeCensus on deleted tree should throw an error");
client.destroy();
});

Просмотреть файл

@ -0,0 +1,22 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
// Test deleteHeapSnapshot is a noop if the provided path matches no snapshot
function run_test() {
run_next_test();
}
add_task(function* () {
const client = new HeapAnalysesClient();
let threw = false;
try {
yield client.deleteHeapSnapshot("path-does-not-exist");
} catch (_) {
threw = true;
}
ok(threw, "deleteHeapSnapshot on non-existant path should throw an error");
client.destroy();
});

Просмотреть файл

@ -0,0 +1,62 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
// Test other dominatorTrees can still be retrieved after deleting a snapshot
function run_test() {
run_next_test();
}
const breakdown = {
by: "coarseType",
objects: { by: "count", count: true, bytes: true },
scripts: { by: "count", count: true, bytes: true },
strings: { by: "count", count: true, bytes: true },
other: { by: "count", count: true, bytes: true },
};
function* createSnapshotAndDominatorTree(client) {
let snapshotFilePath = saveNewHeapSnapshot();
yield client.readHeapSnapshot(snapshotFilePath);
let dominatorTreeId = yield client.computeDominatorTree(snapshotFilePath);
return { dominatorTreeId, snapshotFilePath };
}
add_task(function* () {
const client = new HeapAnalysesClient();
let savedSnapshots = [
yield createSnapshotAndDominatorTree(client),
yield createSnapshotAndDominatorTree(client),
yield createSnapshotAndDominatorTree(client)
];
ok(true, "Create 3 snapshots and dominator trees");
yield client.deleteHeapSnapshot(savedSnapshots[1].snapshotFilePath);
ok(true, "Snapshot deleted");
let tree = yield client.getDominatorTree({
dominatorTreeId: savedSnapshots[0].dominatorTreeId,
breakdown
});
ok(tree, "Should get a valid tree for first snapshot");
let threw = false;
try {
yield client.getDominatorTree({
dominatorTreeId: savedSnapshots[1].dominatorTreeId,
breakdown
});
} catch (_) {
threw = true;
}
ok(threw, "getDominatorTree on a deleted snapshot should throw an error");
tree = yield client.getDominatorTree({
dominatorTreeId: savedSnapshots[2].dominatorTreeId,
breakdown
});
ok(tree, "Should get a valid tree for third snapshot");
client.destroy();
});

Просмотреть файл

@ -43,6 +43,9 @@ support-files =
[test_DominatorTreeNode_LabelAndShallowSize_04.js]
[test_HeapAnalyses_computeDominatorTree_01.js]
[test_HeapAnalyses_computeDominatorTree_02.js]
[test_HeapAnalyses_deleteHeapSnapshot_01.js]
[test_HeapAnalyses_deleteHeapSnapshot_02.js]
[test_HeapAnalyses_deleteHeapSnapshot_03.js]
[test_HeapAnalyses_getCreationTime_01.js]
[test_HeapAnalyses_getDominatorTree_01.js]
[test_HeapAnalyses_getDominatorTree_02.js]