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_processor.js
lib/punycode.js
test/addons/doc-*/
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.
// 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;

33
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);

1
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',
],
},

Loading…
Cancel
Save