From ddac1e453489cbd38379fffe7b09b49c83c8cf49 Mon Sep 17 00:00:00 2001 From: "Jonathan R. Madsen" Date: Wed, 29 Jun 2022 19:39:55 -0500 Subject: [PATCH] Handle OMNITRACE_ENABLED + minor updates (#78) - handle OMNITRACE_ENABLED=OFF by disabling everything - use set_data to get wrappee in pthread_create_gotcha - clear roctracer_data storage if roctracer not initialized [ROCm/rocprofiler-systems commit: f82845388aab108ed1d1fc404f433a0def391bb3] --- .../library/components/pthread_create_gotcha.cpp | 15 ++++++++++----- .../library/components/pthread_create_gotcha.hpp | 9 ++++++++- .../omnitrace/library/components/roctracer.cpp | 7 ++++++- .../library/components/roctracer_callbacks.cpp | 9 +++++++++ .../library/components/roctracer_callbacks.hpp | 3 +++ .../source/lib/omnitrace/library/config.cpp | 16 ++++++++++++++++ .../source/lib/omnitrace/library/ompt.cpp | 1 + 7 files changed, 53 insertions(+), 7 deletions(-) diff --git a/projects/rocprofiler-systems/source/lib/omnitrace/library/components/pthread_create_gotcha.cpp b/projects/rocprofiler-systems/source/lib/omnitrace/library/components/pthread_create_gotcha.cpp index 030c6e245f..0274742a9e 100644 --- a/projects/rocprofiler-systems/source/lib/omnitrace/library/components/pthread_create_gotcha.cpp +++ b/projects/rocprofiler-systems/source/lib/omnitrace/library/components/pthread_create_gotcha.cpp @@ -29,10 +29,9 @@ #include "library/runtime.hpp" #include "library/sampling.hpp" #include "library/thread_data.hpp" -#include "timemory/components/timing/wall_clock.hpp" -#include #include +#include #include #include @@ -203,6 +202,7 @@ void pthread_create_gotcha::configure() { pthread_create_gotcha_t::get_initializer() = []() { + if(!tim::settings::enabled()) return; pthread_create_gotcha_t::template configure< 0, int, pthread_t*, const pthread_attr_t*, void* (*) (void*), void*>( "pthread_create"); @@ -257,6 +257,12 @@ pthread_create_gotcha::shutdown(int64_t _tid) } } +void +pthread_create_gotcha::set_data(wrappee_t _v) +{ + m_wrappee = _v; +} + // pthread_create int pthread_create_gotcha::operator()(pthread_t* thread, const pthread_attr_t* attr, @@ -282,8 +288,7 @@ pthread_create_gotcha::operator()(pthread_t* thread, const pthread_attr_t* attr, { auto* _obj = new wrapper(start_routine, arg, _enable_sampling, _tid, nullptr); // create the thread - auto _ret = - ::pthread_create(thread, attr, &wrapper::wrap, static_cast(_obj)); + auto _ret = (*m_wrappee)(thread, attr, &wrapper::wrap, static_cast(_obj)); return _ret; } @@ -300,7 +305,7 @@ pthread_create_gotcha::operator()(pthread_t* thread, const pthread_attr_t* attr, auto* _wrap = new wrapper(start_routine, arg, _enable_sampling, _tid, &_promise); // create the thread - auto _ret = ::pthread_create(thread, attr, &wrapper::wrap, static_cast(_wrap)); + auto _ret = (*m_wrappee)(thread, attr, &wrapper::wrap, static_cast(_wrap)); // wait for thread to set promise OMNITRACE_DEBUG("waiting for child to signal it is setup...\n"); diff --git a/projects/rocprofiler-systems/source/lib/omnitrace/library/components/pthread_create_gotcha.hpp b/projects/rocprofiler-systems/source/lib/omnitrace/library/components/pthread_create_gotcha.hpp index 7e6b466a61..29d675db0c 100644 --- a/projects/rocprofiler-systems/source/lib/omnitrace/library/components/pthread_create_gotcha.hpp +++ b/projects/rocprofiler-systems/source/lib/omnitrace/library/components/pthread_create_gotcha.hpp @@ -34,9 +34,11 @@ namespace omnitrace { struct pthread_create_gotcha : tim::component::base { + using routine_t = void* (*) (void*); + using wrappee_t = int (*)(pthread_t*, const pthread_attr_t*, routine_t, void*); + struct wrapper { - using routine_t = void* (*) (void*); using promise_t = std::promise; wrapper(routine_t _routine, void* _arg, bool, int64_t, promise_t*); @@ -68,6 +70,11 @@ struct pthread_create_gotcha : tim::component::base static auto& get_execution_time(int64_t _tid = threading::get_id()); static bool is_valid_execution_time(int64_t _tid, uint64_t _ts); + + void set_data(wrappee_t); + +private: + wrappee_t m_wrappee = &pthread_create; }; inline auto& diff --git a/projects/rocprofiler-systems/source/lib/omnitrace/library/components/roctracer.cpp b/projects/rocprofiler-systems/source/lib/omnitrace/library/components/roctracer.cpp index 39e277bfe5..73cf3af4ad 100644 --- a/projects/rocprofiler-systems/source/lib/omnitrace/library/components/roctracer.cpp +++ b/projects/rocprofiler-systems/source/lib/omnitrace/library/components/roctracer.cpp @@ -166,7 +166,12 @@ void roctracer::shutdown() { auto_lock_t _lk{ type_mutex() }; - if(!roctracer_is_setup()) return; + if(!roctracer_is_setup()) + { + if(!roctracer_is_init() && tim::storage::instance()) + tim::storage::instance()->reset(); + return; + } roctracer_is_setup() = false; OMNITRACE_VERBOSE_F(1, "shutting down roctracer...\n"); diff --git a/projects/rocprofiler-systems/source/lib/omnitrace/library/components/roctracer_callbacks.cpp b/projects/rocprofiler-systems/source/lib/omnitrace/library/components/roctracer_callbacks.cpp index 840e0d504f..dc836b65b7 100644 --- a/projects/rocprofiler-systems/source/lib/omnitrace/library/components/roctracer_callbacks.cpp +++ b/projects/rocprofiler-systems/source/lib/omnitrace/library/components/roctracer_callbacks.cpp @@ -853,6 +853,13 @@ hip_activity_callback(const char* begin, const char* end, void*) } } +bool& +roctracer_is_init() +{ + static bool _v = tim::get_env("OMNITRACE_ROCTRACER_IS_INIT", false); + return _v; +} + bool& roctracer_is_setup() { @@ -892,7 +899,9 @@ extern "C" const char* const* failed_tool_names) { if(!tim::get_env("OMNITRACE_INIT_TOOLING", true)) return true; + if(!tim::settings::enabled()) return true; + roctracer_is_init() = true; pthread_gotcha::push_enable_sampling_on_child_threads(false); OMNITRACE_CONDITIONAL_BASIC_PRINT_F(get_debug_env() || get_verbose_env() > 0, "\n"); diff --git a/projects/rocprofiler-systems/source/lib/omnitrace/library/components/roctracer_callbacks.hpp b/projects/rocprofiler-systems/source/lib/omnitrace/library/components/roctracer_callbacks.hpp index 8e2a4c25de..bc598bdb1c 100644 --- a/projects/rocprofiler-systems/source/lib/omnitrace/library/components/roctracer_callbacks.hpp +++ b/projects/rocprofiler-systems/source/lib/omnitrace/library/components/roctracer_callbacks.hpp @@ -71,6 +71,9 @@ hip_api_callback(uint32_t domain, uint32_t cid, const void* callback_data, void* void hip_activity_callback(const char* begin, const char* end, void*); +bool& +roctracer_is_init(); + bool& roctracer_is_setup(); diff --git a/projects/rocprofiler-systems/source/lib/omnitrace/library/config.cpp b/projects/rocprofiler-systems/source/lib/omnitrace/library/config.cpp index 2900df9a28..0ee7fb9407 100644 --- a/projects/rocprofiler-systems/source/lib/omnitrace/library/config.cpp +++ b/projects/rocprofiler-systems/source/lib/omnitrace/library/config.cpp @@ -604,6 +604,22 @@ configure_mode_settings() // recycle all subsequent thread ids threading::recycle_ids() = tim::get_env("OMNITRACE_RECYCLE_TIDS", !get_use_sampling()); + + if(!get_config()->get_enabled()) + { + _set("OMNITRACE_USE_PERFETTO", false); + _set("OMNITRACE_USE_TIMEMORY", false); + _set("OMNITRACE_USE_ROCM_SMI", false); + _set("OMNITRACE_USE_ROCTRACER", false); + _set("OMNITRACE_USE_KOKKOSP", false); + _set("OMNITRACE_USE_OMPT", false); + _set("OMNITRACE_USE_SAMPLING", false); + _set("OMNITRACE_USE_PROCESS_SAMPLING", false); + _set("OMNITRACE_USE_CODE_COVERAGE", false); + _set("OMNITRACE_CRITICAL_TRACE", false); + set_setting_value("OMNITRACE_TIMEMORY_COMPONENTS", std::string{}); + set_setting_value("OMNITRACE_PAPI_EVENTS", std::string{}); + } } void diff --git a/projects/rocprofiler-systems/source/lib/omnitrace/library/ompt.cpp b/projects/rocprofiler-systems/source/lib/omnitrace/library/ompt.cpp index 6a64b297a9..fb702ea044 100644 --- a/projects/rocprofiler-systems/source/lib/omnitrace/library/ompt.cpp +++ b/projects/rocprofiler-systems/source/lib/omnitrace/library/ompt.cpp @@ -61,6 +61,7 @@ bool _init_toolset_off = (trait::runtime_enabled::set(false), void setup() { + if(!tim::settings::enabled()) return; trait::runtime_enabled::set(true); trait::runtime_enabled::set(true); comp::user_ompt_bundle::global_init();