mirror of
https://github.com/wolfpld/tracy.git
synced 2024-11-29 16:54:35 +00:00
Zone text (custom string) transfer.
This commit is contained in:
parent
3c0ce01954
commit
d1bbb731fc
@ -16,6 +16,8 @@
|
|||||||
#define ZoneScoped static const tracy::SourceLocation __tracy_source_location { __FUNCTION__, __FILE__, __LINE__, 0 }; tracy::ScopedZone ___tracy_scoped_zone( &__tracy_source_location );
|
#define ZoneScoped static const tracy::SourceLocation __tracy_source_location { __FUNCTION__, __FILE__, __LINE__, 0 }; tracy::ScopedZone ___tracy_scoped_zone( &__tracy_source_location );
|
||||||
#define ZoneScopedC( color ) static const tracy::SourceLocation __tracy_source_location { __FUNCTION__, __FILE__, __LINE__, color }; tracy::ScopedZone ___tracy_scoped_zone( &__tracy_source_location );
|
#define ZoneScopedC( color ) static const tracy::SourceLocation __tracy_source_location { __FUNCTION__, __FILE__, __LINE__, color }; tracy::ScopedZone ___tracy_scoped_zone( &__tracy_source_location );
|
||||||
|
|
||||||
|
#define ZoneText( txt, size ) ___tracy_scoped_zone.Text( txt, size );
|
||||||
|
|
||||||
#define FrameMark tracy::Profiler::FrameMark();
|
#define FrameMark tracy::Profiler::FrameMark();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -103,6 +103,15 @@ void Profiler::ZoneEnd( uint64_t id, QueueZoneEnd&& data )
|
|||||||
ZoneEndImpl( s_token, id, std::move( data ) );
|
ZoneEndImpl( s_token, id, std::move( data ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Profiler::ZoneText( uint64_t id, QueueZoneText&& data )
|
||||||
|
{
|
||||||
|
QueueItem item;
|
||||||
|
item.hdr.type = QueueType::ZoneText;
|
||||||
|
item.hdr.id = id;
|
||||||
|
item.zoneText = std::move( data );
|
||||||
|
s_queue.enqueue( s_token, std::move( item ) );
|
||||||
|
}
|
||||||
|
|
||||||
void Profiler::FrameMark()
|
void Profiler::FrameMark()
|
||||||
{
|
{
|
||||||
QueueItem item;
|
QueueItem item;
|
||||||
@ -199,7 +208,7 @@ bool Profiler::SendData( const char* data, size_t len )
|
|||||||
|
|
||||||
bool Profiler::SendString( uint64_t str, const char* ptr, QueueType type )
|
bool Profiler::SendString( uint64_t str, const char* ptr, QueueType type )
|
||||||
{
|
{
|
||||||
assert( type == QueueType::StringData || type == QueueType::ThreadName );
|
assert( type == QueueType::StringData || type == QueueType::ThreadName || type == QueueType::CustomStringData );
|
||||||
|
|
||||||
QueueHeader hdr;
|
QueueHeader hdr;
|
||||||
hdr.type = type;
|
hdr.type = type;
|
||||||
@ -261,6 +270,10 @@ bool Profiler::HandleServerQuery()
|
|||||||
SendString( ptr, GetThreadName( ptr ), QueueType::ThreadName );
|
SendString( ptr, GetThreadName( ptr ), QueueType::ThreadName );
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case ServerQueryCustomString:
|
||||||
|
SendString( ptr, (const char*)ptr, QueueType::CustomStringData );
|
||||||
|
delete[] (const char*)ptr;
|
||||||
|
break;
|
||||||
case ServerQuerySourceLocation:
|
case ServerQuerySourceLocation:
|
||||||
SendSourceLocation( ptr );
|
SendSourceLocation( ptr );
|
||||||
break;
|
break;
|
||||||
|
@ -44,6 +44,7 @@ public:
|
|||||||
|
|
||||||
static uint64_t ZoneBegin( QueueZoneBegin&& data );
|
static uint64_t ZoneBegin( QueueZoneBegin&& data );
|
||||||
static void ZoneEnd( uint64_t id, QueueZoneEnd&& data );
|
static void ZoneEnd( uint64_t id, QueueZoneEnd&& data );
|
||||||
|
static void ZoneText( uint64_t id, QueueZoneText&& data );
|
||||||
static void FrameMark();
|
static void FrameMark();
|
||||||
|
|
||||||
static bool ShouldExit();
|
static bool ShouldExit();
|
||||||
|
@ -22,6 +22,14 @@ public:
|
|||||||
Profiler::ZoneEnd( m_id, QueueZoneEnd { Profiler::GetTime() } );
|
Profiler::ZoneEnd( m_id, QueueZoneEnd { Profiler::GetTime() } );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Text( const char* txt, size_t size )
|
||||||
|
{
|
||||||
|
auto ptr = new char[size+1];
|
||||||
|
memcpy( ptr, txt, size );
|
||||||
|
ptr[size] = '\0';
|
||||||
|
Profiler::ZoneText( m_id, QueueZoneText { (uint64_t)ptr } );
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint64_t m_id;
|
uint64_t m_id;
|
||||||
};
|
};
|
||||||
|
@ -20,7 +20,8 @@ enum ServerQuery : uint8_t
|
|||||||
{
|
{
|
||||||
ServerQueryString,
|
ServerQueryString,
|
||||||
ServerQueryThreadString,
|
ServerQueryThreadString,
|
||||||
ServerQuerySourceLocation
|
ServerQueryCustomString,
|
||||||
|
ServerQuerySourceLocation,
|
||||||
};
|
};
|
||||||
|
|
||||||
#pragma pack( 1 )
|
#pragma pack( 1 )
|
||||||
|
@ -12,8 +12,10 @@ enum class QueueType : uint8_t
|
|||||||
ZoneEnd,
|
ZoneEnd,
|
||||||
StringData,
|
StringData,
|
||||||
ThreadName,
|
ThreadName,
|
||||||
|
CustomStringData,
|
||||||
FrameMark,
|
FrameMark,
|
||||||
SourceLocation,
|
SourceLocation,
|
||||||
|
ZoneText,
|
||||||
NUM_TYPES
|
NUM_TYPES
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -39,6 +41,11 @@ struct QueueSourceLocation
|
|||||||
uint32_t color;
|
uint32_t color;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct QueueZoneText
|
||||||
|
{
|
||||||
|
uint64_t text; // ptr
|
||||||
|
};
|
||||||
|
|
||||||
struct QueueHeader
|
struct QueueHeader
|
||||||
{
|
{
|
||||||
union
|
union
|
||||||
@ -57,6 +64,7 @@ struct QueueItem
|
|||||||
QueueZoneBegin zoneBegin;
|
QueueZoneBegin zoneBegin;
|
||||||
QueueZoneEnd zoneEnd;
|
QueueZoneEnd zoneEnd;
|
||||||
QueueSourceLocation srcloc;
|
QueueSourceLocation srcloc;
|
||||||
|
QueueZoneText zoneText;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -70,7 +78,9 @@ static const size_t QueueDataSize[] = {
|
|||||||
sizeof( QueueHeader ),
|
sizeof( QueueHeader ),
|
||||||
sizeof( QueueHeader ),
|
sizeof( QueueHeader ),
|
||||||
sizeof( QueueHeader ),
|
sizeof( QueueHeader ),
|
||||||
|
sizeof( QueueHeader ),
|
||||||
sizeof( QueueHeader ) + sizeof( QueueSourceLocation ),
|
sizeof( QueueHeader ) + sizeof( QueueSourceLocation ),
|
||||||
|
sizeof( QueueHeader ) + sizeof( QueueZoneText ),
|
||||||
};
|
};
|
||||||
|
|
||||||
static_assert( sizeof( QueueDataSize ) / sizeof( size_t ) == (uint8_t)QueueType::NUM_TYPES, "QueueDataSize mismatch" );
|
static_assert( sizeof( QueueDataSize ) / sizeof( size_t ) == (uint8_t)QueueType::NUM_TYPES, "QueueDataSize mismatch" );
|
||||||
|
@ -12,6 +12,7 @@ struct Event
|
|||||||
int64_t end;
|
int64_t end;
|
||||||
uint64_t srcloc;
|
uint64_t srcloc;
|
||||||
|
|
||||||
|
const char* text;
|
||||||
Event* parent;
|
Event* parent;
|
||||||
Vector<Event*> child;
|
Vector<Event*> child;
|
||||||
};
|
};
|
||||||
|
@ -157,7 +157,7 @@ close:
|
|||||||
|
|
||||||
void View::DispatchProcess( const QueueItem& ev )
|
void View::DispatchProcess( const QueueItem& ev )
|
||||||
{
|
{
|
||||||
if( ev.hdr.type == QueueType::StringData || ev.hdr.type == QueueType::ThreadName )
|
if( ev.hdr.type == QueueType::CustomStringData || ev.hdr.type == QueueType::StringData || ev.hdr.type == QueueType::ThreadName )
|
||||||
{
|
{
|
||||||
timeval tv;
|
timeval tv;
|
||||||
tv.tv_sec = 0;
|
tv.tv_sec = 0;
|
||||||
@ -167,7 +167,11 @@ void View::DispatchProcess( const QueueItem& ev )
|
|||||||
uint16_t sz;
|
uint16_t sz;
|
||||||
m_sock.Read( &sz, sizeof( sz ), &tv, ShouldExit );
|
m_sock.Read( &sz, sizeof( sz ), &tv, ShouldExit );
|
||||||
m_sock.Read( buf, sz, &tv, ShouldExit );
|
m_sock.Read( buf, sz, &tv, ShouldExit );
|
||||||
if( ev.hdr.type == QueueType::StringData )
|
if( ev.hdr.type == QueueType::CustomStringData )
|
||||||
|
{
|
||||||
|
AddCustomString( ev.hdr.id, std::string( buf, buf+sz ) );
|
||||||
|
}
|
||||||
|
else if( ev.hdr.type == QueueType::StringData )
|
||||||
{
|
{
|
||||||
AddString( ev.hdr.id, std::string( buf, buf+sz ) );
|
AddString( ev.hdr.id, std::string( buf, buf+sz ) );
|
||||||
}
|
}
|
||||||
@ -185,12 +189,16 @@ void View::DispatchProcess( const QueueItem& ev )
|
|||||||
void View::DispatchProcess( const QueueItem& ev, const char*& ptr )
|
void View::DispatchProcess( const QueueItem& ev, const char*& ptr )
|
||||||
{
|
{
|
||||||
ptr += QueueDataSize[ev.hdr.idx];
|
ptr += QueueDataSize[ev.hdr.idx];
|
||||||
if( ev.hdr.type == QueueType::StringData || ev.hdr.type == QueueType::ThreadName )
|
if( ev.hdr.type == QueueType::CustomStringData || ev.hdr.type == QueueType::StringData || ev.hdr.type == QueueType::ThreadName )
|
||||||
{
|
{
|
||||||
uint16_t sz;
|
uint16_t sz;
|
||||||
memcpy( &sz, ptr, sizeof( sz ) );
|
memcpy( &sz, ptr, sizeof( sz ) );
|
||||||
ptr += sizeof( sz );
|
ptr += sizeof( sz );
|
||||||
if( ev.hdr.type == QueueType::StringData )
|
if( ev.hdr.type == QueueType::CustomStringData )
|
||||||
|
{
|
||||||
|
AddCustomString( ev.hdr.id, std::string( ptr, ptr+sz ) );
|
||||||
|
}
|
||||||
|
else if( ev.hdr.type == QueueType::StringData )
|
||||||
{
|
{
|
||||||
AddString( ev.hdr.id, std::string( ptr, ptr+sz ) );
|
AddString( ev.hdr.id, std::string( ptr, ptr+sz ) );
|
||||||
}
|
}
|
||||||
@ -222,6 +230,9 @@ void View::Process( const QueueItem& ev )
|
|||||||
case QueueType::SourceLocation:
|
case QueueType::SourceLocation:
|
||||||
AddSourceLocation( ev.hdr.id, ev.srcloc );
|
AddSourceLocation( ev.hdr.id, ev.srcloc );
|
||||||
break;
|
break;
|
||||||
|
case QueueType::ZoneText:
|
||||||
|
ProcessZoneText( ev.hdr.id, ev.zoneText );
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
assert( false );
|
assert( false );
|
||||||
break;
|
break;
|
||||||
@ -238,6 +249,7 @@ void View::ProcessZoneBegin( uint64_t id, const QueueZoneBegin& ev )
|
|||||||
|
|
||||||
zone->start = ev.time * m_timerMul;
|
zone->start = ev.time * m_timerMul;
|
||||||
zone->srcloc = ev.srcloc;
|
zone->srcloc = ev.srcloc;
|
||||||
|
zone->text = nullptr;
|
||||||
|
|
||||||
std::unique_lock<std::mutex> lock( m_lock );
|
std::unique_lock<std::mutex> lock( m_lock );
|
||||||
|
|
||||||
@ -296,6 +308,13 @@ void View::ProcessFrameMark( uint64_t id )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void View::ProcessZoneText( uint64_t id, const QueueZoneText& ev )
|
||||||
|
{
|
||||||
|
auto it = m_openZones.find( id );
|
||||||
|
assert( it != m_openZones.end() );
|
||||||
|
CheckCustomString( ev.text, it->second );
|
||||||
|
}
|
||||||
|
|
||||||
void View::CheckString( uint64_t ptr )
|
void View::CheckString( uint64_t ptr )
|
||||||
{
|
{
|
||||||
if( m_strings.find( ptr ) != m_strings.end() ) return;
|
if( m_strings.find( ptr ) != m_strings.end() ) return;
|
||||||
@ -320,6 +339,16 @@ void View::CheckThreadString( uint64_t id )
|
|||||||
m_sock.Send( &id, sizeof( id ) );
|
m_sock.Send( &id, sizeof( id ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void View::CheckCustomString( uint64_t ptr, Event* dst )
|
||||||
|
{
|
||||||
|
assert( m_pendingCustomStrings.find( ptr ) == m_pendingCustomStrings.end() );
|
||||||
|
m_pendingCustomStrings.emplace( ptr, dst );
|
||||||
|
|
||||||
|
uint8_t type = ServerQueryCustomString;
|
||||||
|
m_sock.Send( &type, sizeof( type ) );
|
||||||
|
m_sock.Send( &ptr, sizeof( ptr ) );
|
||||||
|
}
|
||||||
|
|
||||||
void View::CheckSourceLocation( uint64_t ptr )
|
void View::CheckSourceLocation( uint64_t ptr )
|
||||||
{
|
{
|
||||||
if( m_sourceLocation.find( ptr ) != m_sourceLocation.end() ) return;
|
if( m_sourceLocation.find( ptr ) != m_sourceLocation.end() ) return;
|
||||||
@ -352,6 +381,23 @@ void View::AddThreadString( uint64_t id, std::string&& str )
|
|||||||
m_threadNames.emplace( id, std::move( str ) );
|
m_threadNames.emplace( id, std::move( str ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void View::AddCustomString( uint64_t ptr, std::string&& str )
|
||||||
|
{
|
||||||
|
auto pit = m_pendingCustomStrings.find( ptr );
|
||||||
|
assert( pit != m_pendingCustomStrings.end() );
|
||||||
|
auto sit = m_customStrings.find( str );
|
||||||
|
if( sit == m_customStrings.end() )
|
||||||
|
{
|
||||||
|
pit->second->text = str.c_str();
|
||||||
|
m_customStrings.emplace( std::move( str ) );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pit->second->text = sit->c_str();
|
||||||
|
}
|
||||||
|
m_pendingCustomStrings.erase( pit );
|
||||||
|
}
|
||||||
|
|
||||||
void View::AddSourceLocation( uint64_t ptr, const QueueSourceLocation& srcloc )
|
void View::AddSourceLocation( uint64_t ptr, const QueueSourceLocation& srcloc )
|
||||||
{
|
{
|
||||||
assert( m_sourceLocation.find( ptr ) == m_sourceLocation.end() );
|
assert( m_sourceLocation.find( ptr ) == m_sourceLocation.end() );
|
||||||
|
@ -49,13 +49,16 @@ private:
|
|||||||
void ProcessZoneBegin( uint64_t id, const QueueZoneBegin& ev );
|
void ProcessZoneBegin( uint64_t id, const QueueZoneBegin& ev );
|
||||||
void ProcessZoneEnd( uint64_t id, const QueueZoneEnd& ev );
|
void ProcessZoneEnd( uint64_t id, const QueueZoneEnd& ev );
|
||||||
void ProcessFrameMark( uint64_t id );
|
void ProcessFrameMark( uint64_t id );
|
||||||
|
void ProcessZoneText( uint64_t id, const QueueZoneText& ev );
|
||||||
|
|
||||||
void CheckString( uint64_t ptr );
|
void CheckString( uint64_t ptr );
|
||||||
void CheckThreadString( uint64_t id );
|
void CheckThreadString( uint64_t id );
|
||||||
|
void CheckCustomString( uint64_t ptr, Event* dst );
|
||||||
void CheckSourceLocation( uint64_t ptr );
|
void CheckSourceLocation( uint64_t ptr );
|
||||||
|
|
||||||
void AddString( uint64_t ptr, std::string&& str );
|
void AddString( uint64_t ptr, std::string&& str );
|
||||||
void AddThreadString( uint64_t id, std::string&& str );
|
void AddThreadString( uint64_t id, std::string&& str );
|
||||||
|
void AddCustomString( uint64_t ptr, std::string&& str );
|
||||||
void AddSourceLocation( uint64_t id, const QueueSourceLocation& srcloc );
|
void AddSourceLocation( uint64_t id, const QueueSourceLocation& srcloc );
|
||||||
|
|
||||||
void NewZone( Event* zone, uint64_t thread );
|
void NewZone( Event* zone, uint64_t thread );
|
||||||
@ -93,6 +96,7 @@ private:
|
|||||||
Vector<ThreadData> m_threads;
|
Vector<ThreadData> m_threads;
|
||||||
std::unordered_map<uint64_t, std::string> m_strings;
|
std::unordered_map<uint64_t, std::string> m_strings;
|
||||||
std::unordered_map<uint64_t, std::string> m_threadNames;
|
std::unordered_map<uint64_t, std::string> m_threadNames;
|
||||||
|
std::unordered_set<std::string> m_customStrings;
|
||||||
std::unordered_map<uint64_t, QueueSourceLocation> m_sourceLocation;
|
std::unordered_map<uint64_t, QueueSourceLocation> m_sourceLocation;
|
||||||
uint64_t m_zonesCnt;
|
uint64_t m_zonesCnt;
|
||||||
|
|
||||||
@ -105,6 +109,7 @@ private:
|
|||||||
std::unordered_set<uint64_t> m_pendingStrings;
|
std::unordered_set<uint64_t> m_pendingStrings;
|
||||||
std::unordered_set<uint64_t> m_pendingThreads;
|
std::unordered_set<uint64_t> m_pendingThreads;
|
||||||
std::unordered_set<uint64_t> m_pendingSourceLocation;
|
std::unordered_set<uint64_t> m_pendingSourceLocation;
|
||||||
|
std::unordered_map<uint64_t, Event*> m_pendingCustomStrings;
|
||||||
std::unordered_map<uint64_t, uint32_t> m_threadMap;
|
std::unordered_map<uint64_t, uint32_t> m_threadMap;
|
||||||
|
|
||||||
Slab<EventSize*1024*1024> m_slab;
|
Slab<EventSize*1024*1024> m_slab;
|
||||||
|
Loading…
Reference in New Issue
Block a user