mirror of
https://github.com/wolfpld/tracy.git
synced 2026-10-23 09:10:51 +00:00
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.
92 lines
1.8 KiB
C++
92 lines
1.8 KiB
C++
#ifndef __TRACYALLOC_HPP__
|
|
#define __TRACYALLOC_HPP__
|
|
|
|
#include <stdlib.h>
|
|
|
|
#ifdef TRACY_PLATFORM_HEADER
|
|
# include TRACY_PLATFORM_HEADER
|
|
#endif
|
|
|
|
#if defined TRACY_ENABLE && !defined __EMSCRIPTEN__
|
|
# include "TracyApi.h"
|
|
# include "TracyForceInline.hpp"
|
|
# if !defined TRACY_HAS_CUSTOM_ALLOCATOR
|
|
# include "../client/tracy_rpmalloc.hpp"
|
|
# define TRACY_USE_RPMALLOC
|
|
# endif
|
|
#endif
|
|
|
|
namespace tracy
|
|
{
|
|
|
|
#if defined TRACY_USE_RPMALLOC || defined TRACY_HAS_CUSTOM_ALLOCATOR
|
|
TRACY_API void InitAllocator();
|
|
#else
|
|
static inline void InitAllocator() {}
|
|
#endif
|
|
|
|
static inline void* tracy_malloc( size_t size )
|
|
{
|
|
#if defined TRACY_HAS_CUSTOM_ALLOCATOR
|
|
InitAllocator();
|
|
return PlatformMalloc( size );
|
|
#elif defined TRACY_USE_RPMALLOC
|
|
InitAllocator();
|
|
return rpmalloc( size );
|
|
#else
|
|
return malloc( size );
|
|
#endif
|
|
}
|
|
|
|
static inline void* tracy_malloc_fast( size_t size )
|
|
{
|
|
#if defined TRACY_HAS_CUSTOM_ALLOCATOR
|
|
return PlatformMalloc( size );
|
|
#elif defined TRACY_USE_RPMALLOC
|
|
return rpmalloc( size );
|
|
#else
|
|
return malloc( size );
|
|
#endif
|
|
}
|
|
|
|
static inline void tracy_free( void* ptr )
|
|
{
|
|
#if defined TRACY_HAS_CUSTOM_ALLOCATOR
|
|
InitAllocator();
|
|
PlatformFree( ptr );
|
|
#elif defined TRACY_USE_RPMALLOC
|
|
InitAllocator();
|
|
rpfree( ptr );
|
|
#else
|
|
free( ptr );
|
|
#endif
|
|
}
|
|
|
|
static inline void tracy_free_fast( void* ptr )
|
|
{
|
|
#if defined TRACY_HAS_CUSTOM_ALLOCATOR
|
|
PlatformFree( ptr );
|
|
#elif defined TRACY_USE_RPMALLOC
|
|
rpfree( ptr );
|
|
#else
|
|
free( ptr );
|
|
#endif
|
|
}
|
|
|
|
static inline void* tracy_realloc( void* ptr, size_t size )
|
|
{
|
|
#if defined TRACY_HAS_CUSTOM_ALLOCATOR
|
|
InitAllocator();
|
|
return PlatformRealloc( ptr, size );
|
|
#elif defined TRACY_USE_RPMALLOC
|
|
InitAllocator();
|
|
return rprealloc( ptr, size );
|
|
#else
|
|
return realloc( ptr, size );
|
|
#endif
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|