Add thread name getter combining local and external thread names.

This commit is contained in:
Bartosz Taudul 2019-08-27 23:00:13 +02:00
parent f8e3d1ad0a
commit 3c092b4bec
2 changed files with 32 additions and 0 deletions

View File

@ -1849,6 +1849,37 @@ const char* Worker::GetThreadString( uint64_t id ) const
}
}
const char* Worker::GetThreadName( uint64_t id ) const
{
const auto it = m_data.threadNames.find( id );
if( it == m_data.threadNames.end() )
{
const auto eit = m_data.externalNames.find( id );
if( eit == m_data.externalNames.end() )
{
return "???";
}
else
{
return eit->second.second;
}
}
else
{
// Client should send additional information about thread name, to make this check unnecessary
const auto txt = it->second;
if( txt[0] >= '0' && txt[0] <= '9' && atoi( txt ) == id )
{
const auto eit = m_data.externalNames.find( id );
if( eit != m_data.externalNames.end() )
{
return eit->second.second;
}
}
return txt;
}
}
bool Worker::IsThreadLocal( uint64_t id ) const
{
return m_data.localThreadCompress.Exists( id );

View File

@ -337,6 +337,7 @@ public:
const char* GetString( const StringRef& ref ) const;
const char* GetString( const StringIdx& idx ) const;
const char* GetThreadString( uint64_t id ) const;
const char* GetThreadName( uint64_t id ) const;
bool IsThreadLocal( uint64_t id ) const;
const SourceLocation& GetSourceLocation( int16_t srcloc ) const;
std::pair<const char*, const char*> GetExternalName( uint64_t id ) const;