Bug 1214231 - Provide an option to generate census tree nodes in a worker when taking a census. r=fitzgen

This commit is contained in:
Jordan Santell 2015-10-13 14:30:40 -07:00
parent 3ad5426b56
commit c4ed200669
4 changed files with 65 additions and 6 deletions

View File

@ -63,13 +63,24 @@ HeapAnalysesClient.prototype.readHeapSnapshot = function (snapshotFilePath) {
* breakdown. See the "takeCensus" section of
* `js/src/doc/Debugger/Debugger.Memory.md` for detailed documentation.
*
* @returns Promise<census report>
* The report generated by the given census breakdown.
* @param {Object} requestOptions
* An object specifying options of this worker request.
* - {Boolean} asTreeNode
* Whether or not the census is returned as a CensusTreeNode,
* or just a breakdown report. Defaults to false.
* @see `devtools/shared/heapsnapshot/census-tree-node.js`
*
* @returns Promise<census report|CensusTreeNode>
* The report generated by the given census breakdown, or
* a CensusTreeNode generated by the given census breakdown
* if `asTreeNode` is true.
*/
HeapAnalysesClient.prototype.takeCensus = function (snapshotFilePath,
censusOptions) {
censusOptions={},
requestOptions={}) {
return this._worker.performTask("takeCensus", {
snapshotFilePath,
censusOptions
censusOptions,
requestOptions,
});
};

View File

@ -10,7 +10,9 @@
"use strict";
importScripts("resource://gre/modules/workers/require.js");
importScripts("resource://gre/modules/devtools/shared/worker/helper.js");
const { CensusTreeNode } = require("resource://gre/modules/devtools/shared/heapsnapshot/census-tree-node.js");
// The set of HeapSnapshot instances this worker has read into memory. Keyed by
// snapshot file path.
@ -28,10 +30,11 @@ workerHelper.createTask(self, "readHeapSnapshot", ({ snapshotFilePath }) => {
/**
* @see HeapAnalysesClient.prototype.takeCensus
*/
workerHelper.createTask(self, "takeCensus", ({ snapshotFilePath, censusOptions }) => {
workerHelper.createTask(self, "takeCensus", ({ snapshotFilePath, censusOptions, requestOptions }) => {
if (!snapshots[snapshotFilePath]) {
throw new Error(`No known heap snapshot for '${snapshotFilePath}'`);
}
return snapshots[snapshotFilePath].takeCensus(censusOptions);
let report = snapshots[snapshotFilePath].takeCensus(censusOptions);
return requestOptions.asTreeNode ? new CensusTreeNode(censusOptions.breakdown, report) : report;
});

View File

@ -0,0 +1,44 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
// Test that the HeapAnalyses{Client,Worker} can take censuses and return
// a CensusTreeNode.
function run_test() {
run_next_test();
}
const BREAKDOWN = {
by: "internalType",
then: { 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");
const report = yield client.takeCensus(snapshotFilePath, {
breakdown: BREAKDOWN
});
const treeNode = yield client.takeCensus(snapshotFilePath, {
breakdown: BREAKDOWN
}, {
asTreeNode: true
});
ok(treeNode.children.length > 0, "treeNode has children");
ok(treeNode.children.every(type => {
return "name" in type &&
"bytes" in type &&
"count" in type;
}), "all of tree node's children have name, bytes, count");
compareCensusViewData(BREAKDOWN, report, treeNode,
"Returning census as a tree node represents same data as the report");
client.destroy();
});

View File

@ -17,6 +17,7 @@ support-files =
[test_HeapAnalyses_takeCensus_02.js]
[test_HeapAnalyses_takeCensus_03.js]
[test_HeapAnalyses_takeCensus_04.js]
[test_HeapAnalyses_takeCensus_05.js]
[test_HeapSnapshot_takeCensus_01.js]
[test_HeapSnapshot_takeCensus_02.js]
[test_HeapSnapshot_takeCensus_03.js]