mirror of
https://github.com/wolfpld/tracy.git
synced 2026-09-08 11:28:24 +00:00
Add TRACY_PLATFORM_HEADER hook for unsupported platforms.
Extension point so private/unsupported platforms can plug in their own implementations of the kernel/libc primitives Tracy depends on, without patching the `#if`/`#elif` chains. Projects supply a platform header via `-DTRACY_PLATFORM_HEADER="\"my_platform.h\""` at build time. Tracy includes it in any TU that needs the hooks. The header toggles per-category `TRACY_HAS_CUSTOM_*` macros and declares matching `tracy::Platform*` functions. Available hooks: - `TRACY_HAS_CUSTOM_THREAD_ID` → `PlatformGetThreadId` - `TRACY_HAS_CUSTOM_USER_INFO` → `PlatformGetHostname`, `PlatformGetUserLogin`, `PlatformGetUserFullName` - `TRACY_HAS_CUSTOM_SAFE_COPY` → `PlatformSafeMemcpy` - `TRACY_HAS_CUSTOM_ALLOCATOR` → `PlatformMalloc`, `PlatformFree`, `PlatformRealloc`, `PlatformAllocatorInit`, `PlatformAllocatorThreadInit`, `PlatformAllocatorFinalize`, `PlatformAllocatorThreadFinalize` Each hook is wired as the first arm of its respective `#if`/`#elif` chain, so existing supported platforms are unaffected. Template files in `examples/CustomPlatform/` and a new subsection in `manual/tracy.tex` document the mechanism.
This commit is contained in:
@@ -51,6 +51,10 @@
|
||||
|
||||
#include "TracySystem.hpp"
|
||||
|
||||
#ifdef TRACY_PLATFORM_HEADER
|
||||
# include TRACY_PLATFORM_HEADER
|
||||
#endif
|
||||
|
||||
#if defined _WIN32
|
||||
extern "C" typedef HRESULT (WINAPI *t_SetThreadDescription)( HANDLE, PCWSTR );
|
||||
extern "C" typedef HRESULT (WINAPI *t_GetThreadDescription)( HANDLE, PWSTR* );
|
||||
@@ -69,7 +73,9 @@ namespace detail
|
||||
|
||||
TRACY_API uint32_t GetThreadHandleImpl()
|
||||
{
|
||||
#if defined _WIN32
|
||||
#if defined TRACY_HAS_CUSTOM_THREAD_ID
|
||||
return PlatformGetThreadId();
|
||||
#elif defined _WIN32
|
||||
static_assert( sizeof( decltype( GetCurrentThreadId() ) ) <= sizeof( uint32_t ), "Thread handle too big to fit in protocol" );
|
||||
return uint32_t( GetCurrentThreadId() );
|
||||
#elif defined __APPLE__
|
||||
@@ -341,7 +347,9 @@ TRACY_API const char* GetEnvVar( const char* name )
|
||||
|
||||
TRACY_API const char* GetUserLogin()
|
||||
{
|
||||
#if defined _WIN32
|
||||
#if defined TRACY_HAS_CUSTOM_USER_INFO
|
||||
return PlatformGetUserLogin();
|
||||
#elif defined _WIN32
|
||||
# if defined TRACY_WIN32_NO_DESKTOP
|
||||
return "(?)";
|
||||
# else
|
||||
@@ -363,7 +371,9 @@ TRACY_API const char* GetUserLogin()
|
||||
|
||||
TRACY_API const char* GetUserFullName()
|
||||
{
|
||||
#if defined _WIN32
|
||||
#if defined TRACY_HAS_CUSTOM_USER_INFO
|
||||
return PlatformGetUserFullName();
|
||||
#elif defined _WIN32
|
||||
static char buf[1024];
|
||||
ULONG size = sizeof( buf );
|
||||
if( GetUserNameExA( NameDisplay, buf, &size ) ) return buf;
|
||||
|
||||
Reference in New Issue
Block a user