Decouple rpmalloc usage from TRACY_ENABLE flag.

This commit is contained in:
Bartosz Taudul 2022-08-08 19:29:18 +02:00
parent 3840f39fc9
commit bb22542a90
No known key found for this signature in database
GPG Key ID: B7FE2008B7575DF3
3 changed files with 21 additions and 8 deletions

View File

@ -1,8 +1,9 @@
#ifdef TRACY_ENABLE #include "../common/TracyAlloc.hpp"
#ifdef TRACY_USE_RPMALLOC
#include <atomic> #include <atomic>
#include "../common/TracyAlloc.hpp"
#include "../common/TracyForceInline.hpp" #include "../common/TracyForceInline.hpp"
#include "../common/TracyYield.hpp" #include "../common/TracyYield.hpp"

View File

@ -57,6 +57,7 @@
#include <thread> #include <thread>
#include "../common/TracyAlign.hpp" #include "../common/TracyAlign.hpp"
#include "../common/TracyAlloc.hpp"
#include "../common/TracySocket.hpp" #include "../common/TracySocket.hpp"
#include "../common/TracySystem.hpp" #include "../common/TracySystem.hpp"
#include "../common/TracyYield.hpp" #include "../common/TracyYield.hpp"
@ -1547,7 +1548,9 @@ void Profiler::Worker()
while( m_timeBegin.load( std::memory_order_relaxed ) == 0 ) std::this_thread::sleep_for( std::chrono::milliseconds( 10 ) ); while( m_timeBegin.load( std::memory_order_relaxed ) == 0 ) std::this_thread::sleep_for( std::chrono::milliseconds( 10 ) );
#ifdef TRACY_USE_RPMALLOC
rpmalloc_thread_initialize(); rpmalloc_thread_initialize();
#endif
m_exectime = 0; m_exectime = 0;
const auto execname = GetProcessExecutablePath(); const auto execname = GetProcessExecutablePath();
@ -2019,7 +2022,10 @@ void Profiler::CompressWorker()
ThreadExitHandler threadExitHandler; ThreadExitHandler threadExitHandler;
SetThreadName( "Tracy DXT1" ); SetThreadName( "Tracy DXT1" );
while( m_timeBegin.load( std::memory_order_relaxed ) == 0 ) std::this_thread::sleep_for( std::chrono::milliseconds( 10 ) ); while( m_timeBegin.load( std::memory_order_relaxed ) == 0 ) std::this_thread::sleep_for( std::chrono::milliseconds( 10 ) );
#ifdef TRACY_USE_RPMALLOC
rpmalloc_thread_initialize(); rpmalloc_thread_initialize();
#endif
for(;;) for(;;)
{ {
@ -3291,7 +3297,10 @@ void Profiler::SymbolWorker()
ThreadExitHandler threadExitHandler; ThreadExitHandler threadExitHandler;
SetThreadName( "Tracy Symbol Worker" ); SetThreadName( "Tracy Symbol Worker" );
while( m_timeBegin.load( std::memory_order_relaxed ) == 0 ) std::this_thread::sleep_for( std::chrono::milliseconds( 10 ) ); while( m_timeBegin.load( std::memory_order_relaxed ) == 0 ) std::this_thread::sleep_for( std::chrono::milliseconds( 10 ) );
#ifdef TRACY_USE_RPMALLOC
rpmalloc_thread_initialize(); rpmalloc_thread_initialize();
#endif
for(;;) for(;;)
{ {

View File

@ -7,18 +7,21 @@
# include "TracyApi.h" # include "TracyApi.h"
# include "TracyForceInline.hpp" # include "TracyForceInline.hpp"
# include "../client/tracy_rpmalloc.hpp" # include "../client/tracy_rpmalloc.hpp"
# define TRACY_USE_RPMALLOC
#endif #endif
namespace tracy namespace tracy
{ {
#ifdef TRACY_ENABLE #ifdef TRACY_USE_RPMALLOC
TRACY_API void InitRpmalloc(); TRACY_API void InitRpmalloc();
#else
static inline void InitRpmalloc() {}
#endif #endif
static inline void* tracy_malloc( size_t size ) static inline void* tracy_malloc( size_t size )
{ {
#ifdef TRACY_ENABLE #ifdef TRACY_USE_RPMALLOC
InitRpmalloc(); InitRpmalloc();
return rpmalloc( size ); return rpmalloc( size );
#else #else
@ -28,7 +31,7 @@ static inline void* tracy_malloc( size_t size )
static inline void* tracy_malloc_fast( size_t size ) static inline void* tracy_malloc_fast( size_t size )
{ {
#ifdef TRACY_ENABLE #ifdef TRACY_USE_RPMALLOC
return rpmalloc( size ); return rpmalloc( size );
#else #else
return malloc( size ); return malloc( size );
@ -37,7 +40,7 @@ static inline void* tracy_malloc_fast( size_t size )
static inline void tracy_free( void* ptr ) static inline void tracy_free( void* ptr )
{ {
#ifdef TRACY_ENABLE #ifdef TRACY_USE_RPMALLOC
InitRpmalloc(); InitRpmalloc();
rpfree( ptr ); rpfree( ptr );
#else #else
@ -47,7 +50,7 @@ static inline void tracy_free( void* ptr )
static inline void tracy_free_fast( void* ptr ) static inline void tracy_free_fast( void* ptr )
{ {
#ifdef TRACY_ENABLE #ifdef TRACY_USE_RPMALLOC
rpfree( ptr ); rpfree( ptr );
#else #else
free( ptr ); free( ptr );
@ -56,7 +59,7 @@ static inline void tracy_free_fast( void* ptr )
static inline void* tracy_realloc( void* ptr, size_t size ) static inline void* tracy_realloc( void* ptr, size_t size )
{ {
#ifdef TRACY_ENABLE #ifdef TRACY_USE_RPMALLOC
InitRpmalloc(); InitRpmalloc();
return rprealloc( ptr, size ); return rprealloc( ptr, size );
#else #else