Skip to content

Commit

Permalink
dont bind if LDPRELOAD is used.
Browse files Browse the repository at this point in the history
  • Loading branch information
hariharan-devarajan committed Oct 6, 2023
1 parent 4859b24 commit afdad82
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 17 deletions.
31 changes: 18 additions & 13 deletions src/dlio_profiler/core/dlio_profiler_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,11 @@ namespace dlio_profiler {
std::string data_dirs;
int process_id;
bool is_init;
bool bind;
public:
DLIOProfiler(bool is_init, const char *log_file = nullptr, const char *data_dirs = nullptr, const int *process_id = nullptr) : is_enabled(
DLIOProfiler(bool is_init, bool bind, const char *log_file = nullptr, const char *data_dirs = nullptr, const int *process_id = nullptr) : is_enabled(
false), gotcha_priority(1), logger_level(cpplogger::LoggerType::LOG_ERROR), log_file(), data_dirs(
), is_init(is_init) {
), is_init(is_init), bind(bind) {
signal(SIGSEGV, handler);
if (this->is_init) {
char *dlio_profiler_log_level = getenv(DLIO_PROFILER_LOG_LEVEL);
Expand Down Expand Up @@ -108,16 +109,18 @@ namespace dlio_profiler {
DLIO_PROFILER_LOGINFO("Setting process_id to %d", this->process_id);

dlio_profiler::Singleton<DLIOLogger>::get_instance()->update_log_file(this->log_file, this->process_id);
brahma_gotcha_wrap("dlio_profiler", this->gotcha_priority);
auto posix_instance = brahma::POSIXDLIOProfiler::get_instance();
auto stdio_instance = brahma::STDIODLIOProfiler::get_instance();
auto paths = split(this->data_dirs, ':');
posix_instance->untrace(this->log_file.c_str());
stdio_instance->untrace(this->log_file.c_str());
for (const auto &path:paths) {
DLIO_PROFILER_LOGINFO("Profiler will trace %s\n", path.c_str());
posix_instance->trace(path.c_str());
stdio_instance->trace(path.c_str());
if (bind) {
brahma_gotcha_wrap("dlio_profiler", this->gotcha_priority);
auto posix_instance = brahma::POSIXDLIOProfiler::get_instance();
auto stdio_instance = brahma::STDIODLIOProfiler::get_instance();
auto paths = split(this->data_dirs, ':');
posix_instance->untrace(this->log_file.c_str());
stdio_instance->untrace(this->log_file.c_str());
for (const auto &path:paths) {
DLIO_PROFILER_LOGINFO("Profiler will trace %s\n", path.c_str());
posix_instance->trace(path.c_str());
stdio_instance->trace(path.c_str());
}
}
size_t thread_hash = std::hash<std::thread::id>{}(std::this_thread::get_id());
DLIO_PROFILER_LOGINFO("Running DLIO Profiler on thread %ld and pid %ld", thread_hash, this->process_id);
Expand All @@ -132,7 +135,9 @@ namespace dlio_profiler {
if (is_init && is_enabled) {
DLIO_PROFILER_LOGINFO("Calling finalize", "");
dlio_profiler::Singleton<DLIOLogger>::get_instance(false)->finalize();
free_bindings();
if (bind) {
free_bindings();
}
return true;
}
return false;
Expand Down
4 changes: 2 additions & 2 deletions src/dlio_profiler/dlio_profiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ void dlio_profiler_init(void) {
char *init_type_count = getenv(DLIO_PROFILER_INIT_COUNT);
char *init_type = getenv(DLIO_PROFILER_INIT);
if (init_type_count == nullptr && init_type != nullptr && strcmp(init_type, "PRELOAD") == 0) {
dlio_profiler::Singleton<dlio_profiler::DLIOProfiler>::get_instance(true);
dlio_profiler::Singleton<dlio_profiler::DLIOProfiler>::get_instance(true, true);
DLIO_PROFILER_LOGINFO("Running initialize within constructor %d", getpid());
set_init(true);
int val = setenv(DLIO_PROFILER_INIT_COUNT, "1", 1);
Expand All @@ -34,7 +34,7 @@ void dlio_profiler_fini(void) {
char *init_type = getenv(DLIO_PROFILER_INIT);
char *init_type_count = getenv(DLIO_PROFILER_INIT_COUNT);
if (init_type_count != nullptr && init_type != nullptr && strcmp(init_type, "PRELOAD")) {
dlio_profiler::Singleton<dlio_profiler::DLIOProfiler>::get_instance(false)->finalize();
dlio_profiler::Singleton<dlio_profiler::DLIOProfiler>::get_instance(false, false)->finalize();
set_init(false);
int val = unsetenv(DLIO_PROFILER_INIT_COUNT);
(void) val;
Expand Down
6 changes: 4 additions & 2 deletions src/dlio_profiler/dlio_profiler_py.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ namespace dlio_profiler {
void initialize(std::string &log_file, std::string &data_dirs, int process_id) {
char *init_type = getenv(DLIO_PROFILER_INIT);
if (init_type == nullptr || strcmp(init_type, "FUNCTION") == 0) {
dlio_profiler::Singleton<dlio_profiler::DLIOProfiler>::get_instance(true, log_file.c_str(), data_dirs.c_str(), &process_id);
dlio_profiler::Singleton<dlio_profiler::DLIOProfiler>::get_instance(true, true, log_file.c_str(), data_dirs.c_str(), &process_id);
} else {
dlio_profiler::Singleton<dlio_profiler::DLIOProfiler>::get_instance(true, false, log_file.c_str(), data_dirs.c_str(), &process_id);
}
}
TimeResolution get_time() {
Expand All @@ -42,7 +44,7 @@ namespace dlio_profiler {
void finalize() {
char *init_type = getenv(DLIO_PROFILER_INIT);
if (init_type == nullptr || strcmp(init_type, "FUNCTION") == 0) {
dlio_profiler::Singleton<dlio_profiler::DLIOProfiler>::get_instance(false)->finalize();
dlio_profiler::Singleton<dlio_profiler::DLIOProfiler>::get_instance(false, false)->finalize();
}
}
} // dlio_profiler
Expand Down

0 comments on commit afdad82

Please sign in to comment.