diff --git a/TracyClientDLL.cpp b/TracyClientDLL.cpp index ef51c608..3f810594 100644 --- a/TracyClientDLL.cpp +++ b/TracyClientDLL.cpp @@ -11,78 +11,9 @@ // Define TRACY_ENABLE to enable profiler. -#include "common/TracySystem.cpp" - #ifdef TRACY_ENABLE - -#include "client/TracyProfiler.hpp" -#include "client/concurrentqueue.h" - -#include "common/TracyQueue.hpp" - -#ifdef __APPLE__ -# include -#endif - -namespace tracy -{ -#ifdef _WIN32 -# define DLL_IMPORT __declspec(dllimport) -#else -# define DLL_IMPORT -#endif - - DLL_IMPORT void*(*get_rpmalloc())(size_t size); - DLL_IMPORT void(*get_rpfree())(void* ptr); - DLL_IMPORT moodycamel::ConcurrentQueue::ExplicitProducer*(*get_token())(); - DLL_IMPORT Profiler&(*get_profiler())(); - DLL_IMPORT std::atomic&(*get_getlockcounter())(); - DLL_IMPORT std::atomic&(*get_getgpuctxcounter())(); - DLL_IMPORT GpuCtxWrapper&(*get_getgpuctx())(); - - static void*(*rpmalloc_fpt)(size_t size) = get_rpmalloc(); - static void(*rpfree_fpt)(void* ptr) = get_rpfree(); - static moodycamel::ConcurrentQueue::ExplicitProducer*(*GetToken_fpt)() = get_token(); - static Profiler&(*GetProfiler_fpt)() = get_profiler(); - static std::atomic&(*GetLockCounter_fpt)() = get_getlockcounter(); - static std::atomic&(*GetGpuCtxCounter_fpt)() = get_getgpuctxcounter(); - static GpuCtxWrapper&(*GetGpuCtx_fpt)() = get_getgpuctx(); - - RPMALLOC_RESTRICT void* rpmalloc(size_t size) { return rpmalloc_fpt(size); } - void rpfree(void* ptr) { rpfree_fpt(ptr); } - moodycamel::ConcurrentQueue::ExplicitProducer* GetToken() { return GetToken_fpt(); } - Profiler& GetProfiler() { return GetProfiler_fpt(); } - std::atomic& GetLockCounter() { return GetLockCounter_fpt(); } - std::atomic& GetGpuCtxCounter() { return GetGpuCtxCounter_fpt(); } - GpuCtxWrapper& GetGpuCtx() { return GetGpuCtx_fpt(); } - -#if defined TRACY_HW_TIMER && __ARM_ARCH >= 6 && !defined TARGET_OS_IOS - DLL_IMPORT int64_t(*get_GetTimeImpl())(); - - int64_t(*GetTimeImpl)() = get_GetTimeImpl(); -#endif - -#ifdef TRACY_COLLECT_THREAD_NAMES - DLL_IMPORT std::atomic&(*get_getthreadnamedata())(); - DLL_IMPORT void(*get_rpmalloc_thread_initialize())(); - DLL_IMPORT void(*get_InitRPMallocThread())(); - - static std::atomic&(*GetThreadNameData_fpt)() = get_getthreadnamedata(); - static void(*rpmalloc_thread_initialize_fpt)() = get_rpmalloc_thread_initialize(); - static void(*InitRPMallocThread_fpt)() = get_InitRPMallocThread(); - - std::atomic& GetThreadNameData() { return GetThreadNameData_fpt(); } - void rpmalloc_thread_initialize(void) { rpmalloc_thread_initialize_fpt(); } - void InitRPMallocThread() { InitRPMallocThread_fpt(); } -#endif - -#ifdef TRACY_ON_DEMAND - DLL_IMPORT LuaZoneState&(*get_getluazonestate())(); - - static LuaZoneState&(*GetLuaZoneState_fpt)() = get_getluazonestate(); - - LuaZoneState& GetLuaZoneState() { return GetLuaZoneState_fpt(); } -#endif -} - +# ifndef TRACY_IMPORTS +# define TRACY_IMPORTS 1 +# endif +# include "common/TracySystem.cpp" #endif diff --git a/TracyLua.hpp b/TracyLua.hpp index 0a034532..6c170fc0 100644 --- a/TracyLua.hpp +++ b/TracyLua.hpp @@ -136,7 +136,7 @@ namespace tracy { #ifdef TRACY_ON_DEMAND -LuaZoneState& GetLuaZoneState(); +TRACY_API LuaZoneState& GetLuaZoneState(); #endif namespace detail diff --git a/client/TracyProfiler.cpp b/client/TracyProfiler.cpp index f9f2b266..844011f5 100644 --- a/client/TracyProfiler.cpp +++ b/client/TracyProfiler.cpp @@ -772,12 +772,12 @@ static Thread* s_thread; #ifdef TRACY_DELAYED_INIT struct ThreadNameData; -moodycamel::ConcurrentQueue& GetQueue(); +TRACY_API moodycamel::ConcurrentQueue& GetQueue(); struct RPMallocInit { RPMallocInit() { rpmalloc_initialize(); } }; struct RPMallocThreadInit { RPMallocThreadInit() { rpmalloc_thread_initialize(); } }; -void InitRPMallocThread() +TRACY_API void InitRPMallocThread() { rpmalloc_initialize(); rpmalloc_thread_initialize(); @@ -834,24 +834,24 @@ static ProfilerThreadData& GetProfilerThreadData() return data; } -moodycamel::ConcurrentQueue::ExplicitProducer* GetToken() { return GetProfilerThreadData().token.ptr; } -Profiler& GetProfiler() { return GetProfilerData().profiler; } -moodycamel::ConcurrentQueue& GetQueue() { return GetProfilerData().queue; } -int64_t GetInitTime() { return GetProfilerData().initTime; } -std::atomic& GetLockCounter() { return GetProfilerData().lockCounter; } -std::atomic& GetGpuCtxCounter() { return GetProfilerData().gpuCtxCounter; } -GpuCtxWrapper& GetGpuCtx() { return GetProfilerThreadData().gpuCtx; } +TRACY_API moodycamel::ConcurrentQueue::ExplicitProducer* GetToken() { return GetProfilerThreadData().token.ptr; } +TRACY_API Profiler& GetProfiler() { return GetProfilerData().profiler; } +TRACY_API moodycamel::ConcurrentQueue& GetQueue() { return GetProfilerData().queue; } +TRACY_API int64_t GetInitTime() { return GetProfilerData().initTime; } +TRACY_API std::atomic& GetLockCounter() { return GetProfilerData().lockCounter; } +TRACY_API std::atomic& GetGpuCtxCounter() { return GetProfilerData().gpuCtxCounter; } +TRACY_API GpuCtxWrapper& GetGpuCtx() { return GetProfilerThreadData().gpuCtx; } # ifdef TRACY_COLLECT_THREAD_NAMES -std::atomic& GetThreadNameData() { return GetProfilerData().threadNameData; } +TRACY_API std::atomic& GetThreadNameData() { return GetProfilerData().threadNameData; } # endif # ifdef TRACY_ON_DEMAND -LuaZoneState& GetLuaZoneState() { return GetProfilerThreadData().luaZoneState; } +TRACY_API LuaZoneState& GetLuaZoneState() { return GetProfilerThreadData().luaZoneState; } # endif #else -void InitRPMallocThread() +TRACY_API void InitRPMallocThread() { rpmalloc_thread_initialize(); } @@ -893,52 +893,23 @@ thread_local LuaZoneState init_order(104) s_luaZoneState { 0, false }; static Profiler init_order(105) s_profiler; -moodycamel::ConcurrentQueue::ExplicitProducer* GetToken() { return s_token.ptr; } -Profiler& GetProfiler() { return s_profiler; } -moodycamel::ConcurrentQueue& GetQueue() { return s_queue; } -int64_t GetInitTime() { return s_initTime.val; } -std::atomic& GetLockCounter() { return s_lockCounter; } -std::atomic& GetGpuCtxCounter() { return s_gpuCtxCounter; } -GpuCtxWrapper& GetGpuCtx() { return s_gpuCtx; } +TRACY_API moodycamel::ConcurrentQueue::ExplicitProducer* GetToken() { return s_token.ptr; } +TRACY_API Profiler& GetProfiler() { return s_profiler; } +TRACY_API moodycamel::ConcurrentQueue& GetQueue() { return s_queue; } +TRACY_API int64_t GetInitTime() { return s_initTime.val; } +TRACY_API std::atomic& GetLockCounter() { return s_lockCounter; } +TRACY_API std::atomic& GetGpuCtxCounter() { return s_gpuCtxCounter; } +TRACY_API GpuCtxWrapper& GetGpuCtx() { return s_gpuCtx; } # ifdef TRACY_COLLECT_THREAD_NAMES -std::atomic& GetThreadNameData() { return s_threadNameData; } +TRACY_API std::atomic& GetThreadNameData() { return s_threadNameData; } # endif # ifdef TRACY_ON_DEMAND -LuaZoneState& GetLuaZoneState() { return s_luaZoneState; } +TRACY_API LuaZoneState& GetLuaZoneState() { return s_luaZoneState; } # endif #endif -// DLL exports to enable TracyClientDLL.cpp to retrieve the instances of Tracy objects and functions -#ifdef _WIN32 -# define DLL_EXPORT __declspec(dllexport) -#else -# define DLL_EXPORT __attribute__((visibility("default"))) -#endif - -DLL_EXPORT void*(*get_rpmalloc())(size_t size) { return rpmalloc; } -DLL_EXPORT void(*get_rpfree())(void* ptr) { return rpfree; } -DLL_EXPORT moodycamel::ConcurrentQueue::ExplicitProducer*(*get_token())() { return GetToken; } -DLL_EXPORT Profiler&(*get_profiler())() { return GetProfiler; } -DLL_EXPORT std::atomic&(*get_getlockcounter())() { return GetLockCounter; } -DLL_EXPORT std::atomic&(*get_getgpuctxcounter())() { return GetGpuCtxCounter; } -DLL_EXPORT GpuCtxWrapper&(*get_getgpuctx())() { return GetGpuCtx; } - -#if defined TRACY_HW_TIMER && __ARM_ARCH >= 6 && !defined TARGET_OS_IOS -DLL_EXPORT int64_t(*get_GetTimeImpl())() { return GetTimeImpl; } -#endif - -#ifdef TRACY_COLLECT_THREAD_NAMES -DLL_EXPORT std::atomic&(*get_getthreadnamedata())() { return GetThreadNameData; } -DLL_EXPORT void(*get_rpmalloc_thread_initialize())() { return rpmalloc_thread_initialize; } -DLL_EXPORT void(*get_InitRPMallocThread())() { return InitRPMallocThread; } -#endif - -#ifdef TRACY_ON_DEMAND -DLL_EXPORT LuaZoneState&(*get_getluazonestate())() { return GetLuaZoneState; } -#endif - enum { BulkSize = TargetFrameSize / QueueItemSize }; Profiler::Profiler() diff --git a/client/TracyProfiler.hpp b/client/TracyProfiler.hpp index b6024173..e8bba8ac 100644 --- a/client/TracyProfiler.hpp +++ b/client/TracyProfiler.hpp @@ -53,11 +53,11 @@ struct GpuCtxWrapper GpuCtx* ptr; }; -moodycamel::ConcurrentQueue::ExplicitProducer* GetToken(); -Profiler& GetProfiler(); -std::atomic& GetLockCounter(); -std::atomic& GetGpuCtxCounter(); -GpuCtxWrapper& GetGpuCtx(); +TRACY_API moodycamel::ConcurrentQueue::ExplicitProducer* GetToken(); +TRACY_API Profiler& GetProfiler(); +TRACY_API std::atomic& GetLockCounter(); +TRACY_API std::atomic& GetGpuCtxCounter(); +TRACY_API GpuCtxWrapper& GetGpuCtx(); void InitRPMallocThread(); diff --git a/client/tracy_rpmalloc.cpp b/client/tracy_rpmalloc.cpp index 9e8d66c2..8dd8c98f 100644 --- a/client/tracy_rpmalloc.cpp +++ b/client/tracy_rpmalloc.cpp @@ -1906,7 +1906,7 @@ _memory_guard_block(void* block) { // Extern interface -RPMALLOC_RESTRICT void* +TRACY_API RPMALLOC_RESTRICT void* rpmalloc(size_t size) { #if ENABLE_VALIDATE_ARGS if (size >= MAX_ALLOC_SIZE) { @@ -1920,7 +1920,7 @@ rpmalloc(size_t size) { return block; } -void +TRACY_API void rpfree(void* ptr) { _memory_guard_validate(ptr); _memory_deallocate(ptr); diff --git a/client/tracy_rpmalloc.hpp b/client/tracy_rpmalloc.hpp index b6687e49..454dec70 100644 --- a/client/tracy_rpmalloc.hpp +++ b/client/tracy_rpmalloc.hpp @@ -13,6 +13,8 @@ #include +#include "../common/TracyApi.h" + namespace tracy { @@ -103,7 +105,7 @@ rpmalloc_config(void); extern void rpmalloc_finalize(void); -extern void +void rpmalloc_thread_initialize(void); extern void @@ -121,10 +123,10 @@ rpmalloc_thread_statistics(rpmalloc_thread_statistics_t* stats); extern void rpmalloc_global_statistics(rpmalloc_global_statistics_t* stats); -extern RPMALLOC_RESTRICT void* +TRACY_API RPMALLOC_RESTRICT void* rpmalloc(size_t size) RPMALLOC_ATTRIBUTE; -extern void +TRACY_API void rpfree(void* ptr); extern RPMALLOC_RESTRICT void* diff --git a/common/TracyApi.h b/common/TracyApi.h new file mode 100644 index 00000000..6a2efba2 --- /dev/null +++ b/common/TracyApi.h @@ -0,0 +1,14 @@ +#ifndef __TRACYAPI_H__ +#define __TRACYAPI_H__ + +#ifdef _WIN32 +# if defined TRACY_IMPORTS +# define TRACY_API __declspec(dllimport) +# else +# define TRACY_API __declspec(dllexport) +# endif +#else +# define TRACY_API __attribute__((visibility("default"))) +#endif + +#endif // __TRACYAPI_H__ diff --git a/common/TracySystem.cpp b/common/TracySystem.cpp index 9ea468f3..27297ea8 100644 --- a/common/TracySystem.cpp +++ b/common/TracySystem.cpp @@ -44,8 +44,8 @@ struct ThreadNameData const char* name; ThreadNameData* next; }; -std::atomic& GetThreadNameData(); -void InitRPMallocThread(); +TRACY_API std::atomic& GetThreadNameData(); +TRACY_API void InitRPMallocThread(); #endif void SetThreadName( std::thread& thread, const char* name ) diff --git a/common/TracySystem.hpp b/common/TracySystem.hpp index 32c9626f..469b56da 100644 --- a/common/TracySystem.hpp +++ b/common/TracySystem.hpp @@ -18,6 +18,8 @@ extern "C" __declspec(dllimport) unsigned long __stdcall GetCurrentThreadId(void #include #include +#include "TracyApi.h" + namespace tracy {