Skip to content

Commit

Permalink
add pid for log files set through env variables.
Browse files Browse the repository at this point in the history
  • Loading branch information
hariharan-devarajan committed Oct 6, 2023
1 parent a0cb02c commit e8b4668
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
16 changes: 8 additions & 8 deletions src/dlio_profiler/core/dlio_profiler_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,16 @@ namespace dlio_profiler {
if (dlio_profiler_priority_str != nullptr) {
gotcha_priority = atoi(dlio_profiler_priority_str);
}

if (process_id == nullptr) {
this->process_id = getpid();
} else {
this->process_id = *process_id;
}
DLIO_PROFILER_LOGINFO("Setting process_id to %d", this->process_id);
if (log_file == nullptr) {
char *dlio_profiler_log = getenv(DLIO_PROFILER_LOG_FILE);
if (dlio_profiler_log != nullptr) {
this->log_file = dlio_profiler_log;
this->log_file = std::string(dlio_profiler_log) + "-" + std::to_string(this->process_id) + ".pfw";
} else {
const char *message = "log_file not defined. Please define env variable DLIO_PROFILER_LOG_FILE";
DLIO_PROFILER_LOGERROR(message, "");
Expand All @@ -101,12 +106,7 @@ namespace dlio_profiler {
}

DLIO_PROFILER_LOGINFO("Setting data_dirs to %s", this->data_dirs.c_str());
if (process_id == nullptr) {
this->process_id = getpid();
} else {
this->process_id = *process_id;
}
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);
if (bind) {
Expand Down
3 changes: 2 additions & 1 deletion src/dlio_profiler/dlio_profiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ 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, true);
int pid = getpid();
dlio_profiler::Singleton<dlio_profiler::DLIOProfiler>::get_instance(true, true, nullptr, nullptr, &pid);
DLIO_PROFILER_LOGINFO("Running initialize within constructor %d", getpid());
set_init(true);
int val = setenv(DLIO_PROFILER_INIT_COUNT, "1", 1);
Expand Down

0 comments on commit e8b4668

Please sign in to comment.