mirror of
https://github.com/wolfpld/tracy.git
synced 2025-03-20 07:40:02 +08:00
Add memory discard message.
This can be used to erase all allocations made within the named memory pool. The usual use case would be for arena allocators, which allocate by advancing a pointer and never have to free the memory. There is no tracking of individual allocations and everything is freed frequently, by reseting the pointer, for example once per frame. Since this is used in special-purpose allocators, there is no support for discarding the memory of the default memory pool.
This commit is contained in:
@@ -2862,6 +2862,15 @@ Profiler::DequeueStatus Profiler::DequeueSerial()
|
||||
MemWrite( &item->memFree.time, dt );
|
||||
break;
|
||||
}
|
||||
case QueueType::MemDiscard:
|
||||
case QueueType::MemDiscardCallstack:
|
||||
{
|
||||
int64_t t = MemRead<int64_t>( &item->memDiscard.time );
|
||||
int64_t dt = t - refSerial;
|
||||
refSerial = t;
|
||||
MemWrite( &item->memDiscard.time, dt );
|
||||
break;
|
||||
}
|
||||
case QueueType::GpuZoneBeginSerial:
|
||||
case QueueType::GpuZoneBeginCallstackSerial:
|
||||
{
|
||||
|
||||
@@ -633,6 +633,40 @@ public:
|
||||
#endif
|
||||
}
|
||||
|
||||
static tracy_force_inline void MemDiscard( const char* name, bool secure )
|
||||
{
|
||||
if( secure && !ProfilerAvailable() ) return;
|
||||
#ifdef TRACY_ON_DEMAND
|
||||
if( !GetProfiler().IsConnected() ) return;
|
||||
#endif
|
||||
const auto thread = GetThreadHandle();
|
||||
|
||||
GetProfiler().m_serialLock.lock();
|
||||
SendMemDiscard( QueueType::MemDiscard, thread, name );
|
||||
GetProfiler().m_serialLock.unlock();
|
||||
}
|
||||
|
||||
static tracy_force_inline void MemDiscardCallstack( const char* name, bool secure, int depth )
|
||||
{
|
||||
if( secure && !ProfilerAvailable() ) return;
|
||||
#ifdef TRACY_HAS_CALLSTACK
|
||||
# ifdef TRACY_ON_DEMAND
|
||||
if( !GetProfiler().IsConnected() ) return;
|
||||
# endif
|
||||
const auto thread = GetThreadHandle();
|
||||
|
||||
auto callstack = Callstack( depth );
|
||||
|
||||
GetProfiler().m_serialLock.lock();
|
||||
SendCallstackSerial( callstack );
|
||||
SendMemDiscard( QueueType::MemDiscard, thread, name );
|
||||
GetProfiler().m_serialLock.unlock();
|
||||
#else
|
||||
static_cast<void>(depth); // unused
|
||||
MemDiscard( name, secure );
|
||||
#endif
|
||||
}
|
||||
|
||||
static tracy_force_inline void SendCallstack( int depth )
|
||||
{
|
||||
#ifdef TRACY_HAS_CALLSTACK
|
||||
@@ -922,6 +956,18 @@ private:
|
||||
GetProfiler().m_serialQueue.commit_next();
|
||||
}
|
||||
|
||||
static tracy_force_inline void SendMemDiscard( QueueType type, const uint32_t thread, const char* name )
|
||||
{
|
||||
assert( type == QueueType::MemDiscard || type == QueueType::MemDiscardCallstack );
|
||||
|
||||
auto item = GetProfiler().m_serialQueue.prepare_next();
|
||||
MemWrite( &item->hdr.type, type );
|
||||
MemWrite( &item->memDiscard.time, GetTime() );
|
||||
MemWrite( &item->memDiscard.thread, thread );
|
||||
MemWrite( &item->memDiscard.name, (uint64_t)name );
|
||||
GetProfiler().m_serialQueue.commit_next();
|
||||
}
|
||||
|
||||
static tracy_force_inline void SendMemName( const char* name )
|
||||
{
|
||||
assert( name );
|
||||
|
||||
Reference in New Issue
Block a user