Skip to content

Commit f0de081

Browse files
committed
squash! inspector: split --cpu-prof-path to --prof-dir and --cpu-prof-name
1 parent 4212a65 commit f0de081

File tree

10 files changed

+68
-64
lines changed

10 files changed

+68
-64
lines changed

doc/api/cli.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ added: REPLACEME
8585
Starts the V8 CPU profiler on start up, and writes the CPU profile to disk
8686
before exit.
8787

88-
If `--prof-dir` is not specified, the generated profile will be placed in the
89-
current working directory.
88+
If `--node-prof-dir` is not specified, the generated profile will be placed
89+
in the current working directory.
9090

9191
If `--cpu-prof-name` is not specified, the generated profile will be
9292
named `CPU.${yyyymmdd}.${hhmmss}.${pid}.${tid}.${seq}.cpuprofile`.
@@ -360,6 +360,19 @@ added: v7.10.0
360360

361361
This option is a no-op. It is kept for compatibility.
362362

363+
### `--node-prof-dir`
364+
<!-- YAML
365+
added: REPLACEME
366+
-->
367+
368+
> Stability: 1 - Experimental
369+
370+
Specify the directory where the CPU profiles generated by `--cpu-prof` will
371+
be placed.
372+
373+
This does not apply to `--prof` whose output is handled by V8 instead of
374+
Node.js.
375+
363376
### `--no-deprecation`
364377
<!-- YAML
365378
added: v0.8.0
@@ -475,19 +488,6 @@ added: v2.0.0
475488

476489
Generate V8 profiler output.
477490

478-
### `--prof-dir`
479-
<!-- YAML
480-
added: REPLACEME
481-
-->
482-
483-
> Stability: 1 - Experimental
484-
485-
Specify the directory where the CPU profiles generated by `--cpu-prof` will
486-
be placed.
487-
488-
This does not apply to `--prof` whose output is handled by V8 instead of
489-
Node.js.
490-
491491
### `--prof-process`
492492
<!-- YAML
493493
added: v5.2.0

doc/node.1

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ Print source-able bash completion script for Node.js.
8181
.It Fl -cpu-prof
8282
Start the V8 CPU profiler on start up, and write the CPU profile to disk
8383
before exit. If
84-
.Fl -prof-dir
84+
.Fl -node-prof-dir
8585
is not specified, the profile will be written to the current working directory
8686
with a generated file name.
8787
.
@@ -213,6 +213,13 @@ Specify the maximum size of HTTP headers in bytes. Defaults to 8KB.
213213
This option is a no-op.
214214
It is kept for compatibility.
215215
.
216+
.It Fl -node-prof-dir
217+
The directory where the CPU profiles generated by
218+
.Fl -cpu-prof
219+
will be placed. Note that this does not apply to
220+
.Fl -prof
221+
whose output is handled by V8, not Node.js.
222+
.
216223
.It Fl -no-deprecation
217224
Silence deprecation warnings.
218225
.
@@ -240,13 +247,6 @@ Instructs the module loader to preserve symbolic links when resolving and cachin
240247
.It Fl -prof
241248
Generate V8 profiler output.
242249
.
243-
.It Fl -prof-dir
244-
The directory where the CPU profiles generated by
245-
.Fl -cpu-prof
246-
will be placed. Note that this does not apply to
247-
.Fl -prof
248-
whose output is handled by V8, not Node.js.
249-
.
250250
.It Fl -prof-process
251251
Process V8 profiler output generated using the V8 option
252252
.Fl -prof .

src/env-inl.h

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -687,26 +687,12 @@ inline const std::string& Environment::cpu_profile_path() const {
687687
return cpu_profile_path_;
688688
}
689689

