mirror of
https://github.com/wolfpld/tracy.git
synced 2024-11-22 22:44:34 +00:00
General solution for string pointer/index problem.
This commit is contained in:
parent
fb46b3cf24
commit
947cd04e5e
@ -8,14 +8,24 @@
|
|||||||
namespace tracy
|
namespace tracy
|
||||||
{
|
{
|
||||||
|
|
||||||
|
#pragma pack( 1 )
|
||||||
|
|
||||||
|
struct StringRef
|
||||||
|
{
|
||||||
|
union
|
||||||
|
{
|
||||||
|
uint64_t strptr;
|
||||||
|
uint32_t stridx;
|
||||||
|
};
|
||||||
|
bool isptr;
|
||||||
|
};
|
||||||
|
|
||||||
struct TextData
|
struct TextData
|
||||||
{
|
{
|
||||||
const char* userText;
|
const char* userText;
|
||||||
uint64_t zoneName; // ptr
|
uint64_t zoneName; // ptr
|
||||||
};
|
};
|
||||||
|
|
||||||
#pragma pack( 1 )
|
|
||||||
|
|
||||||
struct SourceLocation
|
struct SourceLocation
|
||||||
{
|
{
|
||||||
uint64_t function; // ptr
|
uint64_t function; // ptr
|
||||||
|
@ -321,19 +321,7 @@ View::View( FileRead& f )
|
|||||||
uint64_t ptr, tsz;
|
uint64_t ptr, tsz;
|
||||||
f.Read( &ptr, sizeof( ptr ) );
|
f.Read( &ptr, sizeof( ptr ) );
|
||||||
auto msgdata = m_slab.Alloc<MessageData>();
|
auto msgdata = m_slab.Alloc<MessageData>();
|
||||||
f.Read( &msgdata->_time_literal, sizeof( msgdata->_time_literal ) );
|
f.Read( msgdata, sizeof( *msgdata ) );
|
||||||
if( msgdata->literal )
|
|
||||||
{
|
|
||||||
f.Read( &msgdata->str, sizeof( msgdata->str ) );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
f.Read( &tsz, sizeof( tsz ) );
|
|
||||||
auto txt = m_slab.Alloc<char>( tsz+1 );
|
|
||||||
f.Read( txt, tsz );
|
|
||||||
txt[tsz] = '\0';
|
|
||||||
msgdata->txt = txt;
|
|
||||||
}
|
|
||||||
m_messages.push_back( msgdata );
|
m_messages.push_back( msgdata );
|
||||||
msgMap.emplace( ptr, msgdata );
|
msgMap.emplace( ptr, msgdata );
|
||||||
}
|
}
|
||||||
@ -839,8 +827,8 @@ void View::ProcessMessageLiteral( const QueueMessage& ev )
|
|||||||
CheckString( ev.text );
|
CheckString( ev.text );
|
||||||
auto msg = m_slab.Alloc<MessageData>();
|
auto msg = m_slab.Alloc<MessageData>();
|
||||||
msg->time = int64_t( ev.time * m_timerMul );
|
msg->time = int64_t( ev.time * m_timerMul );
|
||||||
msg->literal = true;
|
msg->ref.isptr = true;
|
||||||
msg->str = ev.text;
|
msg->ref.strptr = ev.text;
|
||||||
InsertMessageData( msg, ev.thread );
|
InsertMessageData( msg, ev.thread );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -996,18 +984,16 @@ void View::AddSourceLocationPayload( uint64_t ptr, const char* data, size_t sz )
|
|||||||
m_pendingSourceLocationPayload.erase( pit );
|
m_pendingSourceLocationPayload.erase( pit );
|
||||||
}
|
}
|
||||||
|
|
||||||
void View::AddMessageData( uint64_t ptr, const char* str, size_t sz )
|
void View::AddMessageData( uint64_t ptr, char* str, size_t sz )
|
||||||
{
|
{
|
||||||
auto txt = m_slab.Alloc<char>( sz+1 );
|
const auto sl = StoreString( str, sz );
|
||||||
memcpy( txt, str, sz );
|
|
||||||
txt[sz] = '\0';
|
|
||||||
|
|
||||||
auto it = m_pendingMessages.find( ptr );
|
auto it = m_pendingMessages.find( ptr );
|
||||||
assert( it != m_pendingMessages.end() );
|
assert( it != m_pendingMessages.end() );
|
||||||
auto msg = m_slab.Alloc<MessageData>();
|
auto msg = m_slab.Alloc<MessageData>();
|
||||||
msg->time = it->second.time;
|
msg->time = it->second.time;
|
||||||
msg->literal = false;
|
msg->ref.isptr = false;
|
||||||
msg->txt = txt;
|
msg->ref.stridx = sl.idx;
|
||||||
InsertMessageData( msg, it->second.thread );
|
InsertMessageData( msg, it->second.thread );
|
||||||
m_pendingMessages.erase( it );
|
m_pendingMessages.erase( it );
|
||||||
}
|
}
|
||||||
@ -1329,7 +1315,7 @@ int64_t View::GetZoneEnd( const ZoneEvent& ev ) const
|
|||||||
const char* View::GetString( uint64_t ptr ) const
|
const char* View::GetString( uint64_t ptr ) const
|
||||||
{
|
{
|
||||||
const auto it = m_strings.find( ptr );
|
const auto it = m_strings.find( ptr );
|
||||||
if( it == m_strings.end() )
|
if( it == m_strings.end() || it->second == nullptr )
|
||||||
{
|
{
|
||||||
return "???";
|
return "???";
|
||||||
}
|
}
|
||||||
@ -1339,6 +1325,18 @@ const char* View::GetString( uint64_t ptr ) const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char* View::GetString( const StringRef& ref ) const
|
||||||
|
{
|
||||||
|
if( ref.isptr )
|
||||||
|
{
|
||||||
|
return GetString( ref.strptr );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return m_stringData[ref.stridx];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const char* View::GetThreadString( uint64_t id ) const
|
const char* View::GetThreadString( uint64_t id ) const
|
||||||
{
|
{
|
||||||
const auto it = m_threadNames.find( id );
|
const auto it = m_threadNames.find( id );
|
||||||
@ -1967,7 +1965,7 @@ void View::DrawZones()
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
ImGui::Text( "%s", TimeToString( (*it)->time - m_frames[0] ) );
|
ImGui::Text( "%s", TimeToString( (*it)->time - m_frames[0] ) );
|
||||||
ImGui::Text( "%s", (*it)->literal ? GetString( (*it)->str ) : (*it)->txt );
|
ImGui::Text( "%s", GetString( (*it)->ref ) );
|
||||||
}
|
}
|
||||||
ImGui::EndTooltip();
|
ImGui::EndTooltip();
|
||||||
m_msgHighlight = *it;
|
m_msgHighlight = *it;
|
||||||
@ -3029,7 +3027,7 @@ void View::DrawMessages()
|
|||||||
for( auto& v : m_messages )
|
for( auto& v : m_messages )
|
||||||
{
|
{
|
||||||
char tmp[64 * 1024];
|
char tmp[64 * 1024];
|
||||||
sprintf( tmp, "%10s | %s", TimeToString( v->time - m_frames[0] ), v->literal ? GetString( v->str ) : v->txt );
|
sprintf( tmp, "%10s | %s", TimeToString( v->time - m_frames[0] ), GetString( v->ref ) );
|
||||||
if( m_msgHighlight == v )
|
if( m_msgHighlight == v )
|
||||||
{
|
{
|
||||||
ImGui::TextColored( ImVec4( 0xDD / 255.f, 0x22 / 255.f, 0x22 / 255.f, 1.f ), "%s", tmp );
|
ImGui::TextColored( ImVec4( 0xDD / 255.f, 0x22 / 255.f, 0x22 / 255.f, 1.f ), "%s", tmp );
|
||||||
@ -3323,17 +3321,7 @@ void View::Write( FileWrite& f )
|
|||||||
{
|
{
|
||||||
const auto ptr = (uint64_t)v;
|
const auto ptr = (uint64_t)v;
|
||||||
f.Write( &ptr, sizeof( ptr ) );
|
f.Write( &ptr, sizeof( ptr ) );
|
||||||
f.Write( &v->_time_literal, sizeof( v->_time_literal ) );
|
f.Write( v, sizeof( *v ) );
|
||||||
if( v->literal )
|
|
||||||
{
|
|
||||||
f.Write( &v->str, sizeof( v->str ) );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
sz = strlen( v->txt );
|
|
||||||
f.Write( &sz, sizeof( sz ) );
|
|
||||||
f.Write( v->txt, sz );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sz = m_textData.size();
|
sz = m_textData.size();
|
||||||
|
@ -54,20 +54,8 @@ private:
|
|||||||
|
|
||||||
struct MessageData
|
struct MessageData
|
||||||
{
|
{
|
||||||
union
|
int64_t time;
|
||||||
{
|
StringRef ref;
|
||||||
struct
|
|
||||||
{
|
|
||||||
int64_t time : 63;
|
|
||||||
int64_t literal : 1;
|
|
||||||
};
|
|
||||||
int64_t _time_literal;
|
|
||||||
};
|
|
||||||
union
|
|
||||||
{
|
|
||||||
const char* txt;
|
|
||||||
uint64_t str;
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ThreadData
|
struct ThreadData
|
||||||
@ -153,7 +141,7 @@ 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, const char* data, size_t sz );
|
void AddSourceLocationPayload( uint64_t ptr, const char* data, size_t sz );
|
||||||
void AddMessageData( uint64_t ptr, const char* str, 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 );
|
||||||
|
|
||||||
@ -182,6 +170,7 @@ private:
|
|||||||
int64_t GetLastTime() const;
|
int64_t GetLastTime() const;
|
||||||
int64_t GetZoneEnd( const ZoneEvent& ev ) const;
|
int64_t GetZoneEnd( const ZoneEvent& ev ) const;
|
||||||
const char* GetString( uint64_t ptr ) const;
|
const char* GetString( uint64_t ptr ) const;
|
||||||
|
const char* GetString( const StringRef& ref ) const;
|
||||||
const char* GetThreadString( uint64_t id ) const;
|
const char* GetThreadString( uint64_t id ) const;
|
||||||
const SourceLocation& GetSourceLocation( int32_t srcloc ) const;
|
const SourceLocation& GetSourceLocation( int32_t srcloc ) const;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user