1
0
mirror of https://github.com/wolfpld/tracy.git synced 2025-03-20 07:40:02 +08:00

Move callstack collection in mem events out of critical section.

This commit is contained in:
Bartosz Taudul 2018-06-22 23:00:03 +02:00
parent 4d60d3a20e
commit f0ce7de193

View File

@ -218,24 +218,36 @@ public:
static tracy_force_inline void MemAllocCallstack( const void* ptr, size_t size, int depth ) static tracy_force_inline void MemAllocCallstack( const void* ptr, size_t size, int depth )
{ {
#ifdef TRACY_HAS_CALLSTACK
const auto thread = GetThreadHandle(); const auto thread = GetThreadHandle();
rpmalloc_thread_initialize(); rpmalloc_thread_initialize();
auto callstack = Callstack( depth );
s_profiler.m_serialLock.lock(); s_profiler.m_serialLock.lock();
SendMemAlloc( QueueType::MemAllocCallstack, thread, ptr, size ); SendMemAlloc( QueueType::MemAllocCallstack, thread, ptr, size );
SendCallstackMemory( depth ); SendCallstackMemory( callstack );
s_profiler.m_serialLock.unlock(); s_profiler.m_serialLock.unlock();
#else
MemAlloc( ptr, size );
#endif
} }
static tracy_force_inline void MemFreeCallstack( const void* ptr, int depth ) static tracy_force_inline void MemFreeCallstack( const void* ptr, int depth )
{ {
#ifdef TRACY_HAS_CALLSTACK
const auto thread = GetThreadHandle(); const auto thread = GetThreadHandle();
rpmalloc_thread_initialize(); rpmalloc_thread_initialize();
auto callstack = Callstack( depth );
s_profiler.m_serialLock.lock(); s_profiler.m_serialLock.lock();
SendMemFree( QueueType::MemFreeCallstack, thread, ptr ); SendMemFree( QueueType::MemFreeCallstack, thread, ptr );
SendCallstackMemory( depth ); SendCallstackMemory( callstack );
s_profiler.m_serialLock.unlock(); s_profiler.m_serialLock.unlock();
#else
MemFree( ptr );
#endif
} }
static tracy_force_inline void SendCallstack( int depth, uint64_t thread ) static tracy_force_inline void SendCallstack( int depth, uint64_t thread )
@ -279,10 +291,9 @@ private:
void CalibrateTimer(); void CalibrateTimer();
void CalibrateDelay(); void CalibrateDelay();
static tracy_force_inline void SendCallstackMemory( int depth ) static tracy_force_inline void SendCallstackMemory( void* ptr )
{ {
#ifdef TRACY_HAS_CALLSTACK #ifdef TRACY_HAS_CALLSTACK
auto ptr = Callstack( depth );
auto item = s_profiler.m_serialQueue.push_next(); auto item = s_profiler.m_serialQueue.push_next();
MemWrite( &item->hdr.type, QueueType::CallstackMemory ); MemWrite( &item->hdr.type, QueueType::CallstackMemory );
MemWrite( &item->callstackMemory.ptr, (uint64_t)ptr ); MemWrite( &item->callstackMemory.ptr, (uint64_t)ptr );