Skip to content

Commit

Permalink
JSC Heap Capture add other roots to visualization
Browse files Browse the repository at this point in the history
Reviewed By: amnn

Differential Revision: D4422659

fbshipit-source-id: a32e87d2d39b6ff571f02d613b32db630e5e6de1
  • Loading branch information
cwdick authored and facebook-github-bot committed Jan 26, 2017
1 parent 0fc62ee commit 936c62a
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 26 deletions.
67 changes: 53 additions & 14 deletions local-cli/server/middleware/heapCapture/bundle.js

Large diffs are not rendered by default.

42 changes: 30 additions & 12 deletions local-cli/server/middleware/heapCapture/src/heapCapture.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,17 +263,7 @@ function markModules(refs) {
});
}

function registerPathToRoot(refs, registry, strings) {
markReactComponentTree(refs, registry, strings);
markModules(refs);
let breadth = [];
forEachRef(refs, (visitor) => {
const ref = visitor.getRef();
if (ref.type === 'CallbackGlobalObject') {
ref.rootPath = registry.insert(registry.root, strings.intern(ref.type));
breadth.push(visitor.clone());
}
});
function registerPathToRootBFS(breadth, registry, strings) {
while (breadth.length > 0) {
const nextBreadth = [];
for (let i = 0; i < breadth.length; i++) {
Expand Down Expand Up @@ -302,6 +292,34 @@ function registerPathToRoot(refs, registry, strings) {
}
}

function registerPathToRoot(capture, registry, strings) {
const refs = capture.refs;
const roots = capture.roots;
markReactComponentTree(refs, registry, strings);
markModules(refs);
let breadth = [];
// BFS from global objects first
forEachRef(refs, (visitor) => {
const ref = visitor.getRef();
if (ref.type === 'CallbackGlobalObject') {
ref.rootPath = registry.insert(registry.root, strings.intern(ref.type));
breadth.push(visitor.clone());
}
});
registerPathToRootBFS(breadth, registry, strings);
breadth = [];
// lower priority, BFS from other roots
for (const id of roots) {
const visitor = new RefVisitor(refs, id);
const ref = visitor.getRef();
if (ref.rootPath === undefined) {
ref.rootPath = registry.insert(registry.root, strings.intern(`root ${id}: ${ref.type}`));
breadth.push(visitor.clone());
}
}
registerPathToRootBFS(breadth, registry, strings);
}

function registerCapture(data, captureId, capture, stacks, strings) {
// NB: capture.refs is potentially VERY large, so we try to avoid making
// copies, even if iteration is a bit more annoying.
Expand All @@ -313,7 +331,7 @@ function registerCapture(data, captureId, capture, stacks, strings) {
rowCount++;
}
const inserter = data.rowInserter(rowCount);
registerPathToRoot(capture.refs, stacks, strings);
registerPathToRoot(capture, stacks, strings);
const noneString = strings.intern('#none');
const noneStack = stacks.insert(stacks.root, noneString);
forEachRef(capture.refs, (visitor) => {
Expand Down

0 comments on commit 936c62a

Please sign in to comment.