| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 040b9db commit c491e4d
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -320,17 +320,20 @@ void EndStartedProfilers(Environment* env) { | |||
| 320 | 320 | } | |
| 321 | 321 | } | |
| 322 | 322 | ||
| 323 | - std::string GetCwd() { | ||
| 323 | + std::string GetCwd(Environment* env) { | ||
| 324 | 324 | char cwd[PATH_MAX_BYTES]; | |
| 325 | 325 | size_t size = PATH_MAX_BYTES; | |
| 326 | 326 | int err = uv_cwd(cwd, &size); | |
| 327 | - // This can fail if the cwd is deleted. | ||
| 328 | - // TODO(joyeecheung): store this in the Environment during Environment | ||
| 329 | - // creation and fallback to exec_path and argv0, then we no longer need | ||
| 330 | - // SetCoverageDirectory(). | ||
| 331 | - CHECK_EQ(err, 0); | ||
| 332 | - CHECK_GT(size, 0); | ||
| 333 | - return cwd; | ||
| 327 | + | ||
| 328 | + if (err == 0) { | ||
| 329 | + CHECK_GT(size, 0); | ||
| 330 | + return cwd; | ||
| 331 | + } | ||
| 332 | + | ||
| 333 | + // This can fail if the cwd is deleted. In that case, fall back to | ||
| 334 | + // exec_path. | ||
| 335 | + const std::string& exec_path = env->exec_path(); | ||
| 336 | + return exec_path.substr(0, exec_path.find_last_of(kPathSeparator)); | ||
| 334 | 337 | } | |
| 335 | 338 | ||
| 336 | 339 | void StartProfilers(Environment* env) { | |
@@ -345,7 +348,7 @@ void StartProfilers(Environment* env) { | |||
| 345 | 348 | if (env->options()->cpu_prof) { | |
| 346 | 349 | const std::string& dir = env->options()->cpu_prof_dir; | |
| 347 | 350 | env->set_cpu_prof_interval(env->options()->cpu_prof_interval); | |
| 348 | - env->set_cpu_prof_dir(dir.empty() ? GetCwd() : dir); | ||
| 351 | + env->set_cpu_prof_dir(dir.empty() ? GetCwd(env) : dir); | ||
| 349 | 352 | if (env->options()->cpu_prof_name.empty()) { | |
| 350 | 353 | DiagnosticFilename filename(env, "CPU", "cpuprofile"); | |
| 351 | 354 | env->set_cpu_prof_name(*filename); | |
@@ -360,7 +363,7 @@ void StartProfilers(Environment* env) { | |||
| 360 | 363 | if (env->options()->heap_prof) { | |
| 361 | 364 | const std::string& dir = env->options()->heap_prof_dir; | |
| 362 | 365 | env->set_heap_prof_interval(env->options()->heap_prof_interval); | |
| 363 | - env->set_heap_prof_dir(dir.empty() ? GetCwd() : dir); | ||
| 366 | + env->set_heap_prof_dir(dir.empty() ? GetCwd(env) : dir); | ||
| 364 | 367 | if (env->options()->heap_prof_name.empty()) { | |
| 365 | 368 | DiagnosticFilename filename(env, "Heap", "heapprofile"); | |
| 366 | 369 | env->set_heap_prof_name(*filename); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments