Custom lock name transfer.

This commit is contained in:
Bartosz Taudul 2020-03-08 13:47:38 +01:00
parent 0fe606dd8b
commit e7240cb77d
9 changed files with 88 additions and 2 deletions

View File

@ -33,6 +33,7 @@
#define LockableBase( type ) type
#define SharedLockableBase( type ) type
#define LockMark(x) (void)x;
#define LockableName(x,y,z);
#define TracyPlot(x,y)
#define TracyPlotConfig(x,y)
@ -107,6 +108,7 @@
#define LockableBase( type ) tracy::Lockable<type>
#define SharedLockableBase( type ) tracy::SharedLockable<type>
#define LockMark( varname ) static const tracy::SourceLocationData __tracy_lock_location_##varname { nullptr, __FUNCTION__, __FILE__, (uint32_t)__LINE__, 0 }; varname.Mark( &__tracy_lock_location_##varname );
#define LockableName( varname, txt, size ) varname.CustomName( txt, size );
#define TracyPlot( name, val ) tracy::Profiler::PlotData( name, val );
#define TracyPlotConfig( name, type ) tracy::Profiler::ConfigurePlot( name, type );

View File

@ -153,6 +153,20 @@ public:
Profiler::QueueSerialFinish();
}
tracy_force_inline void CustomName( const char* name, size_t size )
{
auto ptr = (char*)tracy_malloc( size+1 );
memcpy( ptr, name, size );
ptr[size] = '\0';
TracyLfqPrepare( QueueType::LockName );
MemWrite( &item->lockName.id, m_id );
MemWrite( &item->lockName.name, (uint64_t)ptr );
#ifdef TRACY_ON_DEMAND
GetProfiler().DeferItem( *item );
#endif
TracyLfqCommit;
}
private:
uint32_t m_id;
@ -199,6 +213,11 @@ public:
m_ctx.Mark( srcloc );
}
tracy_force_inline void CustomName( const char* name, size_t size )
{
m_ctx.CustomName( name, size );
}
private:
T m_lockable;
LockableCtx m_ctx;
@ -434,6 +453,20 @@ public:
Profiler::QueueSerialFinish();
}
tracy_force_inline void CustomName( const char* name, size_t size )
{
auto ptr = (char*)tracy_malloc( size+1 );
memcpy( ptr, name, size );
ptr[size] = '\0';
TracyLfqPrepare( QueueType::LockName );
MemWrite( &item->lockName.id, m_id );
MemWrite( &item->lockName.name, (uint64_t)ptr );
#ifdef TRACY_ON_DEMAND
GetProfiler().DeferItem( *item );
#endif
TracyLfqCommit;
}
private:
uint32_t m_id;
@ -500,6 +533,11 @@ public:
m_ctx.Mark( srcloc );
}
tracy_force_inline void CustomName( const char* name, size_t size )
{
m_ctx.CustomName( txt, size );
}
private:
T m_lockable;
SharedLockableCtx m_ctx;

View File

@ -1624,6 +1624,12 @@ static void FreeAssociatedMemory( const QueueItem& item )
ptr = MemRead<uint64_t>( &item.frameImage.image );
tracy_free( (void*)ptr );
break;
#ifndef TRACY_ON_DEMAND
case QueueType::LockName:
ptr = MemRead<uint64_t>( &item.lockName.name );
tracy_free( (void*)ptr );
break;
#endif
#ifdef TRACY_ON_DEMAND
case QueueType::MessageAppInfo:
// Don't free memory associated with deferred messages.
@ -1786,6 +1792,13 @@ Profiler::DequeueStatus Profiler::Dequeue( moodycamel::ConsumerToken& token )
MemWrite( &item->zoneEnd.time, dt );
break;
}
case QueueType::LockName:
ptr = MemRead<uint64_t>( &item->lockName.name );
SendString( ptr, (const char*)ptr, QueueType::CustomStringData );
#ifndef TRACY_ON_DEMAND
tracy_free( (void*)ptr );
#endif
break;
case QueueType::GpuZoneBegin:
case QueueType::GpuZoneBeginCallstack:
{

View File

@ -9,7 +9,7 @@ namespace tracy
constexpr unsigned Lz4CompressBound( unsigned isize ) { return isize + ( isize / 255 ) + 16; }
enum : uint32_t { ProtocolVersion = 27 };
enum : uint32_t { ProtocolVersion = 28 };
enum : uint32_t { BroadcastVersion = 0 };
using lz4sz_t = uint32_t;

View File

@ -32,6 +32,7 @@ enum class QueueType : uint8_t
LockSharedWait,
LockSharedObtain,
LockSharedRelease,
LockName,
MemAlloc,
MemFree,
MemAllocCallstack,
@ -194,6 +195,12 @@ struct QueueLockMark
uint64_t srcloc; // ptr
};
struct QueueLockName
{
uint32_t id;
uint64_t name; // ptr
};
enum class PlotDataType : uint8_t
{
Float,
@ -412,6 +419,7 @@ struct QueueItem
QueueLockObtain lockObtain;
QueueLockRelease lockRelease;
QueueLockMark lockMark;
QueueLockName lockName;
QueuePlotData plotData;
QueueMessage message;
QueueMessageColor messageColor;
@ -468,6 +476,7 @@ static constexpr size_t QueueDataSize[] = {
sizeof( QueueHeader ) + sizeof( QueueLockWait ), // shared
sizeof( QueueHeader ) + sizeof( QueueLockObtain ), // shared
sizeof( QueueHeader ) + sizeof( QueueLockRelease ), // shared
sizeof( QueueHeader ) + sizeof( QueueLockName ),
sizeof( QueueHeader ) + sizeof( QueueMemAlloc ),
sizeof( QueueHeader ) + sizeof( QueueMemFree ),
sizeof( QueueHeader ) + sizeof( QueueMemAlloc ), // callstack

View File

@ -533,6 +533,7 @@ struct LockMap
int64_t end = std::numeric_limits<int64_t>::min();
};
StringIdx customName;
int16_t srcloc;
Vector<LockEventPtr> timeline;
unordered_flat_map<uint64_t, uint8_t> threadMap;

View File

@ -7,7 +7,7 @@ namespace Version
{
enum { Major = 0 };
enum { Minor = 6 };
enum { Patch = 5 };
enum { Patch = 6 };
}
}

