Skip to content

Commit

Permalink
src: fall back to env->exec_path() for default profile directory
Browse files Browse the repository at this point in the history
When the current working directory is deleted, fall back to
exec_path as the default profile directory.

PR-URL: #28252
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
joyeecheung authored and targos committed Jul 2, 2019
1 parent 040b9db commit c491e4d
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/inspector_profiler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -320,17 +320,20 @@ void EndStartedProfilers(Environment* env) {
}
}

std::string GetCwd() {
std::string GetCwd(Environment* env) {
char cwd[PATH_MAX_BYTES];
size_t size = PATH_MAX_BYTES;
int err = uv_cwd(cwd, &size);
// This can fail if the cwd is deleted.
// TODO(joyeecheung): store this in the Environment during Environment
// creation and fallback to exec_path and argv0, then we no longer need
// SetCoverageDirectory().
CHECK_EQ(err, 0);
CHECK_GT(size, 0);
return cwd;

if (err == 0) {
CHECK_GT(size, 0);
return cwd;
}

// This can fail if the cwd is deleted. In that case, fall back to
// exec_path.
const std::string& exec_path = env->exec_path();
return exec_path.substr(0, exec_path.find_last_of(kPathSeparator));
}

void StartProfilers(Environment* env) {
Expand All @@ -345,7 +348,7 @@ void StartProfilers(Environment* env) {
if (env->options()->cpu_prof) {
const std::string& dir = env->options()->cpu_prof_dir;
env->set_cpu_prof_interval(env->options()->cpu_prof_interval);
env->set_cpu_prof_dir(dir.empty() ? GetCwd() : dir);
env->set_cpu_prof_dir(dir.empty() ? GetCwd(env) : dir);
if (env->options()->cpu_prof_name.empty()) {
DiagnosticFilename filename(env, "CPU", "cpuprofile");
env->set_cpu_prof_name(*filename);
Expand All @@ -360,7 +363,7 @@ void StartProfilers(Environment* env) {
if (env->options()->heap_prof) {
const std::string& dir = env->options()->heap_prof_dir;
env->set_heap_prof_interval(env->options()->heap_prof_interval);
env->set_heap_prof_dir(dir.empty() ? GetCwd() : dir);
env->set_heap_prof_dir(dir.empty() ? GetCwd(env) : dir);
if (env->options()->heap_prof_name.empty()) {
DiagnosticFilename filename(env, "Heap", "heapprofile");
env->set_heap_prof_name(*filename);
Expand Down

0 comments on commit c491e4d

Please sign in to comment.