diff --git a/devtools/shared/heapsnapshot/HeapAnalysesClient.js b/devtools/shared/heapsnapshot/HeapAnalysesClient.js index b023bb73d4c9..8182e57cbf88 100644 --- a/devtools/shared/heapsnapshot/HeapAnalysesClient.js +++ b/devtools/shared/heapsnapshot/HeapAnalysesClient.js @@ -69,6 +69,9 @@ HeapAnalysesClient.prototype.readHeapSnapshot = function (snapshotFilePath) { * 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` + * - {Boolean} asInvertedTreeNode + * Whether or not the census is returned as an inverted + * CensusTreeNode. Defaults to false. * * @returns Promise * The report generated by the given census breakdown, or @@ -106,6 +109,9 @@ HeapAnalysesClient.prototype.takeCensus = function (snapshotFilePath, * - {Boolean} asTreeNode * Whether the resulting delta report should be converted to a census * tree node before returned. Defaults to false. + * - {Boolean} asInvertedTreeNode + * Whether or not the census is returned as an inverted + * CensusTreeNode. Defaults to false. * * @returns Promise * The delta report generated by diffing the two census reports, or a diff --git a/devtools/shared/heapsnapshot/HeapAnalysesWorker.js b/devtools/shared/heapsnapshot/HeapAnalysesWorker.js index 0f613408f86b..aebff40066dc 100644 --- a/devtools/shared/heapsnapshot/HeapAnalysesWorker.js +++ b/devtools/shared/heapsnapshot/HeapAnalysesWorker.js @@ -37,9 +37,14 @@ workerHelper.createTask(self, "takeCensus", ({ snapshotFilePath, censusOptions, } let report = snapshots[snapshotFilePath].takeCensus(censusOptions); - return requestOptions.asTreeNode - ? censusReportToCensusTreeNode(censusOptions.breakdown, report) - : report; + + if (requestOptions.asTreeNode) { + return censusReportToCensusTreeNode(censusOptions.breakdown, report); + } else if (requestOptions.asInvertedTreeNode) { + return censusReportToCensusTreeNode(censusOptions.breakdown, report, { invert: true }); + } else { + return report; + } }); /** @@ -65,7 +70,11 @@ workerHelper.createTask(self, "takeCensusDiff", request => { const second = snapshots[secondSnapshotFilePath].takeCensus(censusOptions); const delta = CensusUtils.diff(censusOptions.breakdown, first, second); - return requestOptions.asTreeNode - ? censusReportToCensusTreeNode(censusOptions.breakdown, delta) - : delta; + if (requestOptions.asTreeNode) { + return censusReportToCensusTreeNode(censusOptions.breakdown, delta); + } else if (requestOptions.asInvertedTreeNode) { + return censusReportToCensusTreeNode(censusOptions.breakdown, delta, { invert: true }); + } else { + return delta; + } }); diff --git a/devtools/shared/heapsnapshot/tests/unit/test_HeapAnalyses_takeCensusDiff_02.js b/devtools/shared/heapsnapshot/tests/unit/test_HeapAnalyses_takeCensusDiff_02.js new file mode 100644 index 000000000000..f676d3273069 --- /dev/null +++ b/devtools/shared/heapsnapshot/tests/unit/test_HeapAnalyses_takeCensusDiff_02.js @@ -0,0 +1,54 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Test that the HeapAnalyses{Client,Worker} can take diffs between censuses as +// inverted trees. + +function run_test() { + run_next_test(); +} + +const BREAKDOWN = { + by: "coarseType", + objects: { + by: "objectClass", + then: { by: "count", count: true, bytes: true }, + other: { by: "count", count: true, bytes: true }, + }, + scripts: { + by: "internalType", + then: { by: "count", count: true, bytes: true }, + }, + strings: { + by: "internalType", + then: { by: "count", count: true, bytes: true }, + }, + other: { + by: "internalType", + then: { by: "count", count: true, bytes: true }, + }, +}; + +add_task(function* () { + const firstSnapshotFilePath = saveNewHeapSnapshot(); + const secondSnapshotFilePath = saveNewHeapSnapshot(); + + const client = new HeapAnalysesClient(); + yield client.readHeapSnapshot(firstSnapshotFilePath); + yield client.readHeapSnapshot(secondSnapshotFilePath); + + ok(true, "Should have read both heap snapshot files"); + + const delta = yield client.takeCensusDiff(firstSnapshotFilePath, + secondSnapshotFilePath, + { breakdown: BREAKDOWN }); + + const deltaTreeNode = yield client.takeCensusDiff(firstSnapshotFilePath, + secondSnapshotFilePath, + { breakdown: BREAKDOWN }, + { asInvertedTreeNode: true }); + + compareCensusViewData(BREAKDOWN, delta, deltaTreeNode, { invert: true }); + + client.destroy(); +}); diff --git a/devtools/shared/heapsnapshot/tests/unit/test_HeapAnalyses_takeCensus_07.js b/devtools/shared/heapsnapshot/tests/unit/test_HeapAnalyses_takeCensus_07.js new file mode 100644 index 000000000000..6f5c3d184f0d --- /dev/null +++ b/devtools/shared/heapsnapshot/tests/unit/test_HeapAnalyses_takeCensus_07.js @@ -0,0 +1,52 @@ +/* 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 +// an inverted CensusTreeNode. + +function run_test() { + run_next_test(); +} + +const BREAKDOWN = { + by: "coarseType", + objects: { + by: "objectClass", + then: { by: "count", count: true, bytes: true }, + other: { by: "count", count: true, bytes: true }, + }, + scripts: { + by: "internalType", + then: { by: "count", count: true, bytes: true }, + }, + strings: { + by: "internalType", + then: { by: "count", count: true, bytes: true }, + }, + other: { + 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 + }, { + asInvertedTreeNode: true + }); + + compareCensusViewData(BREAKDOWN, report, treeNode, { invert: true }); + + client.destroy(); +}); diff --git a/devtools/shared/heapsnapshot/tests/unit/xpcshell.ini b/devtools/shared/heapsnapshot/tests/unit/xpcshell.ini index 9614985cf5b4..f81e4817693c 100644 --- a/devtools/shared/heapsnapshot/tests/unit/xpcshell.ini +++ b/devtools/shared/heapsnapshot/tests/unit/xpcshell.ini @@ -25,12 +25,14 @@ support-files = [test_census-tree-node-07.js] [test_HeapAnalyses_readHeapSnapshot_01.js] [test_HeapAnalyses_takeCensusDiff_01.js] +[test_HeapAnalyses_takeCensusDiff_02.js] [test_HeapAnalyses_takeCensus_01.js] [test_HeapAnalyses_takeCensus_02.js] [test_HeapAnalyses_takeCensus_03.js] [test_HeapAnalyses_takeCensus_04.js] [test_HeapAnalyses_takeCensus_05.js] [test_HeapAnalyses_takeCensus_06.js] +[test_HeapAnalyses_takeCensus_07.js] [test_HeapSnapshot_creationTime_01.js] [test_HeapSnapshot_takeCensus_01.js] [test_HeapSnapshot_takeCensus_02.js]