Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tickprocessor: pass proper arguments to /bin/sh #8480

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 32 additions & 4 deletions lib/internal/v8_prof_polyfill.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,12 @@ const os = {
/^[0-9a-f]+-[0-9a-f]+$/.test(arg)) {
return '';
}
} else if (process.platform === 'darwin') {
args.unshift('-c', name);
name = '/bin/sh';
}
return cp.spawnSync(name, args).stdout.toString();
let out = cp.spawnSync(name, args).stdout.toString();
// Auto c++filt names, but not [iItT]
if (process.platform === 'darwin' && name === 'nm')
out = macCppfiltNm(out);
return out;
}
};
const print = console.log;
Expand Down Expand Up @@ -100,3 +101,30 @@ function versionCheck() {
}
}
}

function macCppfiltNm(out) {
// Re-grouped copy-paste from `tickprocessor.js`
const FUNC_RE = /^([0-9a-fA-F]{8,16} [iItT] )(.*)$/gm;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a comment, just a note: this matches any hex digit string >= 8 && <= 16 characters long, not just strings of size 8 or 16. Ditto below.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a copy-paste from V8, but I agree with you. It doesn't matter that much in the end, though.

let entries = out.match(FUNC_RE);
if (entries === null)
return out;

entries = entries.map((entry) => {
return entry.replace(/^[0-9a-fA-F]{8,16} [iItT] /, '')
});

let filtered;
try {
filtered = cp.spawnSync('c++filt', [ '-p' , '-i' ], {
input: entries.join('\n')
}).stdout.toString();
} catch (e) {
return out;
}

let i = 0;
filtered = filtered.split(/\n/g);
return out.replace(FUNC_RE, (all, prefix, postfix) => {
return prefix + (filtered[i++] || postfix);
});
}
3 changes: 1 addition & 2 deletions lib/internal/v8_prof_processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ scriptFiles.forEach(function(s) {

var tickArguments = [];
if (process.platform === 'darwin') {
const nm = 'foo() { nm "$@" | (c++filt -p -i || cat) }; foo $@';
tickArguments.push('--mac', '--nm=' + nm);
tickArguments.push('--mac');
} else if (process.platform === 'win32') {
tickArguments.push('--windows');
}
Expand Down
8 changes: 8 additions & 0 deletions test/parallel/test-tick-processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ runTest(/RunInDebugContext/,
setTimeout(function() { process.exit(0); }, 2000);
f();`);

runTest(/Builtin_DateNow/,
`function f() {
this.ts = Date.now();
setImmediate(function() { new f(); });
};
setTimeout(function() { process.exit(0); }, 2000);
f();`);

function runTest(pattern, code) {
cp.execFileSync(process.execPath, ['-prof', '-pe', code]);
var matches = fs.readdirSync(common.tmpDir);
Expand Down