Thread names boilerplate.

This commit is contained in:
Bartosz Taudul 2017-09-22 01:30:57 +02:00
parent d610b9d1a2
commit 3032745cce
2 changed files with 39 additions and 0 deletions

View File

@ -212,6 +212,7 @@ void View::ProcessZoneBegin( uint64_t id, const QueueZoneBegin& ev )
CheckString( ev.filename ); CheckString( ev.filename );
CheckString( ev.function ); CheckString( ev.function );
CheckThreadString( ev.thread );
zone->start = ev.time; zone->start = ev.time;
SourceLocation srcloc { ev.filename, ev.function, ev.line }; SourceLocation srcloc { ev.filename, ev.function, ev.line };
@ -292,6 +293,15 @@ void View::CheckString( uint64_t ptr )
m_sock.Send( &ptr, sizeof( ptr ) ); m_sock.Send( &ptr, sizeof( ptr ) );
} }
void View::CheckThreadString( uint64_t id )
{
if( m_threadNames.find( id ) != m_threadNames.end() ) return;
if( m_pendingThreads.find( id ) != m_pendingThreads.end() ) return;
m_pendingThreads.emplace( id );
// TODO send
}
void View::AddString( uint64_t ptr, std::string&& str ) void View::AddString( uint64_t ptr, std::string&& str )
{ {
assert( m_strings.find( ptr ) == m_strings.end() ); assert( m_strings.find( ptr ) == m_strings.end() );
@ -302,6 +312,17 @@ void View::AddString( uint64_t ptr, std::string&& str )
m_strings.emplace( ptr, std::move( str ) ); m_strings.emplace( ptr, std::move( str ) );
} }
void View::AddThreadString( uint64_t id, std::string&& str )
{
assert( m_threadNames.find( id ) == m_threadNames.end() );
auto it = m_pendingThreads.find( id );
assert( it != m_pendingThreads.end() );
m_pendingThreads.erase( it );
std::lock_guard<std::mutex> lock( m_lock );
m_threadNames.emplace( id, std::move( str ) );
}
void View::NewZone( Event* zone, uint64_t thread ) void View::NewZone( Event* zone, uint64_t thread )
{ {
Vector<Event*>* timeline; Vector<Event*>* timeline;
@ -432,6 +453,19 @@ const char* View::GetString( uint64_t ptr ) const
} }
} }
const char* View::GetThreadString( uint64_t id ) const
{
const auto it = m_threadNames.find( id );
if( it == m_threadNames.end() )
{
return "???";
}
else
{
return it->second.c_str();
}
}
void View::Draw() void View::Draw()
{ {
s_instance->DrawImpl(); s_instance->DrawImpl();

View File

@ -49,7 +49,9 @@ private:
void ProcessFrameMark( uint64_t id ); void ProcessFrameMark( uint64_t id );
void CheckString( uint64_t ptr ); void CheckString( uint64_t ptr );
void CheckThreadString( uint64_t id );
void AddString( uint64_t ptr, std::string&& str ); void AddString( uint64_t ptr, std::string&& str );
void AddThreadString( uint64_t id, std::string&& str );
void NewZone( Event* zone, uint64_t thread ); void NewZone( Event* zone, uint64_t thread );
void UpdateZone( Event* zone ); void UpdateZone( Event* zone );
@ -60,6 +62,7 @@ private:
uint64_t GetLastTime() const; uint64_t GetLastTime() const;
const char* TimeToString( uint64_t ns ) const; const char* TimeToString( uint64_t ns ) const;
const char* GetString( uint64_t ptr ) const; const char* GetString( uint64_t ptr ) const;
const char* GetThreadString( uint64_t id ) const;
void DrawImpl(); void DrawImpl();
void DrawFrames(); void DrawFrames();
@ -79,6 +82,7 @@ private:
Vector<SourceLocation> m_srcFile; Vector<SourceLocation> m_srcFile;
Vector<ThreadData> m_threads; Vector<ThreadData> m_threads;
std::unordered_map<uint64_t, std::string> m_strings; std::unordered_map<uint64_t, std::string> m_strings;
std::unordered_map<uint64_t, std::string> m_threadNames;
std::mutex m_mbpslock; std::mutex m_mbpslock;
std::vector<float> m_mbps; std::vector<float> m_mbps;
@ -87,6 +91,7 @@ private:
std::unordered_map<uint64_t, QueueZoneEnd> m_pendingEndZone; std::unordered_map<uint64_t, QueueZoneEnd> m_pendingEndZone;
std::unordered_map<uint64_t, Event*> m_openZones; std::unordered_map<uint64_t, Event*> m_openZones;
std::unordered_set<uint64_t> m_pendingStrings; std::unordered_set<uint64_t> m_pendingStrings;
std::unordered_set<uint64_t> m_pendingThreads;
std::unordered_map<SourceLocation, uint32_t, SourceLocation::Hasher, SourceLocation::Comparator> m_locationRef; std::unordered_map<SourceLocation, uint32_t, SourceLocation::Hasher, SourceLocation::Comparator> m_locationRef;
std::unordered_map<uint64_t, uint32_t> m_threadMap; std::unordered_map<uint64_t, uint32_t> m_threadMap;