Skip to content

Commit

Permalink
manually clean rocprofiler.pid in RdcWrapper (#323)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #323

rocprofiler.pid is a lock used by rocprofiler to guarantee exclusive access by a single process. the lock will be created the first time instantiate rocprofiler but will not be cleaned up by rdc_shutdown() function

for now, we will need to manually remove this lock

Reviewed By: jj10306

Differential Revision: D65249799

fbshipit-source-id: f23f970fe1ad81a77ace217b4bf4598c1c788e3d
  • Loading branch information
Alston Tang authored and facebook-github-bot committed Nov 1, 2024
1 parent a0940cc commit cc11dae
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions dynolog/src/gpumon/amd/RdcWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "dynolog/src/gpumon/amd/RdcWrapper.h"

#include <glog/logging.h>
#include <fstream>
#include <mutex>

namespace dynolog {
Expand Down Expand Up @@ -113,6 +114,26 @@ void RdcWrapper::clean_(RdcRuntimeContextWithWLock& context) {
if (result != RDC_ST_OK) {
LOG(WARNING) << "rdc_shutdown() failed with error code: " << result;
}

static const char* rocprofilerLockPath = "/tmp/rocprofiler.pid";
std::ifstream rocprofilerLock(rocprofilerLockPath);
if (rocprofilerLock.fail()) {
// rdc may not start rocprofiler
// it's fine if the lock file doesn't exist
return;
}
pid_t rocprofilerPid = -1;
if (rocprofilerLock >> rocprofilerPid) {
if (rocprofilerPid == getpid()) {
LOG(INFO) << "remove rocprofiler.pid";
if (std::remove(rocprofilerLockPath) != 0) {
LOG(ERROR) << "failed to remove rocprofiler lock at "
<< rocprofilerLockPath;
}
}
} else {
LOG(WARNING) << "failed to read pid from rocprofiler lock file";
}
}

RdcMetricsMap RdcWrapper::getRdcMetricsForDevice(size_t device) {
Expand Down

0 comments on commit cc11dae

Please sign in to comment.