Skip to content

Commit

Permalink
Handle OMNITRACE_ENABLED + minor updates (#78)
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
jrmadsen authored Jun 30, 2022
1 parent 2e1fd5a commit f828453
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 7 deletions.
15 changes: 10 additions & 5 deletions source/lib/omnitrace/library/components/pthread_create_gotcha.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <bits/stdint-intn.h>
#include <timemory/backends/threading.hpp>
#include <timemory/components/timing/wall_clock.hpp>
#include <timemory/sampling/allocator.hpp>
#include <timemory/utility/types.hpp>

Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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,
Expand All @@ -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<void*>(_obj));
auto _ret = (*m_wrappee)(thread, attr, &wrapper::wrap, static_cast<void*>(_obj));
return _ret;
}

Expand All @@ -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<void*>(_wrap));
auto _ret = (*m_wrappee)(thread, attr, &wrapper::wrap, static_cast<void*>(_wrap));

// wait for thread to set promise
OMNITRACE_DEBUG("waiting for child to signal it is setup...\n");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@ namespace omnitrace
{
struct pthread_create_gotcha : tim::component::base<pthread_create_gotcha, void>
{
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<void>;

wrapper(routine_t _routine, void* _arg, bool, int64_t, promise_t*);
Expand Down Expand Up @@ -68,6 +70,11 @@ struct pthread_create_gotcha : tim::component::base<pthread_create_gotcha, void>

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&
Expand Down
7 changes: 6 additions & 1 deletion source/lib/omnitrace/library/components/roctracer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,12 @@ void
roctracer::shutdown()
{
auto_lock_t _lk{ type_mutex<roctracer>() };
if(!roctracer_is_setup()) return;
if(!roctracer_is_setup())
{
if(!roctracer_is_init() && tim::storage<comp::roctracer_data>::instance())
tim::storage<comp::roctracer_data>::instance()->reset();
return;
}
roctracer_is_setup() = false;

OMNITRACE_VERBOSE_F(1, "shutting down roctracer...\n");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
16 changes: 16 additions & 0 deletions source/lib/omnitrace/library/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,22 @@ configure_mode_settings()
// recycle all subsequent thread ids
threading::recycle_ids() =
tim::get_env<bool>("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
Expand Down
1 change: 1 addition & 0 deletions source/lib/omnitrace/library/ompt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ bool _init_toolset_off = (trait::runtime_enabled<ompt_toolset_t>::set(false),
void
setup()
{
if(!tim::settings::enabled()) return;
trait::runtime_enabled<ompt_toolset_t>::set(true);
trait::runtime_enabled<ompt_context_t>::set(true);
comp::user_ompt_bundle::global_init();
Expand Down

0 comments on commit f828453

Please sign in to comment.