Skip to content

Commit

Permalink
[PROF-9429] Search profiler mount namespace first (#393)
Browse files Browse the repository at this point in the history
When looking for file corresponding to a mapping, first
look in profiler mount namespace and if absent then
look in /proc/<pid>/root.
In the case of short lived processes, path in profiler
mount namespace will still be accessible after process
exit.
  • Loading branch information
nsavoire authored Mar 27, 2024
1 parent 3e7ad73 commit fb04551
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions src/dso_hdr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -531,9 +531,16 @@ Dso DsoHdr::dso_from_proc_line(int pid, const char *line) {
FileInfo DsoHdr::find_file_info(const Dso &dso) {
int64_t size;
inode_t inode;
// to ensure we always retrieve the file in the context of our process, we go
// through proc maps
// Example : /proc/<pid>/root/usr/local/bin/exe_file

// First, try to find matching file in profiler mount namespace since it will
// still be accessible when process exits
if (get_file_inode(dso._filename.c_str(), &inode, &size) &&
inode == dso._inode) {
return {dso._filename, size, inode};
}

// Try to find matching file in the context of our process, we
// go through proc maps Example : /proc/<pid>/root/usr/local/bin/exe_file
// or /host/proc/<pid>/root/usr/local/bin/exe_file
std::string const proc_path = _path_to_proc + "/proc/" +
std::to_string(dso._pid) + "/root" + dso._filename;
Expand All @@ -543,14 +550,6 @@ FileInfo DsoHdr::find_file_info(const Dso &dso) {
}
return {proc_path, size, inode};
}
// Try to find file in profiler mount namespace
if (get_file_inode(dso._filename.c_str(), &inode, &size)) {
if (inode != dso._inode) {
// There are cases where binaries self modify
LG_DBG("[DSO] inode mismatch for %s", dso._filename.c_str());
}
return {dso._filename, size, inode};
}

LG_DBG("[DSO] Unable to find path to %s", dso._filename.c_str());
return {};
Expand Down

0 comments on commit fb04551

Please sign in to comment.