diff --git a/PerfTools/JeProf/src/jeprof.cc b/PerfTools/JeProf/src/jeprof.cc index c7b2d74c5619d..ed0b7e965be25 100644 --- a/PerfTools/JeProf/src/jeprof.cc +++ b/PerfTools/JeProf/src/jeprof.cc @@ -26,11 +26,25 @@ namespace jeprof { return enable_prof; } + std::string replace(const std::string &s, const char *pat, std::string_view val) { + size_t pos = 0; + size_t patlen = strlen(pat); + std::string result = s; + while ((pos = result.find(pat, pos)) != std::string::npos) { + result.replace(pos, patlen, val.data()); + pos = pos - patlen + val.size(); + } + + return result; + } void makeDump(const std::string &format, std::string_view moduleLabel) { - if (!have_jemalloc_and_prof || format.empty()) + if (!have_jemalloc_and_prof) return; - std::string final("heap_info.out"); + std::string final(format); + if (format.empty()) + final = "%M.heap_info.out"; + final = replace(final, "%M", moduleLabel); const char *fileName = final.c_str(); mallctl("prof.dump", nullptr, nullptr, &fileName, sizeof(const char *)); }