Store source location on 32 bits, not 64.

This commit is contained in:
Bartosz Taudul 2017-10-28 22:14:01 +02:00
parent fb6c91b552
commit 39ac41bc19
3 changed files with 48 additions and 11 deletions

View File

@ -20,7 +20,7 @@ struct ZoneEvent
{ {
int64_t start; int64_t start;
int64_t end; int64_t end;
uint64_t srcloc; uint32_t srcloc;
int8_t cpu_start; int8_t cpu_start;
int8_t cpu_end; int8_t cpu_end;
@ -41,7 +41,7 @@ struct LockEvent
}; };
int64_t time; int64_t time;
uint64_t srcloc; uint32_t srcloc;
uint64_t waitList; uint64_t waitList;
uint8_t thread; uint8_t thread;
uint8_t lockingThread; uint8_t lockingThread;

View File

@ -156,6 +156,7 @@ View::View( const char* addr )
, m_onlyContendedLocks( false ) , m_onlyContendedLocks( false )
, m_namespace( Namespace::Full ) , m_namespace( Namespace::Full )
, m_terminate( false ) , m_terminate( false )
, m_sourceLocationExpand( { 0 } )
{ {
assert( s_instance == nullptr ); assert( s_instance == nullptr );
s_instance = this; s_instance = this;
@ -268,6 +269,15 @@ View::View( FileRead& f )
m_sourceLocation.emplace( ptr, srcloc ); m_sourceLocation.emplace( ptr, srcloc );
} }
f.Read( &sz, sizeof( sz ) );
m_sourceLocationExpand.reserve( sz );
for( uint64_t i=0; i<sz; i++ )
{
uint64_t v;
f.Read( &v, sizeof( v ) );
m_sourceLocationExpand.push_back( v );
}
f.Read( &sz, sizeof( sz ) ); f.Read( &sz, sizeof( sz ) );
for( uint64_t i=0; i<sz; i++ ) for( uint64_t i=0; i<sz; i++ )
{ {
@ -664,7 +674,7 @@ void View::ProcessZoneBegin( const QueueZoneBegin& ev )
zone->start = ev.time * m_timerMul; zone->start = ev.time * m_timerMul;
zone->end = -1; zone->end = -1;
zone->srcloc = ev.srcloc; zone->srcloc = ShrinkSourceLocation( ev.srcloc );
assert( ev.cpu == 0xFFFFFFFF || ev.cpu <= std::numeric_limits<int8_t>::max() ); assert( ev.cpu == 0xFFFFFFFF || ev.cpu <= std::numeric_limits<int8_t>::max() );
zone->cpu_start = ev.cpu == 0xFFFFFFFF ? -1 : (int8_t)ev.cpu; zone->cpu_start = ev.cpu == 0xFFFFFFFF ? -1 : (int8_t)ev.cpu;
zone->text = -1; zone->text = -1;
@ -731,14 +741,14 @@ void View::ProcessLockWait( const QueueLockWait& ev )
if( it == m_lockMap.end() ) if( it == m_lockMap.end() )
{ {
LockMap lm; LockMap lm;
lm.srcloc = ev.lckloc; lm.srcloc = ShrinkSourceLocation( ev.lckloc );
lm.visible = true; lm.visible = true;
it = m_lockMap.emplace( ev.id, std::move( lm ) ).first; it = m_lockMap.emplace( ev.id, std::move( lm ) ).first;
CheckSourceLocation( ev.lckloc ); CheckSourceLocation( ev.lckloc );
} }
else if( it->second.srcloc == 0 ) else if( it->second.srcloc == 0 )
{ {
it->second.srcloc = ev.lckloc; it->second.srcloc = ShrinkSourceLocation( ev.lckloc );
CheckSourceLocation( ev.lckloc ); CheckSourceLocation( ev.lckloc );
} }
InsertLockEvent( it->second, lev, ev.thread ); InsertLockEvent( it->second, lev, ev.thread );
@ -786,7 +796,7 @@ void View::ProcessLockMark( const QueueLockMark& ev )
{ {
case LockEvent::Type::Obtain: case LockEvent::Type::Obtain:
case LockEvent::Type::Wait: case LockEvent::Type::Wait:
(*it)->srcloc = ev.srcloc; (*it)->srcloc = ShrinkSourceLocation( ev.srcloc );
return; return;
default: default:
break; break;
@ -965,6 +975,22 @@ void View::AddMessageData( uint64_t ptr, const char* str, size_t sz )
m_pendingMessages.erase( it ); m_pendingMessages.erase( it );
} }
uint32_t View::ShrinkSourceLocation( uint64_t srcloc )
{
auto it = m_sourceLocationShrink.find( srcloc );
if( it != m_sourceLocationShrink.end() )
{
return it->second;
}
else
{
const auto sz = m_sourceLocationExpand.size();
m_sourceLocationExpand.push_back( srcloc );
m_sourceLocationShrink.emplace( srcloc, sz );
return sz;
}
}
void View::InsertMessageData( MessageData* msg, uint64_t thread ) void View::InsertMessageData( MessageData* msg, uint64_t thread )
{ {
std::lock_guard<std::mutex> lock( m_lock ); std::lock_guard<std::mutex> lock( m_lock );
@ -1285,10 +1311,10 @@ const char* View::GetThreadString( uint64_t id ) const
} }
} }
const QueueSourceLocation& View::GetSourceLocation( uint64_t srcloc ) const const QueueSourceLocation& View::GetSourceLocation( uint32_t srcloc ) const
{ {
static const QueueSourceLocation empty = {}; static const QueueSourceLocation empty = {};
const auto it = m_sourceLocation.find( srcloc ); const auto it = m_sourceLocation.find( m_sourceLocationExpand[srcloc] );
if( it == m_sourceLocation.end() ) return empty; if( it == m_sourceLocation.end() ) return empty;
return it->second; return it->second;
} }
@ -2430,7 +2456,7 @@ int View::DrawLocks( uint64_t tid, bool hover, double pxns, const ImVec2& wpos,
ImGui::Text( "Time: %s", TimeToString( t1 - t0 ) ); ImGui::Text( "Time: %s", TimeToString( t1 - t0 ) );
ImGui::Separator(); ImGui::Separator();
uint64_t markloc = 0; uint32_t markloc = 0;
auto it = vbegin; auto it = vbegin;
for(;;) for(;;)
{ {
@ -3154,6 +3180,13 @@ void View::Write( FileWrite& f )
f.Write( &v.second, sizeof( v.second ) ); f.Write( &v.second, sizeof( v.second ) );
} }
sz = m_sourceLocationExpand.size();
f.Write( &sz, sizeof( sz ) );
for( auto& v : m_sourceLocationExpand )
{
f.Write( &v, sizeof( v ) );
}
sz = m_lockMap.size(); sz = m_lockMap.size();
f.Write( &sz, sizeof( sz ) ); f.Write( &sz, sizeof( sz ) );
for( auto& v : m_lockMap ) for( auto& v : m_lockMap )

View File

@ -81,7 +81,7 @@ private:
struct LockMap struct LockMap
{ {
uint64_t srcloc; uint32_t srcloc;
Vector<LockEvent*> timeline; Vector<LockEvent*> timeline;
std::unordered_map<uint64_t, uint8_t> threadMap; std::unordered_map<uint64_t, uint8_t> threadMap;
std::vector<uint64_t> threadList; std::vector<uint64_t> threadList;
@ -147,6 +147,8 @@ private:
void AddSourceLocation( const QueueSourceLocation& srcloc ); void AddSourceLocation( const QueueSourceLocation& srcloc );
void AddMessageData( uint64_t ptr, const char* str, size_t sz ); void AddMessageData( uint64_t ptr, const char* str, size_t sz );
uint32_t ShrinkSourceLocation( uint64_t srcloc );
void InsertMessageData( MessageData* msg, uint64_t thread ); void InsertMessageData( MessageData* msg, uint64_t thread );
ThreadData* NoticeThread( uint64_t thread ); ThreadData* NoticeThread( uint64_t thread );
@ -171,7 +173,7 @@ private:
int64_t GetZoneEnd( const ZoneEvent& ev ) const; int64_t GetZoneEnd( const ZoneEvent& ev ) const;
const char* GetString( uint64_t ptr ) const; const char* GetString( uint64_t ptr ) const;
const char* GetThreadString( uint64_t id ) const; const char* GetThreadString( uint64_t id ) const;
const QueueSourceLocation& GetSourceLocation( uint64_t srcloc ) const; const QueueSourceLocation& GetSourceLocation( uint32_t srcloc ) const;
const char* ShortenNamespace( const char* name ) const; const char* ShortenNamespace( const char* name ) const;
@ -226,6 +228,7 @@ private:
std::unordered_map<uint64_t, std::string> m_threadNames; std::unordered_map<uint64_t, std::string> m_threadNames;
std::unordered_set<const char*, charutil::Hasher, charutil::Comparator> m_customStrings; std::unordered_set<const char*, charutil::Hasher, charutil::Comparator> m_customStrings;
std::unordered_map<uint64_t, QueueSourceLocation> m_sourceLocation; std::unordered_map<uint64_t, QueueSourceLocation> m_sourceLocation;
std::vector<uint64_t> m_sourceLocationExpand;
std::map<uint32_t, LockMap> m_lockMap; std::map<uint32_t, LockMap> m_lockMap;
uint64_t m_zonesCnt; uint64_t m_zonesCnt;
@ -243,6 +246,7 @@ private:
std::unordered_map<std::string, uint32_t> m_plotRev; std::unordered_map<std::string, uint32_t> m_plotRev;
std::unordered_map<uint64_t, PlotData*> m_pendingPlots; std::unordered_map<uint64_t, PlotData*> m_pendingPlots;
std::unordered_map<uint64_t, MessagePending> m_pendingMessages; std::unordered_map<uint64_t, MessagePending> m_pendingMessages;
std::unordered_map<uint64_t, uint32_t> m_sourceLocationShrink;
Slab<64*1024*1024> m_slab; Slab<64*1024*1024> m_slab;