From b2601fe587cd521942d1f9e3640a4d52170455a0 Mon Sep 17 00:00:00 2001 From: Hariharan Devarajan Date: Tue, 10 Oct 2023 19:51:30 -0700 Subject: [PATCH] Ability to disable POSIX and STDIO calls or all I/O calls. --- docs/api.rst | 3 ++ include/dlio_profiler/core/constants.h | 3 ++ .../dlio_profiler/core/dlio_profiler_main.h | 3 ++ src/dlio_profiler/core/dlio_profiler_main.cpp | 39 ++++++++++++------- 4 files changed, 35 insertions(+), 13 deletions(-) diff --git a/docs/api.rst b/docs/api.rst index 1113d2de..8fe67669 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -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. ================================ ====== =========================================================================== ====================== diff --git a/include/dlio_profiler/core/constants.h b/include/dlio_profiler/core/constants.h index b01895b7..b17e5758 100644 --- a/include/dlio_profiler/core/constants.h +++ b/include/dlio_profiler/core/constants.h @@ -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" diff --git a/include/dlio_profiler/core/dlio_profiler_main.h b/include/dlio_profiler/core/dlio_profiler_main.h index 790405e7..1752340e 100644 --- a/include/dlio_profiler/core/dlio_profiler_main.h +++ b/include/dlio_profiler/core/dlio_profiler_main.h @@ -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); diff --git a/src/dlio_profiler/core/dlio_profiler_main.cpp b/src/dlio_profiler/core/dlio_profiler_main.cpp index e408d684..dffeebd8 100644 --- a/src/dlio_profiler/core/dlio_profiler_main.cpp +++ b/src/dlio_profiler/core/dlio_profiler_main.cpp @@ -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: { @@ -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::get_instance(false)->finalize(); - if (bind) { + if (bind && enable_io) { free_bindings(); } this->is_initialized = false; @@ -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::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()); + } + } } } }