summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/inspector_profiler.cc23
1 files changed, 13 insertions, 10 deletions
diff --git a/src/inspector_profiler.cc b/src/inspector_profiler.cc
index 1b20398dba..122118324f 100644
--- a/src/inspector_profiler.cc
+++ b/src/inspector_profiler.cc
@@ -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) {
@@ -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);
@@ -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);