Bug 1217495 - HeapAnalyses{Client,Worker} should support requests for inverted trees; r=jsantell
authorNick Fitzgerald <fitzgen@gmail.com>
Thu, 22 Oct 2015 13:43:30 -0700
changeset 304250 54f1ea8304351e6f5db86cec4ffce4739c094fc2
parent 304194 0e104df4b5e921276668c761b3d8922e8dd5d614
child 304251 045a0eb88d6aa83ea332d5ba01f83cca791ce13c
push id1001
push userraliiev@mozilla.com
push dateMon, 18 Jan 2016 19:06:03 +0000
treeherdermozilla-release@8b89261f3ac4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjsantell
bugs1217495
milestone44.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1217495 - HeapAnalyses{Client,Worker} should support requests for inverted trees; r=jsantell
devtools/shared/heapsnapshot/HeapAnalysesClient.js
devtools/shared/heapsnapshot/HeapAnalysesWorker.js
devtools/shared/heapsnapshot/tests/unit/test_HeapAnalyses_takeCensusDiff_02.js
devtools/shared/heapsnapshot/tests/unit/test_HeapAnalyses_takeCensus_07.js
devtools/shared/heapsnapshot/tests/unit/xpcshell.ini
--- a/devtools/shared/heapsnapshot/HeapAnalysesClient.js
+++ b/devtools/shared/heapsnapshot/HeapAnalysesClient.js
@@ -64,16 +64,19 @@ HeapAnalysesClient.prototype.readHeapSna
  *        `js/src/doc/Debugger/Debugger.Memory.md` for detailed documentation.
  *
  * @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`
+ *        - {Boolean} asInvertedTreeNode
+ *          Whether or not the census is returned as an inverted
+ *          CensusTreeNode. Defaults to false.
  *
  * @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,
@@ -101,16 +104,19 @@ HeapAnalysesClient.prototype.takeCensus 
  *        breakdown. See the "takeCensus" section of
  *        `js/src/doc/Debugger/Debugger.Memory.md` for detailed documentation.
  *
  * @param {Object} requestOptions
  *        An object specifying options for this request.
  *        - {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<delta report|CensusTreeNode>
  *          The delta report generated by diffing the two census reports, or a
  *          CensusTreeNode generated from the delta report if
  *          `requestOptions.asTreeNode` was true.
  */
 HeapAnalysesClient.prototype.takeCensusDiff = function (firstSnapshotFilePath,
                                                         secondSnapshotFilePath,
--- a/devtools/shared/heapsnapshot/HeapAnalysesWorker.js
+++ b/devtools/shared/heapsnapshot/HeapAnalysesWorker.js
@@ -32,19 +32,24 @@ workerHelper.createTask(self, "readHeapS
  * @see HeapAnalysesClient.prototype.takeCensus
  */
 workerHelper.createTask(self, "takeCensus", ({ snapshotFilePath, censusOptions, requestOptions }) => {
   if (!snapshots[snapshotFilePath]) {
     throw new Error(`No known heap snapshot for '${snapshotFilePath}'`);
   }
 
   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;
+  }
 });
 
 /**
  * @see HeapAnalysesClient.prototype.takeCensusDiff
  */
 workerHelper.createTask(self, "takeCensusDiff", request => {
   const {
     firstSnapshotFilePath,
@@ -60,12 +65,16 @@ workerHelper.createTask(self, "takeCensu
   if (!snapshots[secondSnapshotFilePath]) {
     throw new Error(`No known heap snapshot for '${secondSnapshotFilePath}'`);
   }
 
   const first = snapshots[firstSnapshotFilePath].takeCensus(censusOptions);
   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;
+  }
 });
new file mode 100644
--- /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();
+});
new file mode 100644
--- /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();
+});
--- a/devtools/shared/heapsnapshot/tests/unit/xpcshell.ini
+++ b/devtools/shared/heapsnapshot/tests/unit/xpcshell.ini
@@ -20,22 +20,24 @@ support-files =
 [test_census-tree-node-02.js]
 [test_census-tree-node-03.js]
 [test_census-tree-node-04.js]
 [test_census-tree-node-05.js]
 [test_census-tree-node-06.js]
 [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]
 [test_HeapSnapshot_takeCensus_03.js]
 [test_HeapSnapshot_takeCensus_04.js]
 [test_HeapSnapshot_takeCensus_05.js]
 [test_HeapSnapshot_takeCensus_06.js]
 [test_HeapSnapshot_takeCensus_07.js]