Refactory of SamplingProfiler, CpuProfileGenerator and jscProfilerMiddleware

Reviewed By: cwdick

Differential Revision: D4251541

fbshipit-source-id: ccd221beadd87f6a8cf27a1d68ae06599cf54333
This commit is contained in:
Lukas Piatkowski 2016-12-01 09:37:24 -08:00 committed by Facebook Github Bot
parent 946913e9fa
commit 48b95f08fb
1 changed files with 33 additions and 3 deletions

View File

@ -17,6 +17,7 @@ const urlLib = require('url');
class TreeTransformator {
constructor() {
this.urlResults = {};
this.fakeNodeId = 1073741824;
}
transform(tree, callback) {
@ -25,6 +26,23 @@ class TreeTransformator {
});
}
// private
createFakeNode(name, id) {
return {
'functionName': name,
'scriptId': 0,
'url': '',
'lineNumber': 0,
'columnNumber': 0,
'hitCount': 0,
'callUID': id,
'children': [],
'deoptReason': 'fake_node',
'id': id,
'positionTicks': [],
};
}
// private
transformNode(tree) {
if (tree.url in this.urlResults) {
@ -32,7 +50,7 @@ class TreeTransformator {
line: tree.lineNumber,
column: tree.columnNumber,
});
tree.functionName = original.name
tree.functionName = tree.functionName || original.name
|| (path.posix.basename(original.source || '') + ':' + original.line);
tree.scriptId = tree.id;
tree.url = 'file://' + original.source;
@ -42,12 +60,24 @@ class TreeTransformator {
tree.functionName = 'OUTSIDE VM';
}
tree.children = tree.children.map((t) => this.transformNode(t));
if (tree.deoptReason.startsWith('host:')) {
// Creating a fake node to mark not doing JS, steal the id and hitCount
// of the original node
const fakeNode = this.createFakeNode('INSIDE VM', tree.id);
tree.id = tree.callUID = this.fakeNodeId++;
fakeNode.hitCount = tree.hitCount;
tree.hitCount = 0;
// Append the fake node to the tree
fakeNode.children = tree.children;
tree.children = [fakeNode];
}
return tree;
}
// private
afterUrlsCacheBuild(tree, callback) {
let urls = new Set();
const urls = new Set();
this.gatherUrls(tree, urls);
let size = urls.size;
@ -117,7 +147,7 @@ module.exports = function(req, res, next) {
}
console.log('Received request from JSC profiler, post processing it...');
let profile = JSON.parse(req.rawBody);
const profile = JSON.parse(req.rawBody);
(new TreeTransformator()).transform(profile.head, (newHead) => {
profile.head = newHead;