diff --git a/server/TracyView.cpp b/server/TracyView.cpp index aa75edf5..f8ef8819 100644 --- a/server/TracyView.cpp +++ b/server/TracyView.cpp @@ -243,8 +243,8 @@ View::View( FileRead& f ) auto dst = m_slab.Alloc( ssz+1 ); f.Read( dst, ssz ); dst[ssz] = '\0'; - m_customStringMap.emplace( dst, m_customStringData.size() ); - m_customStringData.push_back( dst ); + m_stringMap.emplace( dst, m_stringData.size() ); + m_stringData.push_back( dst ); stringMap.emplace( ptr, dst ); } @@ -916,28 +916,39 @@ void View::AddThreadString( uint64_t id, std::string&& str ) m_threadNames.emplace( id, std::move( str ) ); } -void View::AddCustomString( uint64_t ptr, std::string&& str ) +void View::AddCustomString( uint64_t ptr, const std::string& str ) { auto pit = m_pendingCustomStrings.find( ptr ); assert( pit != m_pendingCustomStrings.end() ); - std::unique_lock lock( m_lock ); - auto sit = m_customStringMap.find( str.c_str() ); - if( sit == m_customStringMap.end() ) + const auto sl = StoreString( str ); + m_lock.lock(); + GetTextData( *pit->second )->userText = sl.ptr; + m_lock.unlock(); + m_pendingCustomStrings.erase( pit ); +} + +View::StringLocation View::StoreString( const std::string& str ) +{ + StringLocation ret; + auto sit = m_stringMap.find( str.c_str() ); + if( sit == m_stringMap.end() ) { const auto sz = str.size(); auto ptr = m_slab.Alloc( sz+1 ); memcpy( ptr, str.c_str(), sz ); ptr[sz] = '\0'; - GetTextData( *pit->second )->userText = ptr; - m_customStringMap.emplace( ptr, m_customStringData.size() ); - m_customStringData.push_back( ptr ); + ret.ptr = ptr; + ret.idx = m_stringData.size(); + std::lock_guard lock( m_lock ); + m_stringMap.emplace( ptr, m_stringData.size() ); + m_stringData.push_back( ptr ); } else { - GetTextData( *pit->second )->userText = sit->first; + ret.ptr = sit->first; + ret.idx = sit->second; } - lock.unlock(); - m_pendingCustomStrings.erase( pit ); + return ret; } void View::AddSourceLocation( const QueueSourceLocation& srcloc ) @@ -3245,9 +3256,9 @@ void View::Write( FileWrite& f ) f.Write( v.second.c_str(), v.second.size() ); } - sz = m_customStringData.size(); + sz = m_stringData.size(); f.Write( &sz, sizeof( sz ) ); - for( auto& v : m_customStringData ) + for( auto& v : m_stringData ) { uint64_t ptr = (uint64_t)v; f.Write( &ptr, sizeof( ptr ) ); diff --git a/server/TracyView.hpp b/server/TracyView.hpp index 1f380f94..cc33721b 100644 --- a/server/TracyView.hpp +++ b/server/TracyView.hpp @@ -115,6 +115,12 @@ private: uint64_t postponeTime; }; + struct StringLocation + { + const char* ptr; + uint32_t idx; + }; + void Worker(); void DispatchProcess( const QueueItem& ev, const char*& ptr ); @@ -144,11 +150,13 @@ private: void AddString( uint64_t ptr, std::string&& str ); void AddThreadString( uint64_t id, std::string&& str ); - void AddCustomString( uint64_t ptr, std::string&& str ); + void AddCustomString( uint64_t ptr, const std::string& str ); void AddSourceLocation( const QueueSourceLocation& srcloc ); void AddSourceLocationPayload( uint64_t ptr, const char* data, size_t sz ); void AddMessageData( uint64_t ptr, const char* str, size_t sz ); + StringLocation StoreString( const std::string& str ); + uint32_t ShrinkSourceLocation( uint64_t srcloc ); void InsertMessageData( MessageData* msg, uint64_t thread ); @@ -237,8 +245,8 @@ private: std::map m_lockMap; uint64_t m_zonesCnt; - Vector m_customStringData; - std::unordered_map m_customStringMap; + Vector m_stringData; + std::unordered_map m_stringMap; std::mutex m_mbpslock; std::vector m_mbps;