From 4c941686627516f1de76b5da84126c2f2cc95d52 Mon Sep 17 00:00:00 2001 From: Matt Loring Date: Wed, 9 Dec 2015 11:37:51 -0800 Subject: [PATCH] tools: run tick processor without forking Using the tick processor no longer creates temporary files or spawns a child process. --- .eslintignore | 1 + lib/internal/v8_prof_polyfill.js | 28 ++++++++++++++------------ lib/internal/v8_prof_processor.js | 33 +++++++++---------------------- node.gyp | 1 - 4 files changed, 25 insertions(+), 38 deletions(-) diff --git a/.eslintignore b/.eslintignore index 507305bc8f0af2..e1376c84099aa2 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,4 +1,5 @@ lib/internal/v8_prof_polyfill.js +lib/internal/v8_prof_processor.js lib/punycode.js test/addons/doc-*/ test/fixtures diff --git a/lib/internal/v8_prof_polyfill.js b/lib/internal/v8_prof_polyfill.js index 1beae0e4e4b536..755f8f0d65d1fb 100644 --- a/lib/internal/v8_prof_polyfill.js +++ b/lib/internal/v8_prof_polyfill.js @@ -26,40 +26,42 @@ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // Node polyfill -var fs = require('fs'); -var os = { +const fs = require('fs'); +const cp = require('child_process'); +const os = { system: function(name, args) { if (process.platform === 'linux' && name === 'nm') { // Filter out vdso and vsyscall entries. - var arg = args[args.length - 1]; + const arg = args[args.length - 1]; if (arg === '[vdso]' || arg == '[vsyscall]' || /^[0-9a-f]+-[0-9a-f]+$/.test(arg)) { return ''; } + } else if (process.platform === 'darwin') { + args.unshift('-c', name); + name = '/bin/sh'; } - return require('child_process').execFileSync( - name, args, {encoding: 'utf8'}); + return cp.spawnSync(name, args).stdout.toString(); } }; -var print = console.log; +const print = console.log; function read(fileName) { return fs.readFileSync(fileName, 'utf8'); } -arguments = process.argv.slice(2); -var quit = process.exit; +const quit = process.exit; // Polyfill "readline()". -var logFile = arguments[arguments.length - 1]; +const logFile = arguments[arguments.length - 1]; try { fs.accessSync(logFile); } catch(e) { console.error('Please provide a valid isolate file as the final argument.'); process.exit(1); } -var fd = fs.openSync(logFile, 'r'); -var buf = new Buffer(4096); -var dec = new (require('string_decoder').StringDecoder)('utf-8'); +const fd = fs.openSync(logFile, 'r'); +const buf = new Buffer(4096); +const dec = new (require('string_decoder').StringDecoder)('utf-8'); var line = ''; versionCheck(); function readline() { @@ -85,7 +87,7 @@ function versionCheck() { var firstLine = readline(); line = firstLine + '\n' + line; firstLine = firstLine.split(','); - var curVer = process.versions.v8.split('.'); + const curVer = process.versions.v8.split('.'); if (firstLine.length !== 6 && firstLine[0] !== 'v8-version') { console.log('Unable to read v8-version from log file.'); return; diff --git a/lib/internal/v8_prof_processor.js b/lib/internal/v8_prof_processor.js index 543f977d4ae400..05452c18084938 100644 --- a/lib/internal/v8_prof_processor.js +++ b/lib/internal/v8_prof_processor.js @@ -1,9 +1,4 @@ -'use strict'; -var cp = require('child_process'); -var fs = require('fs'); -var path = require('path'); - -var scriptFiles = [ +const scriptFiles = [ 'internal/v8_prof_polyfill', 'v8/tools/splaytree', 'v8/tools/codemap', @@ -16,29 +11,19 @@ var scriptFiles = [ 'v8/tools/SourceMap', 'v8/tools/tickprocessor-driver' ]; -var tempScript = 'tick-processor-tmp-' + process.pid; -var tempNm = 'mac-nm-' + process.pid; +var script = ''; -process.on('exit', function() { - try { fs.unlinkSync(tempScript); } catch (e) {} - try { fs.unlinkSync(tempNm); } catch (e) {} -}); -process.on('uncaughtException', function(err) { - try { fs.unlinkSync(tempScript); } catch (e) {} - try { fs.unlinkSync(tempNm); } catch (e) {} - throw err; +scriptFiles.forEach(function(s) { + script += process.binding('natives')[s] + '\n'; }); -scriptFiles.forEach(function(script) { - fs.appendFileSync(tempScript, process.binding('natives')[script]); -}); -var tickArguments = [tempScript]; +var tickArguments = []; if (process.platform === 'darwin') { - fs.writeFileSync(tempNm, process.binding('natives')['v8/tools/mac-nm'], - { mode: 0o555 }); - tickArguments.push('--mac', '--nm=' + path.join(process.cwd(), tempNm)); + const nm = 'foo() { nm "$@" | (c++filt -p -i || cat) }; foo $@'; + tickArguments.push('--mac', '--nm=' + nm); } else if (process.platform === 'win32') { tickArguments.push('--windows'); } tickArguments.push.apply(tickArguments, process.argv.slice(1)); -cp.spawn(process.execPath, tickArguments, { stdio: 'inherit' }); +script = 'arguments = ' + JSON.stringify(tickArguments) + ';\n' + script; +eval(script); diff --git a/node.gyp b/node.gyp index 4f096f580ab1d7..672c3ce6691b9f 100644 --- a/node.gyp +++ b/node.gyp @@ -91,7 +91,6 @@ 'deps/v8/tools/tickprocessor.js', 'deps/v8/tools/SourceMap.js', 'deps/v8/tools/tickprocessor-driver.js', - 'deps/v8/tools/mac-nm', ], },