Use common string storage for thread names.

This commit is contained in:
Bartosz Taudul 2017-11-10 19:24:12 +01:00
parent 1baf7faf8f
commit b28fdc94ce
2 changed files with 25 additions and 28 deletions

View File

@ -219,18 +219,6 @@ View::View( FileRead& f )
m_strings.emplace( ptr, std::string( tmp, tmp+ssz ) );
}
f.Read( &sz, sizeof( sz ) );
for( uint64_t i=0; i<sz; i++ )
{
uint64_t ptr;
f.Read( &ptr, sizeof( ptr ) );
uint64_t ssz;
f.Read( &ssz, sizeof( ssz ) );
char tmp[16*1024];
f.Read( tmp, ssz );
m_threadNames.emplace( ptr, std::string( tmp, tmp+ssz ) );
}
std::unordered_map<uint64_t, const char*> pointerMap;
f.Read( &sz, sizeof( sz ) );
@ -248,6 +236,15 @@ View::View( FileRead& f )
pointerMap.emplace( ptr, dst );
}
f.Read( &sz, sizeof( sz ) );
for( uint64_t i=0; i<sz; i++ )
{
uint64_t id, ptr;
f.Read( &id, sizeof( id ) );
f.Read( &ptr, sizeof( ptr ) );
m_threadNames.emplace( id, pointerMap.find( ptr )->second );
}
f.Read( &sz, sizeof( sz ) );
for( uint64_t i=0; i<sz; i++ )
{
@ -544,7 +541,7 @@ void View::DispatchProcess( const QueueItem& ev, char*& ptr )
AddString( ev.stringTransfer.ptr, std::string( ptr, ptr+sz ) );
break;
case QueueType::ThreadName:
AddThreadString( ev.stringTransfer.ptr, std::string( ptr, ptr+sz ) );
AddThreadString( ev.stringTransfer.ptr, ptr, sz );
break;
case QueueType::PlotName:
HandlePlotName( ev.stringTransfer.ptr, std::string( ptr, ptr+sz ) );
@ -906,14 +903,15 @@ void View::AddString( uint64_t ptr, std::string&& str )
m_strings.emplace( ptr, std::move( str ) );
}
void View::AddThreadString( uint64_t id, std::string&& str )
void View::AddThreadString( uint64_t id, char* str, size_t sz )
{
assert( m_threadNames.find( id ) == m_threadNames.end() );
auto it = m_pendingThreads.find( id );
assert( it != m_pendingThreads.end() );
m_pendingThreads.erase( it );
const auto sl = StoreString( str, sz );
std::lock_guard<std::mutex> lock( m_lock );
m_threadNames.emplace( id, std::move( str ) );
m_threadNames.emplace( id, sl.ptr );
}
void View::AddCustomString( uint64_t ptr, char* str, size_t sz )
@ -1350,7 +1348,7 @@ const char* View::GetThreadString( uint64_t id ) const
}
else
{
return it->second.c_str();
return it->second;
}
}
@ -3247,16 +3245,6 @@ void View::Write( FileWrite& f )
f.Write( v.second.c_str(), v.second.size() );
}
sz = m_threadNames.size();
f.Write( &sz, sizeof( sz ) );
for( auto& v : m_threadNames )
{
f.Write( &v.first, sizeof( v.first ) );
sz = v.second.size();
f.Write( &sz, sizeof( sz ) );
f.Write( v.second.c_str(), v.second.size() );
}
sz = m_stringData.size();
f.Write( &sz, sizeof( sz ) );
for( auto& v : m_stringData )
@ -3268,6 +3256,15 @@ void View::Write( FileWrite& f )
f.Write( v, sz );
}
sz = m_threadNames.size();
f.Write( &sz, sizeof( sz ) );
for( auto& v : m_threadNames )
{
f.Write( &v.first, sizeof( v.first ) );
uint64_t ptr = (uint64_t)v.second;
f.Write( &ptr, sizeof( ptr ) );
}
sz = m_sourceLocation.size();
f.Write( &sz, sizeof( sz ) );
for( auto& v : m_sourceLocation )

View File

@ -149,7 +149,7 @@ private:
void CheckSourceLocationPayload( uint64_t ptr, ZoneEvent* dst );
void AddString( uint64_t ptr, std::string&& str );
void AddThreadString( uint64_t id, std::string&& str );
void AddThreadString( uint64_t id, char* str, size_t sz );
void AddCustomString( uint64_t ptr, char* str, size_t sz );
void AddSourceLocation( const QueueSourceLocation& srcloc );
void AddSourceLocationPayload( uint64_t ptr, const char* data, size_t sz );
@ -239,7 +239,7 @@ private:
Vector<TextData*> m_textData;
Vector<SourceLocation*> m_sourceLocationPayload;
std::unordered_map<uint64_t, std::string> m_strings;
std::unordered_map<uint64_t, std::string> m_threadNames;
std::unordered_map<uint64_t, const char*> m_threadNames;
std::unordered_map<uint64_t, SourceLocation> m_sourceLocation;
std::vector<uint64_t> m_sourceLocationExpand;
std::map<uint32_t, LockMap> m_lockMap;