Skip to content

Commit

Permalink
tools: run tick processor without forking
Browse files Browse the repository at this point in the history
Using the tick processor no longer creates temporary files or spawns a
child process.

PR-URL: #4224
Reviewed-By: bnoordhuis - Ben Noordhuis <[email protected]>
Reviewed-By: jasnell - James M Snell <[email protected]>
  • Loading branch information
Matt Loring authored and Myles Borins committed Mar 1, 2016
1 parent 70d8827 commit cebe3b9
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 38 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
lib/internal/v8_prof_polyfill.js
lib/internal/v8_prof_processor.js
lib/punycode.js
test/addons/??_*/
test/fixtures
Expand Down
28 changes: 15 additions & 13 deletions lib/internal/v8_prof_polyfill.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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;
Expand Down
33 changes: 9 additions & 24 deletions lib/internal/v8_prof_processor.js
Original file line number Diff line number Diff line change
@@ -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',
Expand All @@ -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 change: 0 additions & 1 deletion node.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@
'deps/v8/tools/tickprocessor.js',
'deps/v8/tools/SourceMap.js',
'deps/v8/tools/tickprocessor-driver.js',
'deps/v8/tools/mac-nm',
],
},

Expand Down

0 comments on commit cebe3b9

Please sign in to comment.