@@ -8,6 +8,7 @@
|
8 | 8 | #include "node_file.h" |
9 | 9 | #include "node_internals.h" |
10 | 10 | #include "util-inl.h" |
| 11 | +#include "uv.h" |
11 | 12 | #include "v8-inspector.h" |
12 | 13 | |
13 | 14 | #include <cinttypes> |
@@ -465,6 +466,27 @@ static void EndStartedProfilers(Environment* env) {
|
465 | 466 | } |
466 | 467 | } |
467 | 468 | |
| 469 | +static std::string ReplacePlaceholders(const std::string& pattern) { |
| 470 | + std::string result = pattern; |
| 471 | + |
| 472 | +static const std::unordered_map<std::string, std::function<std::string()>> |
| 473 | +kPlaceholderMap = { |
| 474 | + {"${pid}", []() { return std::to_string(uv_os_getpid()); }}, |
| 475 | +// TODO(haramj): Add more placeholders as needed. |
| 476 | + }; |
| 477 | + |
| 478 | +for (const auto& [placeholder, getter] : kPlaceholderMap) { |
| 479 | +size_t pos = 0; |
| 480 | +while ((pos = result.find(placeholder, pos)) != std::string::npos) { |
| 481 | +const std::string value = getter(); |
| 482 | + result.replace(pos, placeholder.length(), value); |
| 483 | + pos += value.length(); |
| 484 | + } |
| 485 | + } |
| 486 | + |
| 487 | +return result; |
| 488 | +} |
| 489 | + |
468 | 490 | void StartProfilers(Environment* env) { |
469 | 491 | AtExit(env, [](void* env) { |
470 | 492 | EndStartedProfilers(static_cast<Environment*>(env)); |
@@ -486,7 +508,9 @@ void StartProfilers(Environment* env) {
|
486 | 508 | DiagnosticFilename filename(env, "CPU", "cpuprofile"); |
487 | 509 | env->set_cpu_prof_name(*filename); |
488 | 510 | } else { |
489 | | - env->set_cpu_prof_name(env->options()->cpu_prof_name); |
| 511 | + std::string resolved_name = |
| 512 | +ReplacePlaceholders(env->options()->cpu_prof_name); |
| 513 | + env->set_cpu_prof_name(resolved_name); |
490 | 514 | } |
491 | 515 | CHECK_NULL(env->cpu_profiler_connection()); |
492 | 516 | env->set_cpu_profiler_connection( |
|