Browse Source

tools: run tick processor without forking

Using the tick processor no longer creates temporary files or spawns a
child process.

PR-URL: https://github.com/nodejs/node/pull/4224
Reviewed-By: bnoordhuis - Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: jasnell - James M Snell <jasnell@gmail.com>
process-exit-stdio-flushing
Matt Loring 9 years ago
committed by Ali Ijaz Sheikh
parent
commit
3e2a2e6efa
  1. 1
      .eslintignore
  2. 28
      lib/internal/v8_prof_polyfill.js
  3. 33
      lib/internal/v8_prof_processor.js
  4. 1
      node.gyp

1
.eslintignore

@ -1,4 +1,5 @@
lib/internal/v8_prof_polyfill.js lib/internal/v8_prof_polyfill.js
lib/internal/v8_prof_processor.js
lib/punycode.js lib/punycode.js
test/addons/doc-*/ test/addons/doc-*/
test/fixtures test/fixtures

28
lib/internal/v8_prof_polyfill.js

@ -26,40 +26,42 @@
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Node polyfill // Node polyfill
var fs = require('fs'); const fs = require('fs');
var os = { const cp = require('child_process');
const os = {
system: function(name, args) { system: function(name, args) {
if (process.platform === 'linux' && name === 'nm') { if (process.platform === 'linux' && name === 'nm') {
// Filter out vdso and vsyscall entries. // Filter out vdso and vsyscall entries.
var arg = args[args.length - 1]; const arg = args[args.length - 1];
if (arg === '[vdso]' || if (arg === '[vdso]' ||
arg == '[vsyscall]' || arg == '[vsyscall]' ||
/^[0-9a-f]+-[0-9a-f]+$/.test(arg)) { /^[0-9a-f]+-[0-9a-f]+$/.test(arg)) {
return ''; return '';
} }
} else if (process.platform === 'darwin') {
args.unshift('-c', name);
name = '/bin/sh';
} }
return require('child_process').execFileSync( return cp.spawnSync(name, args).stdout.toString();
name, args, {encoding: 'utf8'});
} }
}; };
var print = console.log; const print = console.log;
function read(fileName) { function read(fileName) {
return fs.readFileSync(fileName, 'utf8'); return fs.readFileSync(fileName, 'utf8');
} }
arguments = process.argv.slice(2); const quit = process.exit;
var quit = process.exit;
// Polyfill "readline()". // Polyfill "readline()".
var logFile = arguments[arguments.length - 1]; const logFile = arguments[arguments.length - 1];
try { try {
fs.accessSync(logFile); fs.accessSync(logFile);
} catch(e) { } catch(e) {
console.error('Please provide a valid isolate file as the final argument.'); console.error('Please provide a valid isolate file as the final argument.');
process.exit(1); process.exit(1);
} }
var fd = fs.openSync(logFile, 'r'); const fd = fs.openSync(logFile, 'r');
var buf = new Buffer(4096); const buf = new Buffer(4096);
var dec = new (require('string_decoder').StringDecoder)('utf-8'); const dec = new (require('string_decoder').StringDecoder)('utf-8');
var line = ''; var line = '';
versionCheck(); versionCheck();
function readline() { function readline() {
@ -85,7 +87,7 @@ function versionCheck() {
var firstLine = readline(); var firstLine = readline();
line = firstLine + '\n' + line; line = firstLine + '\n' + line;
firstLine = firstLine.split(','); firstLine = firstLine.split(',');
var curVer = process.versions.v8.split('.'); const curVer = process.versions.v8.split('.');
if (firstLine.length !== 6 && firstLine[0] !== 'v8-version') { if (firstLine.length !== 6 && firstLine[0] !== 'v8-version') {
console.log('Unable to read v8-version from log file.'); console.log('Unable to read v8-version from log file.');
return; return;

33
lib/internal/v8_prof_processor.js

@ -1,9 +1,4 @@
'use strict'; const scriptFiles = [
var cp = require('child_process');
var fs = require('fs');
var path = require('path');
var scriptFiles = [
'internal/v8_prof_polyfill', 'internal/v8_prof_polyfill',
'v8/tools/splaytree', 'v8/tools/splaytree',
'v8/tools/codemap', 'v8/tools/codemap',
@ -16,29 +11,19 @@ var scriptFiles = [
'v8/tools/SourceMap', 'v8/tools/SourceMap',
'v8/tools/tickprocessor-driver' 'v8/tools/tickprocessor-driver'
]; ];
var tempScript = 'tick-processor-tmp-' + process.pid; var script = '';
var tempNm = 'mac-nm-' + process.pid;
process.on('exit', function() { scriptFiles.forEach(function(s) {
try { fs.unlinkSync(tempScript); } catch (e) {} script += process.binding('natives')[s] + '\n';
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(script) { var tickArguments = [];
fs.appendFileSync(tempScript, process.binding('natives')[script]);
});
var tickArguments = [tempScript];
if (process.platform === 'darwin') { if (process.platform === 'darwin') {
fs.writeFileSync(tempNm, process.binding('natives')['v8/tools/mac-nm'], const nm = 'foo() { nm "$@" | (c++filt -p -i || cat) }; foo $@';
{ mode: 0o555 }); tickArguments.push('--mac', '--nm=' + nm);
tickArguments.push('--mac', '--nm=' + path.join(process.cwd(), tempNm));
} else if (process.platform === 'win32') { } else if (process.platform === 'win32') {
tickArguments.push('--windows'); tickArguments.push('--windows');
} }
tickArguments.push.apply(tickArguments, process.argv.slice(1)); tickArguments.push.apply(tickArguments, process.argv.slice(1));
cp.spawn(process.execPath, tickArguments, { stdio: 'inherit' }); script = 'arguments = ' + JSON.stringify(tickArguments) + ';\n' + script;
eval(script);

1
node.gyp

@ -91,7 +91,6 @@
'deps/v8/tools/tickprocessor.js', 'deps/v8/tools/tickprocessor.js',
'deps/v8/tools/SourceMap.js', 'deps/v8/tools/SourceMap.js',
'deps/v8/tools/tickprocessor-driver.js', 'deps/v8/tools/tickprocessor-driver.js',
'deps/v8/tools/mac-nm',
], ],
}, },

Loading…
Cancel
Save