Skip to content

Commit

Permalink
Merge pull request #15 from hariharan-devarajan/feature/optional_posix
Browse files Browse the repository at this point in the history
Ability to disable POSIX and STDIO calls or all I/O calls.
  • Loading branch information
hariharan-devarajan authored Oct 11, 2023
2 parents 5962303 + b2601fe commit 1a02723
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 13 deletions.
3 changes: 3 additions & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ Configurations of DLIO Profiler
DLIO_PROFILER_INC_METADATA needs to be enabled.
DLIO_PROFILER_GOTCHA_PRIORITY INT PRIORITY of DLIO Profiler in GOTCHA (default: 1).
DLIO_PROFILER_LOG_LEVEL STRING Logging level within DLIO Profiler ERROR/INFO (default INFO).
DLIO_PROFILER_DISABLE_IO STRING Disable automatic binding of all I/O calls.
DLIO_PROFILER_DISABLE_POSIX STRING Disable automatic binding of POSIX I/O calls.
DLIO_PROFILER_DISABLE_STDIO STRING Disable automatic binding of STDIO I/O calls.
================================ ====== ===========================================================================

======================
Expand Down
3 changes: 3 additions & 0 deletions include/dlio_profiler/core/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
#define DLIO_PROFILER_SET_CORE_AFFINITY "DLIO_PROFILER_SET_CORE_AFFINITY"
#define DLIO_PROFILER_ERROR "DLIO_PROFILER_ERROR"
#define DLIO_PROFILER_INC_METADATA "DLIO_PROFILER_INC_METADATA"
#define DLIO_PROFILER_DISABLE_POSIX "DLIO_PROFILER_DISABLE_POSIX"
#define DLIO_PROFILER_DISABLE_STDIO "DLIO_PROFILER_DISABLE_STDIO"
#define DLIO_PROFILER_DISABLE_IO "DLIO_PROFILER_DISABLE_IO"
#define CPP_LOG_CATEGORY "CPP_APP"
#define C_LOG_CATEGORY "C_APP"

Expand Down
3 changes: 3 additions & 0 deletions include/dlio_profiler/core/dlio_profiler_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ namespace dlio_profiler {
int process_id;
bool is_initialized;
bool bind;
bool enable_posix;
bool enable_stdio;
bool enable_io;

void initlialize(bool is_init, bool _bind, const char *_log_file = nullptr, const char *_data_dirs = nullptr,
const int *_process_id = nullptr);
Expand Down
39 changes: 26 additions & 13 deletions src/dlio_profiler/core/dlio_profiler_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
dlio_profiler::DLIOProfilerCore::DLIOProfilerCore(ProfilerStage stage, ProfileType type, const char *log_file,
const char *data_dirs, const int *process_id) : is_enabled(
false), gotcha_priority(1), logger_level(cpplogger::LoggerType::LOG_ERROR), log_file(), data_dirs(),
is_initialized(false),
bind(false) {
is_initialized(false), bind(false), enable_io(false), enable_stdio(false), enable_posix(false) {
const char *user_init_type = getenv(DLIO_PROFILER_INIT);
switch (type) {
case ProfileType::PROFILER_PRELOAD: {
Expand Down Expand Up @@ -59,7 +58,7 @@ bool dlio_profiler::DLIOProfilerCore::finalize() {
if (this->is_initialized && is_enabled) {
DLIO_PROFILER_LOGINFO("Calling finalize on pid %d", this->process_id);
dlio_profiler::Singleton<DLIOLogger>::get_instance(false)->finalize();
if (bind) {
if (bind && enable_io) {
free_bindings();
}
this->is_initialized = false;
Expand Down Expand Up @@ -160,16 +159,30 @@ dlio_profiler::DLIOProfilerCore::initlialize(bool is_init, bool _bind, const cha
DLIO_PROFILER_LOGINFO("Setting data_dirs to %s", this->data_dirs.c_str());
dlio_profiler::Singleton<DLIOLogger>::get_instance()->update_log_file(this->log_file, this->process_id);
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());
char *disable_io = getenv(DLIO_PROFILER_DISABLE_IO);
char *disable_posix = getenv(DLIO_PROFILER_DISABLE_POSIX);
char *disable_stdio = getenv(DLIO_PROFILER_DISABLE_STDIO);
if (disable_io == nullptr || strcmp(disable_io, "1") != 0) {
enable_io = true;
auto paths = split(this->data_dirs, ':');
brahma_gotcha_wrap("dlio_profiler", this->gotcha_priority);
if (disable_posix == nullptr || strcmp(disable_posix, "1") != 0) {
enable_posix = true;
auto posix_instance = brahma::POSIXDLIOProfiler::get_instance();
posix_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());
}
}
if (disable_stdio == nullptr || strcmp(disable_stdio, "1") != 0) {
enable_stdio = true;
auto stdio_instance = brahma::STDIODLIOProfiler::get_instance();
stdio_instance->untrace(this->log_file.c_str());
for (const auto &path:paths) {
stdio_instance->trace(path.c_str());
}
}
}
}
}
Expand Down

0 comments on commit 1a02723

Please sign in to comment.