Skip to content

Commit dddc314

Browse files
Matt LoringMyles Borins
Matt Loring
authored and
Myles Borins
committed
tools: add --prof-process flag to node binary
This change cleans up outstanding comments on nodejs#3032. It improves error handling when no isolate file is provided and adds the --prof-process flag to the node binary which executes the tick processor on the provided isolate file. PR-URL: nodejs#4021 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Evan Lucas <[email protected]>
1 parent 2639d36 commit dddc314

12 files changed

+88
-107
lines changed

.eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
lib/internal/v8_prof_polyfill.js
12
lib/punycode.js
23
test/addons/??_*/
34
test/fixtures

doc/node.1

+2
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ and servers.
6464

6565
--track-heap-objects track heap object allocations for heap snapshots
6666

67+
--prof-process process v8 profiler output generated using --prof
68+
6769
--v8-options print v8 command line options
6870

6971
--tls-cipher-list=list use an alternative default TLS cipher list

tools/v8-prof/polyfill.js lib/internal/v8_prof_polyfill.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,14 @@ arguments = process.argv.slice(2);
5050
var quit = process.exit;
5151

5252
// Polyfill "readline()".
53-
var fd = fs.openSync(arguments[arguments.length - 1], 'r');
53+
var logFile = arguments[arguments.length - 1];
54+
try {
55+
fs.accessSync(logFile);
56+
} catch(e) {
57+
console.error('Please provide a valid isolate file as the final argument.');
58+
process.exit(1);
59+
}
60+
var fd = fs.openSync(logFile, 'r');
5461
var buf = new Buffer(4096);
5562
var dec = new (require('string_decoder').StringDecoder)('utf-8');
5663
var line = '';

lib/internal/v8_prof_processor.js

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
'use strict';
2+
var cp = require('child_process');
3+
var fs = require('fs');
4+
var path = require('path');
5+
6+
var scriptFiles = [
7+
'internal/v8_prof_polyfill',
8+
'v8/tools/splaytree',
9+
'v8/tools/codemap',
10+
'v8/tools/csvparser',
11+
'v8/tools/consarray',
12+
'v8/tools/profile',
13+
'v8/tools/profile_view',
14+
'v8/tools/logreader',
15+
'v8/tools/tickprocessor',
16+
'v8/tools/SourceMap',
17+
'v8/tools/tickprocessor-driver'
18+
];
19+
var tempScript = 'tick-processor-tmp-' + process.pid;
20+
var tempNm = 'mac-nm-' + process.pid;
21+
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;
30+
});
31+
32+
scriptFiles.forEach(function(script) {
33+
fs.appendFileSync(tempScript, process.binding('natives')[script]);
34+
});
35+
var tickArguments = [tempScript];
36+
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));
40+
} else if (process.platform === 'win32') {
41+
tickArguments.push('--windows');
42+
}
43+
tickArguments.push.apply(tickArguments, process.argv.slice(1));
44+
cp.spawn(process.execPath, tickArguments, { stdio: 'inherit' });

node.gyp

+13
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,20 @@
7777
'lib/internal/socket_list.js',
7878
'lib/internal/repl.js',
7979
'lib/internal/util.js',
80+
'lib/internal/v8_prof_polyfill.js',
81+
'lib/internal/v8_prof_processor.js',
8082
'lib/internal/streams/lazy_transform.js',
83+
'deps/v8/tools/splaytree.js',
84+
'deps/v8/tools/codemap.js',
85+
'deps/v8/tools/consarray.js',
86+
'deps/v8/tools/csvparser.js',
87+
'deps/v8/tools/profile.js',
88+
'deps/v8/tools/profile_view.js',
89+
'deps/v8/tools/logreader.js',
90+
'deps/v8/tools/tickprocessor.js',
91+
'deps/v8/tools/SourceMap.js',
92+
'deps/v8/tools/tickprocessor-driver.js',
93+
'deps/v8/tools/mac-nm',
8194
],
8295
},
8396

