diff --git a/lib/internal/v8_prof_polyfill.js b/lib/internal/v8_prof_polyfill.js index 99096ba9e59ec5..821d36bb94ff20 100644 --- a/lib/internal/v8_prof_polyfill.js +++ b/lib/internal/v8_prof_polyfill.js @@ -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(); + var 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; @@ -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; + var entries = out.match(FUNC_RE); + if (entries === null) + return out; + + entries = entries.map((entry) => { + return entry.replace(/^[0-9a-fA-F]{8,16} [iItT] /, '') + }); + + var filtered; + try { + filtered = cp.spawnSync('c++filt', [ '-p' , '-i' ], { + input: entries.join('\n') + }).stdout.toString(); + } catch (e) { + return out; + } + + var i = 0; + filtered = filtered.split(/\n/g); + return out.replace(FUNC_RE, (all, prefix, postfix) => { + return prefix + (filtered[i++] || postfix); + }); +} diff --git a/lib/internal/v8_prof_processor.js b/lib/internal/v8_prof_processor.js index db5f400ed8febf..bbbe27b3e82892 100644 --- a/lib/internal/v8_prof_processor.js +++ b/lib/internal/v8_prof_processor.js @@ -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'); } diff --git a/test/parallel/test-tick-processor.js b/test/parallel/test-tick-processor.js index 40f086c898d651..b4b21d43471473 100644 --- a/test/parallel/test-tick-processor.js +++ b/test/parallel/test-tick-processor.js @@ -43,6 +43,14 @@ runTest(/RunInDebugContext/, setTimeout(function() { process.exit(0); }, 2000); f();`); +runTest(/Runtime_DateCurrentTime/, + `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);