Skip to content

Commit

Permalink
squash! inspector: split --cpu-prof-path to --prof-dir and --cpu-prof…
Browse files Browse the repository at this point in the history
…-name
  • Loading branch information
joyeecheung committed Apr 19, 2019
1 parent 4212a65 commit f0de081
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 64 deletions.
30 changes: 15 additions & 15 deletions doc/api/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ added: REPLACEME
Starts the V8 CPU profiler on start up, and writes the CPU profile to disk
before exit.

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

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

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

### `--node-prof-dir`
<!-- YAML
added: REPLACEME
-->

> Stability: 1 - Experimental
Specify the directory where the CPU profiles generated by `--cpu-prof` will
be placed.

This does not apply to `--prof` whose output is handled by V8 instead of
Node.js.

### `--no-deprecation`
<!-- YAML
added: v0.8.0
Expand Down Expand Up @@ -475,19 +488,6 @@ added: v2.0.0

Generate V8 profiler output.

### `--prof-dir`
<!-- YAML
added: REPLACEME
-->

> Stability: 1 - Experimental
Specify the directory where the CPU profiles generated by `--cpu-prof` will
be placed.

This does not apply to `--prof` whose output is handled by V8 instead of
Node.js.

### `--prof-process`
<!-- YAML
added: v5.2.0
Expand Down
16 changes: 8 additions & 8 deletions doc/node.1
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ Print source-able bash completion script for Node.js.
.It Fl -cpu-prof
Start the V8 CPU profiler on start up, and write the CPU profile to disk
before exit. If
.Fl -prof-dir
.Fl -node-prof-dir
is not specified, the profile will be written to the current working directory
with a generated file name.
.
Expand Down Expand Up @@ -213,6 +213,13 @@ Specify the maximum size of HTTP headers in bytes. Defaults to 8KB.
This option is a no-op.
It is kept for compatibility.
.
.It Fl -node-prof-dir
The directory where the CPU profiles generated by
.Fl -cpu-prof
will be placed. Note that this does not apply to
.Fl -prof
whose output is handled by V8, not Node.js.
.
.It Fl -no-deprecation
Silence deprecation warnings.
.
Expand Down Expand Up @@ -240,13 +247,6 @@ Instructs the module loader to preserve symbolic links when resolving and cachin
.It Fl -prof
Generate V8 profiler output.
.
.It Fl -prof-dir
The directory where the CPU profiles generated by
.Fl -cpu-prof
will be placed. Note that this does not apply to
.Fl -prof
whose output is handled by V8, not Node.js.
.
.It Fl -prof-process
Process V8 profiler output generated using the V8 option
.Fl -prof .
Expand Down
22 changes: 4 additions & 18 deletions src/env-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -687,26 +687,12 @@ inline const std::string& Environment::cpu_profile_path() const {
return cpu_profile_path_;
}

