Skip to content

Commit 1c1c1a0

Browse files
Matt Loringrvagg
Matt Loring
authored andcommittedDec 8, 2015
tools: add --prof-process flag to node binary
This change cleans up outstanding comments on #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: #4021 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Evan Lucas <[email protected]>
1 parent da3137d commit 1c1c1a0

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/doc-*/
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
@@ -78,7 +78,20 @@
7878
'lib/internal/repl.js',
7979
'lib/internal/socket_list.js',
8080
'lib/internal/util.js',
81+
'lib/internal/v8_prof_polyfill.js',
82+
'lib/internal/v8_prof_processor.js',
8183
'lib/internal/streams/lazy_transform.js',
84+
'deps/v8/tools/splaytree.js',
85+
'deps/v8/tools/codemap.js',
86+
'deps/v8/tools/consarray.js',
87+
'deps/v8/tools/csvparser.js',
88+
'deps/v8/tools/profile.js',
89+
'deps/v8/tools/profile_view.js',
90+
'deps/v8/tools/logreader.js',
91+
'deps/v8/tools/tickprocessor.js',
92+
'deps/v8/tools/SourceMap.js',
93+
'deps/v8/tools/tickprocessor-driver.js',
94+
'deps/v8/tools/mac-nm',
8295
],
8396
},
8497

‎src/node.cc

+13-1
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ static const char** preload_modules = nullptr;
144144
static bool use_debug_agent = false;
145145
static bool debug_wait_connect = false;
146146
static int debug_port = 5858;
147+
static bool prof_process = false;
147148
static bool v8_is_profiling = false;
148149
static bool node_is_initialized = false;
149150
static node_module* modpending;
@@ -2958,6 +2959,11 @@ void SetupProcessObject(Environment* env,
29582959
READONLY_PROPERTY(process, "throwDeprecation", True(env->isolate()));
29592960
}
29602961

2962+
// --prof-process
2963+
if (prof_process) {
2964+
READONLY_PROPERTY(process, "profProcess", True(env->isolate()));
2965+
}
2966+
29612967
// --trace-deprecation
29622968
if (trace_deprecation) {
29632969
READONLY_PROPERTY(process, "traceDeprecation", True(env->isolate()));
@@ -3195,6 +3201,8 @@ static void PrintHelp() {
31953201
" is detected after the first tick\n"
31963202
" --track-heap-objects track heap object allocations for heap "
31973203
"snapshots\n"
3204+
" --prof-process process v8 profiler output generated\n"
3205+
" using --prof\n"
31983206
" --v8-options print v8 command line options\n"
31993207
#if HAVE_OPENSSL
32003208
" --tls-cipher-list=val use an alternative default TLS cipher list\n"
@@ -3266,7 +3274,8 @@ static void ParseArgs(int* argc,
32663274
new_argv[0] = argv[0];
32673275

32683276
unsigned int index = 1;
3269-
while (index < nargs && argv[index][0] == '-') {
3277+
bool short_circuit = false;
3278+
while (index < nargs && argv[index][0] == '-' && !short_circuit) {
32703279
const char* const arg = argv[index];
32713280
unsigned int args_consumed = 1;
32723281

@@ -3327,6 +3336,9 @@ static void ParseArgs(int* argc,
33273336
track_heap_objects = true;
33283337
} else if (strcmp(arg, "--throw-deprecation") == 0) {
33293338
throw_deprecation = true;
3339+
} else if (strcmp(arg, "--prof-process") == 0) {
3340+
prof_process = true;
3341+
short_circuit = true;
33303342
} else if (strcmp(arg, "--v8-options") == 0) {
33313343
new_v8_argv[new_v8_argc] = "--help";
33323344
new_v8_argc += 1;

‎src/node.js

+3
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@
7171
var d = NativeModule.require('_debug_agent');
7272
d.start();
7373

74+
} else if (process.profProcess) {
75+
NativeModule.require('internal/v8_prof_processor');
76+
7477
} else {
7578
// There is user code to be run
7679

‎test/parallel/test-tick-processor.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ var common = require('../common');
77

88
common.refreshTmpDir();
99
process.chdir(common.tmpDir);
10-
var processor =
11-
path.join(common.testDir, '..', 'tools', 'v8-prof', 'tick-processor.js');
1210
// Unknown checked for to prevent flakiness, if pattern is not found,
1311
// then a large number of unknown ticks should be present
1412
runTest(/LazyCompile.*\[eval\]:1|.*% UNKNOWN/,
@@ -45,9 +43,9 @@ function runTest(pattern, code) {
4543
assert.fail(null, null, 'There should be a single log file.');
4644
}
4745
var log = matches[0];
48-
var out = cp.execSync(process.execPath + ' ' + processor +
49-
' --call-graph-size=10 ' + log,
46+
var out = cp.execSync(process.execPath +
47+
' --prof-process --call-graph-size=10 ' + log,
5048
{encoding: 'utf8'});
51-
assert(out.match(pattern));
49+
assert(pattern.test(out));
5250
fs.unlinkSync(log);
5351
}

‎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 <mattloring@google.com>
106-
- Added tick processor.
107-
108104
* Tue Jul 7 2015 Ali Ijaz Sheikh <ofrobots@google.com>
109105
- Added gdbinit.
110106

‎tools/v8-prof/tick-processor.js

-51
This file was deleted.

0 commit comments

Comments
 (0)
Please sign in to comment.