690-
inline void Environment::set_prof_dir(const std::string& path) {
691-
prof_dir_ = path;
690+
inline void Environment::set_node_prof_dir(const std::string& path) {
691+
node_prof_dir_ = path;
692692
}
693693

694-
inline const std::string& Environment::prof_dir() const {
695-
return prof_dir_;
696-
}
697-
698-
inline void Environment::InitializeProfDir(const std::string& dir) {
699-
if (!dir.empty()) {
700-
prof_dir_ = dir;
701-
return;
702-
}
703-
char cwd[CWD_BUFSIZE];
704-
size_t size = CWD_BUFSIZE;
705-
int err = uv_cwd(cwd, &size);
706-
// TODO(joyeecheung): fallback to exec path / argv[0]
707-
CHECK_EQ(err, 0);
708-
CHECK_GT(size, 0);
709-
prof_dir_ = cwd;
694+
inline const std::string& Environment::node_prof_dir() const {
695+
return node_prof_dir_;
710696
}
711697

712698
#endif // HAVE_INSPECTOR

src/env.cc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -845,6 +845,24 @@ void Environment::stop_sub_worker_contexts() {
845845
}
846846
}
847847

848+
#if HAVE_INSPECTOR
849+
850+
void Environment::InitializeNodeProfDir(const std::string& dir) {
851+
if (!dir.empty()) {
852+
node_prof_dir_ = dir;
853+
return;
854+
}
855+
char cwd[CWD_BUFSIZE];
856+
size_t size = CWD_BUFSIZE;
857+
int err = uv_cwd(cwd, &size);
858+
// TODO(joyeecheung): fallback to exec path / argv[0]
859+
CHECK_EQ(err, 0);
860+
CHECK_GT(size, 0);
861+
node_prof_dir_ = cwd;
862+
}
863+
864+
#endif // HAVE_INSPECTOR
865+
848866
void MemoryTracker::TrackField(const char* edge_name,
849867
const CleanupHookCallback& value,
850868
const char* node_name) {

src/env.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1138,10 +1138,10 @@ class Environment : public MemoryRetainer {
11381138
inline void set_cpu_profile_path(const std::string& path);
11391139
inline const std::string& cpu_profile_path() const;
11401140

1141-
inline void set_prof_dir(const std::string& path);
1142-
inline const std::string& prof_dir() const;
1141+
inline void set_node_prof_dir(const std::string& path);
1142+
inline const std::string& node_prof_dir() const;
11431143

1144-
inline void InitializeProfDir(const std::string& dir);
1144+
void InitializeNodeProfDir(const std::string& dir);
11451145
#endif // HAVE_INSPECTOR
11461146

11471147
private:
@@ -1178,7 +1178,7 @@ class Environment : public MemoryRetainer {
11781178
std::unique_ptr<profiler::V8CoverageConnection> coverage_connection_;
11791179
std::unique_ptr<profiler::V8CpuProfilerConnection> cpu_profiler_connection_;
11801180
std::string coverage_directory_;
1181-
std::string prof_dir_;
1181+
std::string node_prof_dir_;
11821182
std::string cpu_profile_path_;
11831183
#endif // HAVE_INSPECTOR
11841184

src/inspector_profiler.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ void StartCoverageCollection(Environment* env) {
319319
}
320320

321321
void StartCpuProfiling(Environment* env, const std::string& profile_name) {
322-
std::string path = env->prof_dir() + std::string(kPathSeparator);
322+
std::string path = env->node_prof_dir() + std::string(kPathSeparator);
323323
if (profile_name.empty()) {
324324
DiagnosticFilename filename(env, "CPU", "cpuprofile");
325325
path += *filename;

src/node.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ MaybeLocal<Value> RunBootstrapping(Environment* env) {
239239

240240
#if HAVE_INSPECTOR
241241
if (env->options()->cpu_prof) {
242-
env->InitializeProfDir(env->options()->prof_dir);
242+
env->InitializeNodeProfDir(env->options()->node_prof_dir);
243243
profiler::StartCpuProfiling(env, env->options()->cpu_prof_name);
244244
}
245245
#endif // HAVE_INSPECTOR

src/node_options.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,8 @@ void EnvironmentOptions::CheckOptions(std::vector<std::string>* errors) {
154154
}
155155

156156
// We may add support for other profiles in the future.
157-
if (!prof_dir.empty() && !cpu_prof) {
158-
errors->push_back("--prof-dir must be used with --cpu-prof");
157+
if (!node_prof_dir.empty() && !cpu_prof) {
158+
errors->push_back("--node-prof-dir must be used with --cpu-prof");
159159
}
160160

161161
debug_options_.CheckOptions(errors);
@@ -351,10 +351,10 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
351351
"specified file name of the V8 CPU profile generated with "
352352
"--cpu-prof",
353353
&EnvironmentOptions::cpu_prof_name);
354-
AddOption("--prof-dir",
354+
AddOption("--node-prof-dir",
355355
"Directory where the V8 profiles generated by --cpu-prof will be "
356356
"placed. Does not affect --prof.",
357-
&EnvironmentOptions::prof_dir);
357+
&EnvironmentOptions::node_prof_dir);
358358
#endif // HAVE_INSPECTOR
359359
AddOption("--redirect-warnings",
360360
"write warnings to file instead of stderr",

src/node_options.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ class EnvironmentOptions : public Options {
110110
bool preserve_symlinks_main = false;
111111
bool prof_process = false;
112112
#if HAVE_INSPECTOR
113-
std::string prof_dir;
113+
std::string node_prof_dir;
114114
std::string cpu_prof_name;
115115
bool cpu_prof = false;
116116
#endif // HAVE_INSPECTOR

test/sequential/test-cpu-prof.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
// This tests that --cpu-prof, --prof-dir and --cpu-prof-name works.
3+
// This tests that --cpu-prof, --node-prof-dir and --cpu-prof-name works.
44

55
const common = require('../common');
66
if (process.features.debug &&
@@ -162,11 +162,11 @@ const env = {
162162
`${process.execPath}: --cpu-prof-name must be used with --cpu-prof`);
163163
}
164164

165-
// --prof-dir without --cpu-prof
165+
// --node-prof-dir without --cpu-prof
166166
{
167167
tmpdir.refresh();
168168
const output = spawnSync(process.execPath, [
169-
'--prof-dir',
169+
'--node-prof-dir',
170170
'prof',
171171
fixtures.path('workload', 'fibonacci.js'),
172172
], {
@@ -180,7 +180,7 @@ const env = {
180180
assert.strictEqual(output.status, 9);
181181
assert.strictEqual(
182182
stderr,
183-
`${process.execPath}: --prof-dir must be used with --cpu-prof`);
183+
`${process.execPath}: --node-prof-dir must be used with --cpu-prof`);
184184
}
185185

186186
// --cpu-prof-name
@@ -205,12 +205,12 @@ const env = {
205205
verifyFrames(output, file, 'fibonacci.js');
206206
}
207207

208-
// relative --prof-dir
208+
// relative --node-prof-dir
209209
{
210210
tmpdir.refresh();
211211
const output = spawnSync(process.execPath, [
212212
'--cpu-prof',
213-
'--prof-dir',
213+
'--node-prof-dir',
214214
'prof',
215215
fixtures.path('workload', 'fibonacci.js'),
216216
], {
@@ -228,13 +228,13 @@ const env = {
228228
verifyFrames(output, profiles[0], 'fibonacci.js');
229229
}
230230

231-
// absolute --prof-dir
231+
// absolute --node-prof-dir
232232
{
233233
tmpdir.refresh();
234234
const dir = path.join(tmpdir.path, 'prof');
235235
const output = spawnSync(process.execPath, [
236236
'--cpu-prof',
237-
'--prof-dir',
237+
'--node-prof-dir',
238238
dir,
239239
fixtures.path('workload', 'fibonacci.js'),
240240
], {
@@ -251,7 +251,7 @@ const env = {
251251
verifyFrames(output, profiles[0], 'fibonacci.js');
252252
}
253253

254-
// --prof-dir and --cpu-prof-name
254+
// --node-prof-dir and --cpu-prof-name
255255
{
256256
tmpdir.refresh();
257257
const dir = path.join(tmpdir.path, 'prof');
@@ -260,7 +260,7 @@ const env = {
260260
'--cpu-prof',
261261
'--cpu-prof-name',
262262
'test.cpuprofile',
263-
'--prof-dir',
263+
'--node-prof-dir',
264264
dir,
265265
fixtures.path('workload', 'fibonacci.js'),
266266
], {
@@ -277,11 +277,11 @@ const env = {
277277
verifyFrames(output, file, 'fibonacci.js');
278278
}
279279

280-
// --prof-dir with worker
280+
// --node-prof-dir with worker
281281
{
282282
tmpdir.refresh();
283283
const output = spawnSync(process.execPath, [
284-
'--prof-dir',
284+
'--node-prof-dir',
285285
'prof',
286286
'--cpu-prof',
287287
fixtures.path('workload', 'fibonacci-worker.js'),

0 commit comments

Comments
 (0)