mirror of
https://github.com/wolfpld/tracy.git
synced 2024-11-10 10:41:50 +00:00
Preemptive message text delivery.
This commit is contained in:
parent
76e11174dc
commit
7f3b8f4647
@ -264,15 +264,19 @@ Profiler::DequeueStatus Profiler::Dequeue( moodycamel::ConsumerToken& token )
|
|||||||
for( size_t i=0; i<sz; i++ )
|
for( size_t i=0; i<sz; i++ )
|
||||||
{
|
{
|
||||||
const auto item = m_itemBuf + i;
|
const auto item = m_itemBuf + i;
|
||||||
|
uint64_t ptr;
|
||||||
switch( item->hdr.type )
|
switch( item->hdr.type )
|
||||||
{
|
{
|
||||||
case QueueType::ZoneText:
|
case QueueType::ZoneText:
|
||||||
{
|
ptr = item->zoneText.text;
|
||||||
const auto ptr = item->zoneText.text;
|
SendString( ptr, (const char*)ptr, QueueType::CustomStringData );
|
||||||
|
tracy_free( (void*)ptr );
|
||||||
|
break;
|
||||||
|
case QueueType::Message:
|
||||||
|
ptr = item->message.text;
|
||||||
SendString( ptr, (const char*)ptr, QueueType::CustomStringData );
|
SendString( ptr, (const char*)ptr, QueueType::CustomStringData );
|
||||||
tracy_free( (void*)ptr );
|
tracy_free( (void*)ptr );
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -322,7 +326,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 || type == QueueType::CustomStringData || type == QueueType::PlotName || type == QueueType::MessageData );
|
assert( type == QueueType::StringData || type == QueueType::ThreadName || type == QueueType::CustomStringData || type == QueueType::PlotName );
|
||||||
|
|
||||||
QueueItem item;
|
QueueItem item;
|
||||||
item.hdr.type = type;
|
item.hdr.type = type;
|
||||||
@ -417,10 +421,6 @@ bool Profiler::HandleServerQuery()
|
|||||||
case ServerQueryPlotName:
|
case ServerQueryPlotName:
|
||||||
SendString( ptr, (const char*)ptr, QueueType::PlotName );
|
SendString( ptr, (const char*)ptr, QueueType::PlotName );
|
||||||
break;
|
break;
|
||||||
case ServerQueryMessage:
|
|
||||||
SendString( ptr, (const char*)ptr, QueueType::MessageData );
|
|
||||||
tracy_free( (void*)ptr );
|
|
||||||
break;
|
|
||||||
case ServerQueryTerminate:
|
case ServerQueryTerminate:
|
||||||
return false;
|
return false;
|
||||||
default:
|
default:
|
||||||
|
@ -24,7 +24,6 @@ enum ServerQuery : uint8_t
|
|||||||
ServerQuerySourceLocation,
|
ServerQuerySourceLocation,
|
||||||
ServerQuerySourceLocationPayload,
|
ServerQuerySourceLocationPayload,
|
||||||
ServerQueryPlotName,
|
ServerQueryPlotName,
|
||||||
ServerQueryMessage,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
enum { WelcomeMessageProgramNameSize = 64 };
|
enum { WelcomeMessageProgramNameSize = 64 };
|
||||||
|
@ -28,7 +28,6 @@ enum class QueueType : uint8_t
|
|||||||
PlotName,
|
PlotName,
|
||||||
Message,
|
Message,
|
||||||
MessageLiteral,
|
MessageLiteral,
|
||||||
MessageData,
|
|
||||||
NUM_TYPES
|
NUM_TYPES
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -193,7 +192,6 @@ static const size_t QueueDataSize[] = {
|
|||||||
sizeof( QueueHeader ) + sizeof( QueueStringTransfer ), // plot name
|
sizeof( QueueHeader ) + sizeof( QueueStringTransfer ), // plot name
|
||||||
sizeof( QueueHeader ) + sizeof( QueueMessage ),
|
sizeof( QueueHeader ) + sizeof( QueueMessage ),
|
||||||
sizeof( QueueHeader ) + sizeof( QueueMessage ), // literal
|
sizeof( QueueHeader ) + sizeof( QueueMessage ), // literal
|
||||||
sizeof( QueueHeader ) + sizeof( QueueStringTransfer ), // message data
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static_assert( QueueItemSize == 32, "Queue item size not 32 bytes" );
|
static_assert( QueueItemSize == 32, "Queue item size not 32 bytes" );
|
||||||
|
@ -468,7 +468,7 @@ void View::Worker()
|
|||||||
if( m_terminate )
|
if( m_terminate )
|
||||||
{
|
{
|
||||||
if( !m_pendingStrings.empty() || !m_pendingThreads.empty() || !m_pendingSourceLocation.empty() ||
|
if( !m_pendingStrings.empty() || !m_pendingThreads.empty() || !m_pendingSourceLocation.empty() ||
|
||||||
!m_pendingCustomStrings.empty() || !m_pendingPlots.empty() || !m_pendingMessages.empty() )
|
!m_pendingCustomStrings.empty() || !m_pendingPlots.empty() )
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -496,7 +496,7 @@ close:
|
|||||||
void View::DispatchProcess( const QueueItem& ev, char*& ptr )
|
void View::DispatchProcess( const QueueItem& ev, char*& ptr )
|
||||||
{
|
{
|
||||||
ptr += QueueDataSize[ev.hdr.idx];
|
ptr += QueueDataSize[ev.hdr.idx];
|
||||||
if( ev.hdr.type == QueueType::CustomStringData || ev.hdr.type == QueueType::StringData || ev.hdr.type == QueueType::ThreadName || ev.hdr.type == QueueType::PlotName || ev.hdr.type == QueueType::MessageData || ev.hdr.type == QueueType::SourceLocationPayload )
|
if( ev.hdr.type == QueueType::CustomStringData || ev.hdr.type == QueueType::StringData || ev.hdr.type == QueueType::ThreadName || ev.hdr.type == QueueType::PlotName || ev.hdr.type == QueueType::SourceLocationPayload )
|
||||||
{
|
{
|
||||||
uint16_t sz;
|
uint16_t sz;
|
||||||
memcpy( &sz, ptr, sizeof( sz ) );
|
memcpy( &sz, ptr, sizeof( sz ) );
|
||||||
@ -515,9 +515,6 @@ void View::DispatchProcess( const QueueItem& ev, char*& ptr )
|
|||||||
case QueueType::PlotName:
|
case QueueType::PlotName:
|
||||||
HandlePlotName( ev.stringTransfer.ptr, ptr, sz );
|
HandlePlotName( ev.stringTransfer.ptr, ptr, sz );
|
||||||
break;
|
break;
|
||||||
case QueueType::MessageData:
|
|
||||||
AddMessageData( ev.stringTransfer.ptr, ptr, sz );
|
|
||||||
break;
|
|
||||||
case QueueType::SourceLocationPayload:
|
case QueueType::SourceLocationPayload:
|
||||||
AddSourceLocationPayload( ev.stringTransfer.ptr, ptr, sz );
|
AddSourceLocationPayload( ev.stringTransfer.ptr, ptr, sz );
|
||||||
break;
|
break;
|
||||||
@ -669,7 +666,7 @@ void View::ProcessZoneText( const QueueZoneText& ev )
|
|||||||
auto it = m_pendingCustomStrings.find( ev.text );
|
auto it = m_pendingCustomStrings.find( ev.text );
|
||||||
assert( it != m_pendingCustomStrings.end() );
|
assert( it != m_pendingCustomStrings.end() );
|
||||||
m_lock.lock();
|
m_lock.lock();
|
||||||
GetTextData( *zone )->userText = it->second;
|
GetTextData( *zone )->userText = it->second.ptr;
|
||||||
m_lock.unlock();
|
m_lock.unlock();
|
||||||
m_pendingCustomStrings.erase( it );
|
m_pendingCustomStrings.erase( it );
|
||||||
}
|
}
|
||||||
@ -807,8 +804,14 @@ void View::ProcessPlotData( const QueuePlotData& ev )
|
|||||||
|
|
||||||
void View::ProcessMessage( const QueueMessage& ev )
|
void View::ProcessMessage( const QueueMessage& ev )
|
||||||
{
|
{
|
||||||
m_pendingMessages.emplace( ev.text, MessagePending { int64_t( ev.time * m_timerMul ), ev.thread } );
|
auto it = m_pendingCustomStrings.find( ev.text );
|
||||||
ServerQuery( ServerQueryMessage, ev.text );
|
assert( it != m_pendingCustomStrings.end() );
|
||||||
|
auto msg = m_slab.Alloc<MessageData>();
|
||||||
|
msg->time = int64_t( ev.time * m_timerMul );
|
||||||
|
msg->ref.isidx = true;
|
||||||
|
msg->ref.stridx = it->second.idx;
|
||||||
|
InsertMessageData( msg, ev.thread );
|
||||||
|
m_pendingCustomStrings.erase( it );
|
||||||
}
|
}
|
||||||
|
|
||||||
void View::ProcessMessageLiteral( const QueueMessage& ev )
|
void View::ProcessMessageLiteral( const QueueMessage& ev )
|
||||||
@ -883,9 +886,8 @@ void View::AddThreadString( uint64_t id, char* str, size_t sz )
|
|||||||
|
|
||||||
void View::AddCustomString( uint64_t ptr, char* str, size_t sz )
|
void View::AddCustomString( uint64_t ptr, char* str, size_t sz )
|
||||||
{
|
{
|
||||||
const auto sl = StoreString( str, sz );
|
|
||||||
assert( m_pendingCustomString.find( ptr ) == m_pendingCustomStrings.end() );
|
assert( m_pendingCustomString.find( ptr ) == m_pendingCustomStrings.end() );
|
||||||
m_pendingCustomStrings.emplace( ptr, sl.ptr );
|
m_pendingCustomStrings.emplace( ptr, StoreString( str, sz ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
View::StringLocation View::StoreString( char* str, size_t sz )
|
View::StringLocation View::StoreString( char* str, size_t sz )
|
||||||
@ -966,20 +968,6 @@ void View::AddSourceLocationPayload( uint64_t ptr, char* data, size_t sz )
|
|||||||
m_pendingSourceLocationPayload.erase( pit );
|
m_pendingSourceLocationPayload.erase( pit );
|
||||||
}
|
}
|
||||||
|
|
||||||
void View::AddMessageData( uint64_t ptr, char* str, size_t sz )
|
|
||||||
{
|
|
||||||
const auto sl = StoreString( str, sz );
|
|
||||||
|
|
||||||
auto it = m_pendingMessages.find( ptr );
|
|
||||||
assert( it != m_pendingMessages.end() );
|
|
||||||
auto msg = m_slab.Alloc<MessageData>();
|
|
||||||
msg->time = it->second.time;
|
|
||||||
msg->ref.isidx = true;
|
|
||||||
msg->ref.stridx = sl.idx;
|
|
||||||
InsertMessageData( msg, it->second.thread );
|
|
||||||
m_pendingMessages.erase( it );
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t View::ShrinkSourceLocation( uint64_t srcloc )
|
uint32_t View::ShrinkSourceLocation( uint64_t srcloc )
|
||||||
{
|
{
|
||||||
auto it = m_sourceLocationShrink.find( srcloc );
|
auto it = m_sourceLocationShrink.find( srcloc );
|
||||||
|
@ -46,12 +46,6 @@ private:
|
|||||||
Short
|
Short
|
||||||
};
|
};
|
||||||
|
|
||||||
struct MessagePending
|
|
||||||
{
|
|
||||||
int64_t time;
|
|
||||||
uint64_t thread;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct MessageData
|
struct MessageData
|
||||||
{
|
{
|
||||||
int64_t time;
|
int64_t time;
|
||||||
@ -156,7 +150,6 @@ private:
|
|||||||
void AddCustomString( uint64_t ptr, char* str, size_t sz );
|
void AddCustomString( uint64_t ptr, char* str, size_t sz );
|
||||||
void AddSourceLocation( const QueueSourceLocation& srcloc );
|
void AddSourceLocation( const QueueSourceLocation& srcloc );
|
||||||
void AddSourceLocationPayload( uint64_t ptr, char* data, size_t sz );
|
void AddSourceLocationPayload( uint64_t ptr, char* data, size_t sz );
|
||||||
void AddMessageData( uint64_t ptr, char* str, size_t sz );
|
|
||||||
|
|
||||||
StringLocation StoreString( char* str, size_t sz );
|
StringLocation StoreString( char* str, size_t sz );
|
||||||
|
|
||||||
@ -259,12 +252,11 @@ 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, const char*> m_pendingCustomStrings;
|
std::unordered_map<uint64_t, StringLocation> m_pendingCustomStrings;
|
||||||
std::unordered_map<uint64_t, uint32_t> m_threadMap;
|
std::unordered_map<uint64_t, uint32_t> m_threadMap;
|
||||||
std::unordered_map<uint64_t, uint32_t> m_plotMap;
|
std::unordered_map<uint64_t, uint32_t> m_plotMap;
|
||||||
std::unordered_map<const char*, uint32_t, charutil::Hasher, charutil::Comparator> m_plotRev;
|
std::unordered_map<const char*, uint32_t, charutil::Hasher, charutil::Comparator> m_plotRev;
|
||||||
std::unordered_map<uint64_t, PlotData*> m_pendingPlots;
|
std::unordered_map<uint64_t, PlotData*> m_pendingPlots;
|
||||||
std::unordered_map<uint64_t, MessagePending> m_pendingMessages;
|
|
||||||
std::unordered_map<uint64_t, uint32_t> m_sourceLocationShrink;
|
std::unordered_map<uint64_t, uint32_t> m_sourceLocationShrink;
|
||||||
std::unordered_map<uint64_t, ZoneEvent*> m_pendingSourceLocationPayload;
|
std::unordered_map<uint64_t, ZoneEvent*> m_pendingSourceLocationPayload;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user