Skip to content

Commit

Permalink
Set format if one is not set
Browse files Browse the repository at this point in the history
  • Loading branch information
gartung committed Feb 28, 2023
1 parent 9d3e42b commit 7a3b308
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions PerfTools/JeProf/src/jeprof.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 *));
}
Expand Down

0 comments on commit 7a3b308

Please sign in to comment.