inline void Environment::set_prof_dir(const std::string& path) {
prof_dir_ = path;
inline void Environment::set_node_prof_dir(const std::string& path) {
node_prof_dir_ = path;
}

inline const std::string& Environment::prof_dir() const {
return prof_dir_;
}

inline void Environment::InitializeProfDir(const std::string& dir) {
if (!dir.empty()) {
prof_dir_ = dir;
return;
}
char cwd[CWD_BUFSIZE];
size_t size = CWD_BUFSIZE;
int err = uv_cwd(cwd, &size);
// TODO(joyeecheung): fallback to exec path / argv[0]
CHECK_EQ(err, 0);
CHECK_GT(size, 0);
prof_dir_ = cwd;
inline const std::string& Environment::node_prof_dir() const {
return node_prof_dir_;
}

#endif // HAVE_INSPECTOR
Expand Down
18 changes: 18 additions & 0 deletions src/env.cc
Original file line number Diff line number Diff line change
Expand Up @@ -845,6 +845,24 @@ void Environment::stop_sub_worker_contexts() {
}
}

#if HAVE_INSPECTOR

void Environment::InitializeNodeProfDir(const std::string& dir) {
if (!dir.empty()) {
node_prof_dir_ = dir;
return;
}
char cwd[CWD_BUFSIZE];
size_t size = CWD_BUFSIZE;
int err = uv_cwd(cwd, &size);
// TODO(joyeecheung): fallback to exec path / argv[0]
CHECK_EQ(err, 0);
CHECK_GT(size, 0);
node_prof_dir_ = cwd;
}

#endif // HAVE_INSPECTOR

void MemoryTracker::TrackField(const char* edge_name,
const CleanupHookCallback& value,
const char* node_name) {
Expand Down
8 changes: 4 additions & 4 deletions src/env.h
Original file line number Diff line number Diff line change
Expand Up @@ -1138,10 +1138,10 @@ class Environment : public MemoryRetainer {
inline void set_cpu_profile_path(const std::string& path);
inline const std::string& cpu_profile_path() const;

inline void set_prof_dir(const std::string& path);
inline const std::string& prof_dir() const;
inline void set_node_prof_dir(const std::string& path);
inline const std::string& node_prof_dir() const;

inline void InitializeProfDir(const std::string& dir);
void InitializeNodeProfDir(const std::string& dir);
#endif // HAVE_INSPECTOR

private:
Expand Down Expand Up @@ -1178,7 +1178,7 @@ class Environment : public MemoryRetainer {
std::unique_ptr<profiler::V8CoverageConnection> coverage_connection_;
std::unique_ptr<profiler::V8CpuProfilerConnection> cpu_profiler_connection_;
std::string coverage_directory_;
std::string prof_dir_;
std::string node_prof_dir_;
std::string cpu_profile_path_;
#endif // HAVE_INSPECTOR

Expand Down
2 changes: 1 addition & 1 deletion src/inspector_profiler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ void StartCoverageCollection(Environment* env) {
}

void StartCpuProfiling(Environment* env, const std::string& profile_name) {
std::string path = env->prof_dir() + std::string(kPathSeparator);
std::string path = env->node_prof_dir() + std::string(kPathSeparator);
if (profile_name.empty()) {
DiagnosticFilename filename(env, "CPU", "cpuprofile");
path += *filename;
Expand Down
2 changes: 1 addition & 1 deletion src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ MaybeLocal<Value> RunBootstrapping(Environment* env) {

#if HAVE_INSPECTOR
if (env->options()->cpu_prof) {
env->InitializeProfDir(env->options()->prof_dir);
env->InitializeNodeProfDir(env->options()->node_prof_dir);
profiler::StartCpuProfiling(env, env->options()->cpu_prof_name);
}
#endif // HAVE_INSPECTOR
Expand Down
8 changes: 4 additions & 4 deletions src/node_options.cc
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ void EnvironmentOptions::CheckOptions(std::vector<std::string>* errors) {
}

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

debug_options_.CheckOptions(errors);
Expand Down Expand Up @@ -351,10 +351,10 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
"specified file name of the V8 CPU profile generated with "
"--cpu-prof",
&EnvironmentOptions::cpu_prof_name);
AddOption("--prof-dir",
AddOption("--node-prof-dir",
"Directory where the V8 profiles generated by --cpu-prof will be "
"placed. Does not affect --prof.",
&EnvironmentOptions::prof_dir);
&EnvironmentOptions::node_prof_dir);
#endif // HAVE_INSPECTOR
AddOption("--redirect-warnings",
"write warnings to file instead of stderr",
Expand Down
2 changes: 1 addition & 1 deletion src/node_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class EnvironmentOptions : public Options {
bool preserve_symlinks_main = false;
bool prof_process = false;
#if HAVE_INSPECTOR
std::string prof_dir;
std::string node_prof_dir;
std::string cpu_prof_name;
bool cpu_prof = false;
#endif // HAVE_INSPECTOR
Expand Down
24 changes: 12 additions & 12 deletions test/sequential/test-cpu-prof.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

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

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

// --prof-dir without --cpu-prof
// --node-prof-dir without --cpu-prof
{
tmpdir.refresh();
const output = spawnSync(process.execPath, [
'--prof-dir',
'--node-prof-dir',
'prof',
fixtures.path('workload', 'fibonacci.js'),
], {
Expand All @@ -180,7 +180,7 @@ const env = {
assert.strictEqual(output.status, 9);
assert.strictEqual(
stderr,
`${process.execPath}: --prof-dir must be used with --cpu-prof`);
`${process.execPath}: --node-prof-dir must be used with --cpu-prof`);
}

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

// relative --prof-dir
// relative --node-prof-dir
{
tmpdir.refresh();
const output = spawnSync(process.execPath, [
'--cpu-prof',
'--prof-dir',
'--node-prof-dir',
'prof',
fixtures.path('workload', 'fibonacci.js'),
], {
Expand All @@ -228,13 +228,13 @@ const env = {
verifyFrames(output, profiles[0], 'fibonacci.js');
}

// absolute --prof-dir
// absolute --node-prof-dir
{
tmpdir.refresh();
const dir = path.join(tmpdir.path, 'prof');
const output = spawnSync(process.execPath, [
'--cpu-prof',
'--prof-dir',
'--node-prof-dir',
dir,
fixtures.path('workload', 'fibonacci.js'),
], {
Expand All @@ -251,7 +251,7 @@ const env = {
verifyFrames(output, profiles[0], 'fibonacci.js');
}

// --prof-dir and --cpu-prof-name
// --node-prof-dir and --cpu-prof-name
{
tmpdir.refresh();
const dir = path.join(tmpdir.path, 'prof');
Expand All @@ -260,7 +260,7 @@ const env = {
'--cpu-prof',
'--cpu-prof-name',
'test.cpuprofile',
'--prof-dir',
'--node-prof-dir',
dir,
fixtures.path('workload', 'fibonacci.js'),
], {
Expand All @@ -277,11 +277,11 @@ const env = {
verifyFrames(output, file, 'fibonacci.js');
}

// --prof-dir with worker
// --node-prof-dir with worker
{
tmpdir.refresh();
const output = spawnSync(process.execPath, [
'--prof-dir',
'--node-prof-dir',
'prof',
'--cpu-prof',
fixtures.path('workload', 'fibonacci-worker.js'),
Expand Down

0 comments on commit f0de081

Please sign in to comment.