зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1260590 - Add the `CensusUtils.getCensusIndividuals` utility; r=jimb a=kwierso
This commit adds the `getCensusIndividuals` utility for getting the individual node IDs that match the census leaves specified by the given indices in a pre-order depth-first traversal of a census report generated with the given breakdown. MozReview-Commit-ID: A4IRcP82iCC --HG-- extra : histedit_source : e48cc59b522ce82f649f077b4686cea4715980f1
This commit is contained in:
Родитель
546829d13e
Коммит
c4c900965c
|
@ -1,6 +1,9 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
"use strict";
|
||||
|
||||
const { flatten } = require("resource://devtools/shared/ThreadSafeDevToolsUtils.js");
|
||||
|
||||
/*** Visitor ****************************************************************/
|
||||
|
||||
|
@ -65,6 +68,10 @@ EDGES.count = function (breakdown, report) {
|
|||
return [];
|
||||
};
|
||||
|
||||
EDGES.bucket = function (breakdown, report) {
|
||||
return [];
|
||||
};
|
||||
|
||||
EDGES.internalType = function (breakdown, report) {
|
||||
return Object.keys(report).map(key => ({
|
||||
edge: key,
|
||||
|
@ -461,3 +468,22 @@ exports.getReportLeaves = function(indices, breakdown, report) {
|
|||
walk(breakdown, report, visitor);
|
||||
return visitor.leaves();
|
||||
};
|
||||
|
||||
/**
|
||||
* Get a list of the individual node IDs that belong to the census report leaves
|
||||
* of the given indices.
|
||||
*
|
||||
* @param {Set<Number>} indices
|
||||
* @param {Object} breakdown
|
||||
* @param {HeapSnapshot} snapshot
|
||||
*
|
||||
* @returns {Array<NodeId>}
|
||||
*/
|
||||
exports.getCensusIndividuals = function(indices, countBreakdown, snapshot) {
|
||||
const bucketBreakdown = exports.countToBucketBreakdown(countBreakdown);
|
||||
const bucketReport = snapshot.takeCensus({ breakdown: bucketBreakdown });
|
||||
const buckets = exports.getReportLeaves(indices,
|
||||
bucketBreakdown,
|
||||
bucketReport);
|
||||
return flatten(buckets);
|
||||
};
|
||||
|
|
|
@ -0,0 +1,60 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
"use strict";
|
||||
|
||||
// Test basic functionality of `CensusUtils.getCensusIndividuals`.
|
||||
|
||||
function run_test() {
|
||||
const stack1 = saveStack(1);
|
||||
const stack2 = saveStack(1);
|
||||
const stack3 = saveStack(1);
|
||||
|
||||
const COUNT = { by: "count", count: true, bytes: true };
|
||||
const INTERNAL_TYPE = { by: "internalType", then: COUNT };
|
||||
|
||||
const BREAKDOWN = {
|
||||
by: "allocationStack",
|
||||
then: INTERNAL_TYPE,
|
||||
noStack: INTERNAL_TYPE,
|
||||
};
|
||||
|
||||
const MOCK_SNAPSHOT = {
|
||||
takeCensus: ({ breakdown }) => {
|
||||
assertStructurallyEquivalent(
|
||||
breakdown,
|
||||
CensusUtils.countToBucketBreakdown(BREAKDOWN));
|
||||
|
||||
// DFS Index
|
||||
return new Map([ // 0
|
||||
[stack1, { // 1
|
||||
JSObject: [101, 102, 103], // 2
|
||||
JSString: [111, 112, 113], // 3
|
||||
}],
|
||||
[stack2, { // 4
|
||||
JSObject: [201, 202, 203], // 5
|
||||
JSString: [211, 212, 213], // 6
|
||||
}],
|
||||
[stack3, { // 7
|
||||
JSObject: [301, 302, 303], // 8
|
||||
JSString: [311, 312, 313], // 9
|
||||
}],
|
||||
["noStack", { // 10
|
||||
JSObject: [401, 402, 403], // 11
|
||||
JSString: [411, 412, 413], // 12
|
||||
}],
|
||||
]);
|
||||
}
|
||||
};
|
||||
|
||||
const INDICES = new Set([3, 5, 9]);
|
||||
|
||||
const EXPECTED = new Set([111, 112, 113,
|
||||
201, 202, 203,
|
||||
311, 312, 313]);
|
||||
|
||||
const actual = new Set(CensusUtils.getCensusIndividuals(INDICES,
|
||||
BREAKDOWN,
|
||||
MOCK_SNAPSHOT));
|
||||
|
||||
assertStructurallyEquivalent(EXPECTED, actual);
|
||||
}
|
|
@ -50,6 +50,7 @@ support-files =
|
|||
[test_DominatorTreeNode_LabelAndShallowSize_03.js]
|
||||
[test_DominatorTreeNode_LabelAndShallowSize_04.js]
|
||||
[test_DominatorTreeNode_partialTraversal_01.js]
|
||||
[test_getCensusIndividuals_01.js]
|
||||
[test_getReportLeaves_01.js]
|
||||
[test_HeapAnalyses_computeDominatorTree_01.js]
|
||||
[test_HeapAnalyses_computeDominatorTree_02.js]
|
||||
|
|
Загрузка…
Ссылка в новой задаче