Skip to content

Commit

Permalink
Change how values are captured in JSC heap snapshots
Browse files Browse the repository at this point in the history
Reviewed By: dcaspi

Differential Revision: D3757449

fbshipit-source-id: 9952f7ffb9b725ad3e0e3ca0b13b02d2d469bb95
  • Loading branch information
cwdick authored and Facebook Github Bot 7 committed Sep 2, 2016
1 parent 00d6587 commit a0f55c9
Showing 1 changed file with 24 additions and 16 deletions.
40 changes: 24 additions & 16 deletions local-cli/server/middleware/heapCaptureMiddleware.js
Expand Up @@ -66,7 +66,10 @@ function getSourceMapsForCapture(capture, onFailure, onSuccess) {
const sourcemaps = new Map();
for (const id in capture.refs) {
const ref = capture.refs[id];
if (ref.type === 'Function' && ref.value && !!ref.value.url) {
if ((ref.type === 'ScriptExecutable' ||
ref.type === 'EvalExecutable' ||
ref.type === 'ProgramExecutable' ||
ref.type === 'FunctionExecutable') && ref.value.url) {
urls.add(ref.value.url);
}
}
Expand All @@ -88,24 +91,29 @@ function getSourceMapsForCapture(capture, onFailure, onSuccess) {
// capture: capture object
// onSuccess: function (capture object)
// onFailure: function (string)
function symbolocateHeapCaptureFunctions(capture, onFailure, onSuccess) {
function symbolicateHeapCaptureFunctions(capture, onFailure, onSuccess) {
getSourceMapsForCapture(capture, onFailure, (sourcemaps) => {
for (const id in capture.refs) {
const ref = capture.refs[id];
if (ref.type === 'Function' && ref.value && !!ref.value.url) {
if (ref.type === 'ScriptExecutable' ||
ref.type === 'EvalExecutable' ||
ref.type === 'ProgramExecutable' ||
ref.type === 'FunctionExecutable') {
const sourcemap = sourcemaps.get(ref.value.url);
const original = sourcemap.originalPositionFor({
line: ref.value.line,
column: ref.value.col,
});
if (original.name) {
ref.value.name = original.name;
} else if (!ref.value.name) {
ref.value.name = path.posix.basename(original.source) + ':' + original.line;
if (sourcemap) {
const original = sourcemap.originalPositionFor({
line: ref.value.line,
column: ref.value.col,
});
if (original.name) {
ref.value.name = original.name;
} else if (!ref.value.name) {
ref.value.name = path.posix.basename(original.source) + ':' + original.line;
}
ref.value.url = original.source;
ref.value.line = original.line;
ref.value.col = original.column;
}
ref.value.url = 'file://' + original.source;
ref.value.line = original.line;
ref.value.col = original.column;
}
}
onSuccess(capture);
Expand All @@ -118,8 +126,8 @@ module.exports = function(req, res, next) {
return;
}

console.log('Symbolocating Heap Capture');
symbolocateHeapCaptureFunctions(JSON.parse(req.rawBody), (err) => {
console.log('symbolicating Heap Capture');
symbolicateHeapCaptureFunctions(JSON.parse(req.rawBody), (err) => {
console.error('Error when symbolicating: ' + err);
},
(capture) => {
Expand Down

0 comments on commit a0f55c9

Please sign in to comment.