diff --git a/server/TracyEvent.hpp b/server/TracyEvent.hpp index 193dbd1f..b981715c 100644 --- a/server/TracyEvent.hpp +++ b/server/TracyEvent.hpp @@ -135,7 +135,7 @@ private: }; -struct SourceLocation +struct SourceLocationBase { StringRef name; StringRef function; @@ -144,6 +144,11 @@ struct SourceLocation uint32_t color; }; +struct SourceLocation : public SourceLocationBase +{ + mutable uint32_t namehash; +}; + enum { SourceLocationSize = sizeof( SourceLocation ) }; @@ -510,7 +515,7 @@ struct SourceLocationHasher { size_t operator()( const SourceLocation* ptr ) const { - return charutil::hash( (const char*)ptr, sizeof( SourceLocation ) ); + return charutil::hash( (const char*)ptr, sizeof( SourceLocationBase ) ); } typedef tracy::power_of_two_hash_policy hash_policy; }; @@ -519,7 +524,7 @@ struct SourceLocationComparator { bool operator()( const SourceLocation* lhs, const SourceLocation* rhs ) const { - return memcmp( lhs, rhs, sizeof( SourceLocation ) ) == 0; + return memcmp( lhs, rhs, sizeof( SourceLocationBase ) ) == 0; } }; diff --git a/server/TracyView.cpp b/server/TracyView.cpp index 999b0be2..d24e2586 100644 --- a/server/TracyView.cpp +++ b/server/TracyView.cpp @@ -12849,7 +12849,22 @@ uint32_t View::GetRawZoneColor( const ZoneEvent& ev, uint64_t thread, int depth if( color != 0 ) return color | 0xFF000000; if( m_vd.dynamicColors == 2 ) { - return GetThreadColor( sl, depth ); + auto namehash = srcloc.namehash; + if( namehash == 0 && srcloc.function.active ) + { + const auto f = m_worker.GetString( srcloc.function ); + namehash = charutil::hash( f ); + if( namehash == 0 ) namehash++; + srcloc.namehash = namehash; + } + if( namehash == 0 ) + { + return GetThreadColor( sl, depth ); + } + else + { + return GetThreadColor( namehash, depth ); + } } else { diff --git a/server/TracyWorker.cpp b/server/TracyWorker.cpp index a3c4240d..7c4022dc 100644 --- a/server/TracyWorker.cpp +++ b/server/TracyWorker.cpp @@ -541,7 +541,8 @@ Worker::Worker( FileRead& f, EventType::Type eventMask, bool bgTasks ) uint64_t ptr; f.Read( ptr ); SourceLocation srcloc; - f.Read( srcloc ); + f.Read( &srcloc, sizeof( SourceLocationBase ) ); + srcloc.namehash = 0; m_data.sourceLocation.emplace( ptr, srcloc ); } @@ -555,7 +556,8 @@ Worker::Worker( FileRead& f, EventType::Type eventMask, bool bgTasks ) for( uint64_t i=0; i(); - f.Read( srcloc, sizeof( *srcloc ) ); + f.Read( srcloc, sizeof( SourceLocationBase ) ); + srcloc->namehash = 0; m_data.sourceLocationPayload[i] = srcloc; m_data.sourceLocationPayloadMap.emplace( srcloc, int16_t( i ) ); } @@ -5424,7 +5426,7 @@ void Worker::Write( FileWrite& f ) for( auto& v : m_data.sourceLocation ) { f.Write( &v.first, sizeof( v.first ) ); - f.Write( &v.second, sizeof( v.second ) ); + f.Write( &v.second, sizeof( SourceLocationBase ) ); } sz = m_data.sourceLocationExpand.size();