25#if !defined(TIMEMORY_LIBRARY_SOURCE)
26# define TIMEMORY_LIBRARY_SOURCE 1
29#include "timemory/backends/process.hpp"
40#if !defined(TIMEMORY_WINDOWS)
45#if defined(TIMEMORY_WINDOWS)
46# define DLSYM_FUNCTION(VARNAME, HANDLE, FUNCNAME)
48# define DLSYM_FUNCTION(VARNAME, HANDLE, FUNCNAME) \
51 *(void**) (&VARNAME) = dlsym(HANDLE, FUNCNAME.c_str()); \
52 if(VARNAME == nullptr) \
54 fprintf(stderr, "[%s][pid=%i]> %s\n", FUNCNAME.c_str(), \
55 tim::process::get_id(), dlerror()); \
64#if !defined(OS_DYNAMIC_LIBRARY_EXT)
65# if defined(TIMEMORY_MACOS)
66# define OS_DYNAMIC_LIBRARY_EXT "dylib"
67# elif defined(TIMEMORY_WINDOWS)
68# define OS_DYNAMIC_LIBRARY_EXT "dll"
70# define OS_DYNAMIC_LIBRARY_EXT "so"
74struct tools_stubs_dlsym
76 using ctor_function_t = void (*)();
77 using register_function_t = void (*)();
78 using deregister_function_t = void (*)();
79 using start_function_t = uint64_t (*)();
80 using stop_function_t = uint64_t (*)(uint64_t);
82 TIMEMORY_DEFAULT_OBJECT(tools_stubs_dlsym)
85 : m_id{ std::move(
id) }
86 , m_libname{ std::move(libname) }
94#if !defined(TIMEMORY_WINDOWS)
99 auto* libhandle = dlopen(m_libname.c_str(), RTLD_LAZY | RTLD_GLOBAL);
104 fprintf(stderr,
"%s\n", dlerror());
109 auto ctor_name =
TIMEMORY_JOIN(
"",
"timemory_", m_id,
"_library_ctor");
110 auto register_name =
TIMEMORY_JOIN(
"",
"timemory_register_", m_id);
111 auto deregister_name =
TIMEMORY_JOIN(
"",
"timemory_deregister_", m_id);
112 auto start_name =
TIMEMORY_JOIN(
"",
"timemory_start_", m_id);
130 void invoke_register()
136 void invoke_deregister()
142 uint64_t invoke_start()
149 uint64_t invoke_stop(uint64_t val)
152 return (*m_stop)(val);
159 ctor_function_t m_ctor =
nullptr;
160 register_function_t m_register =
nullptr;
161 deregister_function_t m_deregister =
nullptr;
162 start_function_t m_start =
nullptr;
163 stop_function_t m_stop =
nullptr;
178#define TOOL_DLSYM_SPECIALIZAITON(INDEX, ID, ENV_VAR) \
180 tools_stubs_dlsym* get_tool_stubs<INDEX>() \
182 static auto _instance = std::unique_ptr<tools_stubs_dlsym>{}; \
185 auto _env = tim::get_env<std::string>(ENV_VAR, ""); \
186 _instance = std::make_unique<tools_stubs_dlsym>(ID, _env); \
188 return _instance.get(); \
196#define TOOL_INDEX(NAME) NAME##_idx
197#define TOOL_DLSYM(NAME) get_tool_stubs<TOOL_INDEX(NAME)>()
198#define TOOL_PREFIX TIMEMORY_WEAK_PREFIX
199#define TOOL_SUFFIX TIMEMORY_WEAK_POSTFIX TIMEMORY_VISIBILITY("default")
200#define TOOL_STUBS(NAME) \
202 void timemory_##NAME##_library_ctor() TOOL_SUFFIX; \
204 void timemory_register_##NAME() TOOL_SUFFIX; \
206 void timemory_deregister_##NAME() TOOL_SUFFIX; \
208 uint64_t timemory_start_##NAME() TOOL_SUFFIX; \
210 uint64_t timemory_stop_##NAME(uint64_t) TOOL_SUFFIX; \
212 void timemory_##NAME##_library_ctor() { TOOL_DLSYM(NAME)->invoke_ctor(); } \
213 void timemory_register_##NAME() { TOOL_DLSYM(NAME)->invoke_register(); } \
214 void timemory_deregister_##NAME() { TOOL_DLSYM(NAME)->invoke_deregister(); } \
215 uint64_t timemory_start_##NAME() { return TOOL_DLSYM(NAME)->invoke_start(); } \
216 uint64_t timemory_stop_##NAME(uint64_t v) { return TOOL_DLSYM(NAME)->invoke_stop(v); }
void load(Archive &ar, tim::node::graph< Tp > &d)
tim::mpl::apply< std::string > string
#define DEBUG_PRINT_HERE(...)
#define TIMEMORY_JOIN(delim,...)
#define DLSYM_FUNCTION(VARNAME, HANDLE, FUNCNAME)
#define TOOL_DLSYM_SPECIALIZAITON(INDEX, ID, ENV_VAR)
#define OS_DYNAMIC_LIBRARY_EXT
tools_stubs_dlsym * get_tool_stubs()