View File

@ -718,6 +718,10 @@ Worker::Worker( FileRead& f, EventType::Type eventMask, bool bgTasks )
uint32_t id;
uint64_t tsz;
f.Read( id );
if( fileVer >= FileVersion( 0, 6, 6 ) )
{
f.Read( lockmap.customName );
}
if( fileVer >= FileVersion( 0, 5, 2 ) )
{
f.Read( lockmap.srcloc );
@ -832,6 +836,10 @@ Worker::Worker( FileRead& f, EventType::Type eventMask, bool bgTasks )
{
LockType type;
uint64_t tsz;
if( fileVer >= FileVersion( 0, 6, 6 ) )
{
f.Skip( sizeof( LockMap::customName ) );
}
if( fileVer >= FileVersion( 0, 5, 2 ) )
{
f.Skip( sizeof( uint32_t ) + sizeof( LockMap::srcloc ) );
@ -3476,6 +3484,9 @@ bool Worker::Process( const QueueItem& ev )
case QueueType::LockMark:
ProcessLockMark( ev.lockMark );
break;
case QueueType::LockName:
ProcessLockName( ev.lockName );
break;
case QueueType::PlotData:
ProcessPlotData( ev.plotData );
break;
@ -4223,6 +4234,16 @@ void Worker::ProcessLockMark( const QueueLockMark& ev )
}
}
void Worker::ProcessLockName( const QueueLockName& ev )
{
auto lit = m_data.lockMap.find( ev.id );
assert( lit != m_data.lockMap.end() );
auto it = m_pendingCustomStrings.find( ev.name );
assert( it != m_pendingCustomStrings.end() );
lit->second->customName = StringIdx( it->second.idx );
m_pendingCustomStrings.erase( it );
}
void Worker::ProcessPlotData( const QueuePlotData& ev )
{
PlotData* plot = m_data.plots.Retrieve( ev.name, [this] ( uint64_t name ) {
@ -6011,6 +6032,7 @@ void Worker::Write( FileWrite& f )
for( auto& v : m_data.lockMap )
{
f.Write( &v.first, sizeof( v.first ) );
f.Write( &v.second->customName, sizeof( v.second->customName ) );
f.Write( &v.second->srcloc, sizeof( v.second->srcloc ) );
f.Write( &v.second->type, sizeof( v.second->type ) );
f.Write( &v.second->valid, sizeof( v.second->valid ) );

View File

@ -523,6 +523,7 @@ private:
tracy_force_inline void ProcessLockSharedObtain( const QueueLockObtain& ev );
tracy_force_inline void ProcessLockSharedRelease( const QueueLockRelease& ev );
tracy_force_inline void ProcessLockMark( const QueueLockMark& ev );
tracy_force_inline void ProcessLockName( const QueueLockName& ev );
tracy_force_inline void ProcessPlotData( const QueuePlotData& ev );
tracy_force_inline void ProcessPlotConfig( const QueuePlotConfig& ev );
tracy_force_inline void ProcessMessage( const QueueMessage& ev );