Skip to content

Commit cebe3b9

Browse files
Matt LoringMyles Borins
Matt Loring
authored and
Myles Borins
committed
tools: run tick processor without forking
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]>
1 parent 70d8827 commit cebe3b9

File tree

4 files changed

+25
-38
lines changed

4 files changed

+25
-38
lines changed

.eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
lib/internal/v8_prof_polyfill.js
2+
lib/internal/v8_prof_processor.js
23
lib/punycode.js
34
test/addons/??_*/
45
test/fixtures

lib/internal/v8_prof_polyfill.js

+15-13
Original file line numberDiff line numberDiff line change
@@ -26,40 +26,42 @@
2626
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2727

2828
// Node polyfill
29-
var fs = require('fs');
30-
var os = {
29+
const fs = require('fs');
30+
const cp = require('child_process');
31+
const os = {
3132
system: function(name, args) {
3233
if (process.platform === 'linux' && name === 'nm') {
3334
// Filter out vdso and vsyscall entries.
34-
var arg = args[args.length - 1];
35+
const arg = args[args.length - 1];
3536
if (arg === '[vdso]' ||
3637
arg == '[vsyscall]' ||
3738
/^[0-9a-f]+-[0-9a-f]+$/.test(arg)) {
3839
return '';
3940
}
41+
} else if (process.platform === 'darwin') {
42+
args.unshift('-c', name);
43+
name = '/bin/sh';
4044
}
41-
return require('child_process').execFileSync(
42-
name, args, {encoding: 'utf8'});
45+
return cp.spawnSync(name, args).stdout.toString();
4346
}
4447
};
45-
var print = console.log;
48+
const print = console.log;
4649
function read(fileName) {
4750
return fs.readFileSync(fileName, 'utf8');
4851
}
49-
arguments = process.argv.slice(2);
50-
var quit = process.exit;
52+
const quit = process.exit;
5153

5254
// Polyfill "readline()".
53-
var logFile = arguments[arguments.length - 1];
55+
const logFile = arguments[arguments.length - 1];
5456
try {
5557
fs.accessSync(logFile);
5658
} catch(e) {
5759
console.error('Please provide a valid isolate file as the final argument.');
5860
process.exit(1);
5961
}
60-
var fd = fs.openSync(logFile, 'r');
61-
var buf = new Buffer(4096);
62-
var dec = new (require('string_decoder').StringDecoder)('utf-8');
62+
const fd = fs.openSync(logFile, 'r');
63+
const buf = new Buffer(4096);
64+
const dec = new (require('string_decoder').StringDecoder)('utf-8');
6365
var line = '';
6466
versionCheck();
6567
function readline() {
@@ -85,7 +87,7 @@ function versionCheck() {
8587
var firstLine = readline();
8688
line = firstLine + '\n' + line;
8789
firstLine = firstLine.split(',');
88-
var curVer = process.versions.v8.split('.');
90+
const curVer = process.versions.v8.split('.');
8991
if (firstLine.length !== 6 && firstLine[0] !== 'v8-version') {
9092
console.log('Unable to read v8-version from log file.');
9193
return;

lib/internal/v8_prof_processor.js

+9-24
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
'use strict';
2-
var cp = require('child_process');
3-
var fs = require('fs');
4-
var path = require('path');
5-
6-
var scriptFiles = [
1+
const scriptFiles = [
72
'internal/v8_prof_polyfill',
83
'v8/tools/splaytree',
94
'v8/tools/codemap',
@@ -16,29 +11,19 @@ var scriptFiles = [
1611
'v8/tools/SourceMap',
1712
'v8/tools/tickprocessor-driver'
1813
];
19-
var tempScript = 'tick-processor-tmp-' + process.pid;
20-
var tempNm = 'mac-nm-' + process.pid;
14+
var script = '';
2115

22-
process.on('exit', function() {
23-
try { fs.unlinkSync(tempScript); } catch (e) {}
24-
try { fs.unlinkSync(tempNm); } catch (e) {}
25-
});
26-
process.on('uncaughtException', function(err) {
27-
try { fs.unlinkSync(tempScript); } catch (e) {}
28-
try { fs.unlinkSync(tempNm); } catch (e) {}
29-
throw err;
16+
scriptFiles.forEach(function(s) {
17+
script += process.binding('natives')[s] + '\n';
3018
});
3119

32-
scriptFiles.forEach(function(script) {
33-
fs.appendFileSync(tempScript, process.binding('natives')[script]);
34-
});
35-
var tickArguments = [tempScript];
20+
var tickArguments = [];
3621
if (process.platform === 'darwin') {
37-
fs.writeFileSync(tempNm, process.binding('natives')['v8/tools/mac-nm'],
38-
{ mode: 0o555 });
39-
tickArguments.push('--mac', '--nm=' + path.join(process.cwd(), tempNm));
22+
const nm = 'foo() { nm "$@" | (c++filt -p -i || cat) }; foo $@';
23+
tickArguments.push('--mac', '--nm=' + nm);
4024
} else if (process.platform === 'win32') {
4125
tickArguments.push('--windows');
4226
}
4327
tickArguments.push.apply(tickArguments, process.argv.slice(1));
44-
cp.spawn(process.execPath, tickArguments, { stdio: 'inherit' });
28+
script = 'arguments = ' + JSON.stringify(tickArguments) + ';\n' + script;
29+
eval(script);

node.gyp

-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@
9090
'deps/v8/tools/tickprocessor.js',
9191
'deps/v8/tools/SourceMap.js',
9292
'deps/v8/tools/tickprocessor-driver.js',
93-
'deps/v8/tools/mac-nm',
9493
],
9594
},
9695

0 commit comments

Comments
 (0)