src/node.cc

+13-1
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ static const char** preload_modules = nullptr;
141141
static bool use_debug_agent = false;
142142
static bool debug_wait_connect = false;
143143
static int debug_port = 5858;
144+
static bool prof_process = false;
144145
static bool v8_is_profiling = false;
145146
static bool node_is_initialized = false;
146147
static node_module* modpending;
@@ -2972,6 +2973,11 @@ void SetupProcessObject(Environment* env,
29722973
READONLY_PROPERTY(process, "throwDeprecation", True(env->isolate()));
29732974
}
29742975

2976+
// --prof-process
2977+
if (prof_process) {
2978+
READONLY_PROPERTY(process, "profProcess", True(env->isolate()));
2979+
}
2980+
29752981
// --trace-deprecation
29762982
if (trace_deprecation) {
29772983
READONLY_PROPERTY(process, "traceDeprecation", True(env->isolate()));
@@ -3218,6 +3224,8 @@ static void PrintHelp() {
32183224
" is detected after the first tick\n"
32193225
" --track-heap-objects track heap object allocations for heap "
32203226
"snapshots\n"
3227+
" --prof-process process v8 profiler output generated\n"
3228+
" using --prof\n"
32213229
" --v8-options print v8 command line options\n"
32223230
#if HAVE_OPENSSL
32233231
" --tls-cipher-list=val use an alternative default TLS cipher list\n"
@@ -3289,7 +3297,8 @@ static void ParseArgs(int* argc,
32893297
new_argv[0] = argv[0];
32903298

32913299
unsigned int index = 1;
3292-
while (index < nargs && argv[index][0] == '-') {
3300+
bool short_circuit = false;
3301+
while (index < nargs && argv[index][0] == '-' && !short_circuit) {
32933302
const char* const arg = argv[index];
32943303
unsigned int args_consumed = 1;
32953304

@@ -3353,6 +3362,9 @@ static void ParseArgs(int* argc,
33533362
} else if (strncmp(arg, "--security-revert=", 18) == 0) {
33543363
const char* cve = arg + 18;
33553364
Revert(cve);
3365+
} else if (strcmp(arg, "--prof-process") == 0) {
3366+
prof_process = true;
3367+
short_circuit = true;
33563368
} else if (strcmp(arg, "--v8-options") == 0) {
33573369
new_v8_argv[new_v8_argc] = "--help";
33583370
new_v8_argc += 1;

src/node.js

+3
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@
6868
// Start the debugger agent
6969
NativeModule.require('_debug_agent').start();
7070

71+
} else if (process.profProcess) {
72+
NativeModule.require('internal/v8_prof_processor');
73+
7174
} else {
7275
// There is user code to be run
7376

test/parallel/test-tick-processor.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ if (common.isAix) {
1616

1717
common.refreshTmpDir();
1818
process.chdir(common.tmpDir);
19-
var processor =
20-
path.join(common.testDir, '..', 'tools', 'v8-prof', 'tick-processor.js');
2119
// Unknown checked for to prevent flakiness, if pattern is not found,
2220
// then a large number of unknown ticks should be present
2321
runTest(/LazyCompile.*\[eval\]:1|.*% UNKNOWN/,
@@ -54,9 +52,9 @@ function runTest(pattern, code) {
5452
assert.fail(null, null, 'There should be a single log file.');
5553
}
5654
var log = matches[0];
57-
var out = cp.execSync(process.execPath + ' ' + processor +
58-
' --call-graph-size=10 ' + log,
55+
var out = cp.execSync(process.execPath +
56+
' --prof-process --call-graph-size=10 ' + log,
5957
{encoding: 'utf8'});
60-
assert(out.match(pattern));
58+
assert(pattern.test(out));
6159
fs.unlinkSync(log);
6260
}

tools/install.py

-44
Original file line numberDiff line numberDiff line change
@@ -127,48 +127,6 @@ def subdir_files(path, dest, action):
127127
for subdir, files in ret.items():
128128
action(files, subdir + '/')
129129

130-
def build_tick_processor(action):
131-
tmp_script = 'out/Release/tick-processor'
132-
if action == install:
133-
# construct script
134-
scripts = [
135-
'tools/v8-prof/polyfill.js',
136-
'deps/v8/tools/splaytree.js',
137-
'deps/v8/tools/codemap.js',
138-
'deps/v8/tools/csvparser.js',
139-
'deps/v8/tools/consarray.js',
140-
'deps/v8/tools/csvparser.js',
141-
'deps/v8/tools/consarray.js',
142-
'deps/v8/tools/profile.js',
143-
'deps/v8/tools/profile_view.js',
144-
'deps/v8/tools/logreader.js',
145-
'deps/v8/tools/tickprocessor.js',
146-
'deps/v8/tools/SourceMap.js',
147-
'deps/v8/tools/tickprocessor-driver.js']
148-
args = []
149-
if sys.platform == 'win32':
150-
args.append('--windows')
151-
elif sys.platform == 'darwin':
152-
args.append('--nm=' + abspath(install_path, 'share/doc/node') + '/mac-nm')
153-
args.append('--mac')
154-
with open(tmp_script, 'w') as out_file:
155-
# Add #! line to run with node
156-
out_file.write('#! ' + abspath(install_path, 'bin/node') + '\n')
157-
# inject arguments
158-
for arg in args:
159-
out_file.write('process.argv.splice(2, 0, \'' + arg + '\');\n')
160-
# cat in source files
161-
for script in scripts:
162-
with open(script) as in_file:
163-
shutil.copyfileobj(in_file, out_file)
164-
# make executable
165-
st = os.stat(tmp_script)
166-
os.chmod(tmp_script, st.st_mode | stat.S_IEXEC)
167-
# perform installations
168-
action([tmp_script], 'share/doc/node/')
169-
if sys.platform == 'darwin':
170-
action(['deps/v8/tools/mac-nm'], 'share/doc/node/')
171-
172130
def files(action):
173131
is_windows = sys.platform == 'win32'
174132

@@ -183,8 +141,6 @@ def files(action):
183141

184142
action(['deps/v8/tools/gdbinit'], 'share/doc/node/')
185143

186-
build_tick_processor(action)
187-
188144
if 'freebsd' in sys.platform or 'openbsd' in sys.platform:
189145
action(['doc/node.1'], 'man/man1/')
190146
else:

tools/js2c.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ def JS2C(source, target):
310310
else:
311311
ids.append((id, len(lines)))
312312

313-
escaped_id = id.replace('/', '_')
313+
escaped_id = id.replace('-', '_').replace('/', '_')
314314
source_lines.append(SOURCE_DECLARATION % {
315315
'id': id,
316316
'escaped_id': escaped_id,

tools/rpm/node.spec

-4
Original file line numberDiff line numberDiff line change
@@ -94,17 +94,13 @@ done
9494
/usr/include/*
9595
/usr/lib/node_modules/
9696
/usr/share/doc/node/gdbinit
97-
/usr/share/doc/node/tick-processor
9897
/usr/share/man/man1/node.1.gz
9998
/usr/share/systemtap/tapset/node.stp
10099
%{_datadir}/%{name}/
101100
%doc CHANGELOG.md LICENSE README.md
102101

103102

104103
%changelog
105-
* Tue Sep 22 2015 Matt Loring <[email protected]>
106-
- Added tick processor.
107-
108104
* Tue Jul 7 2015 Ali Ijaz Sheikh <[email protected]>
109105
- Added gdbinit.
110106

tools/v8-prof/tick-processor.js

-51
This file was deleted.

0 commit comments

Comments
 (0)