Make srcloc dynamic color depend on function name.

This commit is contained in:
Bartosz Taudul 2019-11-01 20:17:25 +01:00
parent ca0fae33d1
commit 13b656fe61
3 changed files with 29 additions and 7 deletions

View File

@ -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;
}
};

View File

@ -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
{

View File

@ -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<sz; i++ )
{
auto srcloc = m_slab.Alloc<SourceLocation>();
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();