Store lock map as flat_hash_map with pointer values.

This commit is contained in:
Bartosz Taudul 2019-03-16 02:09:50 +01:00
parent 5fbc14c487
commit 71e20e7e7f
3 changed files with 89 additions and 81 deletions

View File

@ -2171,7 +2171,7 @@ void View::DrawZones()
size_t lockCnt = 0;
for( const auto& lock : m_worker.GetLockMap() )
{
const auto& lockmap = lock.second;
const auto& lockmap = *lock.second;
if( !lockmap.valid ) continue;
auto it = lockmap.threadMap.find( v->id );
if( it == lockmap.threadMap.end() ) continue;
@ -3126,7 +3126,7 @@ int View::DrawLocks( uint64_t tid, bool hover, double pxns, const ImVec2& wpos,
int cnt = 0;
for( const auto& v : m_worker.GetLockMap() )
{
const auto& lockmap = v.second;
const auto& lockmap = *v.second;
if( !lockmap.valid || !Vis( &lockmap ).visible ) continue;
if( m_onlyContendedLocks && lockmap.threadList.size() == 1 && m_lockInfoWindow != v.first ) continue;
@ -5196,10 +5196,10 @@ void View::DrawOptions()
size_t multiCnt = 0;
for( const auto& l : m_worker.GetLockMap() )
{
if( l.second.valid && !l.second.timeline.empty() )
if( l.second->valid && !l.second->timeline.empty() )
{
lockCnt++;
if( l.second.threadList.size() == 1 )
if( l.second->threadList.size() == 1 )
{
singleCnt++;
}
@ -5233,7 +5233,7 @@ void View::DrawOptions()
{
for( const auto& l : m_worker.GetLockMap() )
{
Vis( &l.second ).visible = true;
Vis( l.second ).visible = true;
}
}
ImGui::SameLine();
@ -5241,7 +5241,7 @@ void View::DrawOptions()
{
for( const auto& l : m_worker.GetLockMap() )
{
Vis( &l.second ).visible = false;
Vis( l.second ).visible = false;
}
}
ImGui::SameLine();
@ -5256,7 +5256,7 @@ void View::DrawOptions()
{
for( const auto& l : m_worker.GetLockMap() )
{
if( l.second.threadList.size() != 1 ) Vis( &l.second ).visible = true;
if( l.second->threadList.size() != 1 ) Vis( l.second ).visible = true;
}
}
ImGui::SameLine();
@ -5264,20 +5264,20 @@ void View::DrawOptions()
{
for( const auto& l : m_worker.GetLockMap() )
{
if( l.second.threadList.size() != 1 ) Vis( &l.second ).visible = false;
if( l.second->threadList.size() != 1 ) Vis( l.second ).visible = false;
}
}
for( const auto& l : m_worker.GetLockMap() )
{
if( l.second.valid && !l.second.timeline.empty() && l.second.threadList.size() != 1 )
if( l.second->valid && !l.second->timeline.empty() && l.second->threadList.size() != 1 )
{
auto& sl = m_worker.GetSourceLocation( l.second.srcloc );
auto& sl = m_worker.GetSourceLocation( l.second->srcloc );
auto fileName = m_worker.GetString( sl.file );
char buf[1024];
sprintf( buf, "%" PRIu32 ": %s", l.first, m_worker.GetString( m_worker.GetSourceLocation( l.second.srcloc ).function ) );
ImGui::Checkbox( buf, &Vis( &l.second ).visible );
sprintf( buf, "%" PRIu32 ": %s", l.first, m_worker.GetString( m_worker.GetSourceLocation( l.second->srcloc ).function ) );
ImGui::Checkbox( buf, &Vis( l.second ).visible );
if( ImGui::IsItemHovered() )
{
m_lockHoverHighlight = l.first;
@ -5287,7 +5287,7 @@ void View::DrawOptions()
m_lockInfoWindow = l.first;
}
}
if( m_optionsLockBuzzAnim.Match( l.second.srcloc ) )
if( m_optionsLockBuzzAnim.Match( l.second->srcloc ) )
{
const auto time = m_optionsLockBuzzAnim.Time();
const auto indentVal = sin( time * 60.f ) * 10.f * time;
@ -5297,7 +5297,7 @@ void View::DrawOptions()
{
ImGui::SameLine();
}
ImGui::TextDisabled( "(%s) %s:%i", RealToString( l.second.timeline.size(), true ), fileName, sl.line );
ImGui::TextDisabled( "(%s) %s:%i", RealToString( l.second->timeline.size(), true ), fileName, sl.line );
if( ImGui::IsItemClicked( 1 ) )
{
if( FileExists( fileName ) )
@ -5306,7 +5306,7 @@ void View::DrawOptions()
}
else
{
m_optionsLockBuzzAnim.Enable( l.second.srcloc, 0.5f );
m_optionsLockBuzzAnim.Enable( l.second->srcloc, 0.5f );
}
}
}
@ -5322,7 +5322,7 @@ void View::DrawOptions()
{
for( const auto& l : m_worker.GetLockMap() )
{
if( l.second.threadList.size() == 1 ) Vis( &l.second ).visible = true;
if( l.second->threadList.size() == 1 ) Vis( l.second ).visible = true;
}
}
ImGui::SameLine();
@ -5330,20 +5330,20 @@ void View::DrawOptions()
{
for( const auto& l : m_worker.GetLockMap() )
{
if( l.second.threadList.size() == 1 ) Vis( &l.second ).visible = false;
if( l.second->threadList.size() == 1 ) Vis( l.second ).visible = false;
}
}
for( const auto& l : m_worker.GetLockMap() )
{
if( l.second.valid && !l.second.timeline.empty() && l.second.threadList.size() == 1 )
if( l.second->valid && !l.second->timeline.empty() && l.second->threadList.size() == 1 )
{
auto& sl = m_worker.GetSourceLocation( l.second.srcloc );
auto& sl = m_worker.GetSourceLocation( l.second->srcloc );
auto fileName = m_worker.GetString( sl.file );
char buf[1024];
sprintf( buf, "%" PRIu32 ": %s", l.first, m_worker.GetString( m_worker.GetSourceLocation( l.second.srcloc ).function ) );
ImGui::Checkbox( buf, &Vis( &l.second ).visible );
sprintf( buf, "%" PRIu32 ": %s", l.first, m_worker.GetString( m_worker.GetSourceLocation( l.second->srcloc ).function ) );
ImGui::Checkbox( buf, &Vis( l.second ).visible );
if( ImGui::IsItemHovered() )
{
m_lockHoverHighlight = l.first;
@ -5353,7 +5353,7 @@ void View::DrawOptions()
m_lockInfoWindow = l.first;
}
}
if( m_optionsLockBuzzAnim.Match( l.second.srcloc ) )
if( m_optionsLockBuzzAnim.Match( l.second->srcloc ) )
{
const auto time = m_optionsLockBuzzAnim.Time();
const auto indentVal = sin( time * 60.f ) * 10.f * time;
@ -5363,7 +5363,7 @@ void View::DrawOptions()
{
ImGui::SameLine();
}
ImGui::TextDisabled( "(%s) %s:%i", RealToString( l.second.timeline.size(), true ), fileName, sl.line );
ImGui::TextDisabled( "(%s) %s:%i", RealToString( l.second->timeline.size(), true ), fileName, sl.line );
if( ImGui::IsItemClicked( 1 ) )
{
if( FileExists( fileName ) )
@ -5372,7 +5372,7 @@ void View::DrawOptions()
}
else
{
m_optionsLockBuzzAnim.Enable( l.second.srcloc, 0.5f );
m_optionsLockBuzzAnim.Enable( l.second->srcloc, 0.5f );
}
}
}
@ -8403,7 +8403,7 @@ void View::DrawLockInfoWindow()
{
auto it = m_worker.GetLockMap().find( m_lockInfoWindow );
assert( it != m_worker.GetLockMap().end() );
const auto& lock = it->second;
const auto& lock = *it->second;
const auto& srcloc = m_worker.GetSourceLocation( lock.srcloc );
auto fileName = m_worker.GetString( srcloc.file );

View File

@ -566,7 +566,8 @@ Worker::Worker( FileRead& f, EventType::Type eventMask )
for( uint64_t i=0; i<sz; i++ )
{
s_loadProgress.subProgress.store( i, std::memory_order_relaxed );
LockMap lockmap;
auto lockmapPtr = m_slab.AllocInit<LockMap>();
auto& lockmap = *lockmapPtr;
uint32_t id;
uint64_t tsz;
f.Read( id );
@ -665,7 +666,7 @@ Worker::Worker( FileRead& f, EventType::Type eventMask )
}
}
UpdateLockCount( lockmap, 0 );
m_data.lockMap.emplace( id, std::move( lockmap ) );
m_data.lockMap.emplace( id, lockmapPtr );
}
}
else
@ -1214,6 +1215,10 @@ Worker::~Worker()
{
v->~FrameData();
}
for( auto& v : m_data.lockMap )
{
v.second->~LockMap();
}
}
uint64_t Worker::GetLockCount() const
@ -1221,7 +1226,7 @@ uint64_t Worker::GetLockCount() const
uint64_t cnt = 0;
for( auto& l : m_data.lockMap )
{
cnt += l.second.timeline.size();
cnt += l.second->timeline.size();
}
return cnt;
}
@ -2763,20 +2768,20 @@ void Worker::ProcessLockAnnounce( const QueueLockAnnounce& ev )
auto it = m_data.lockMap.find( ev.id );
if( it == m_data.lockMap.end() )
{
LockMap lm;
lm.srcloc = ShrinkSourceLocation( ev.lckloc );
lm.type = ev.type;
lm.timeAnnounce = TscTime( ev.time );
lm.timeTerminate = 0;
lm.valid = true;
m_data.lockMap.emplace( ev.id, std::move( lm ) );
auto lm = m_slab.AllocInit<LockMap>();
lm->srcloc = ShrinkSourceLocation( ev.lckloc );
lm->type = ev.type;
lm->timeAnnounce = TscTime( ev.time );
lm->timeTerminate = 0;
lm->valid = true;
m_data.lockMap.emplace( ev.id, lm );
}
else
{
it->second.srcloc = ShrinkSourceLocation( ev.lckloc );
assert( it->second.type == ev.type );
it->second.timeAnnounce = TscTime( ev.time );
it->second.valid = true;
it->second->srcloc = ShrinkSourceLocation( ev.lckloc );
assert( it->second->type == ev.type );
it->second->timeAnnounce = TscTime( ev.time );
it->second->valid = true;
}
CheckSourceLocation( ev.lckloc );
}
@ -2786,17 +2791,17 @@ void Worker::ProcessLockTerminate( const QueueLockTerminate& ev )
auto it = m_data.lockMap.find( ev.id );
if( it == m_data.lockMap.end() )
{
LockMap lm;
lm.type = ev.type;
lm.timeAnnounce = 0;
lm.timeTerminate = TscTime( ev.time );
lm.valid = false;
m_data.lockMap.emplace( ev.id, std::move( lm ) );
auto lm = m_slab.AllocInit<LockMap>();
lm->type = ev.type;
lm->timeAnnounce = 0;
lm->timeTerminate = TscTime( ev.time );
lm->valid = false;
m_data.lockMap.emplace( ev.id, lm );
}
else
{
assert( it->second.type == ev.type );
it->second.timeTerminate = TscTime( ev.time );
assert( it->second->type == ev.type );
it->second->timeTerminate = TscTime( ev.time );
}
}
@ -2805,12 +2810,12 @@ void Worker::ProcessLockWait( const QueueLockWait& ev )
auto it = m_data.lockMap.find( ev.id );
if( it == m_data.lockMap.end() )
{
LockMap lm;
lm.timeAnnounce = 0;
lm.timeTerminate = 0;
lm.valid = false;
lm.type = ev.type;
it = m_data.lockMap.emplace( ev.id, std::move( lm ) ).first;
auto lm = m_slab.AllocInit<LockMap>();
lm->timeAnnounce = 0;
lm->timeTerminate = 0;
lm->valid = false;
lm->type = ev.type;
it = m_data.lockMap.emplace( ev.id, lm ).first;
}
auto lev = ev.type == LockType::Lockable ? m_slab.Alloc<LockEvent>() : m_slab.Alloc<LockEventShared>();
@ -2818,13 +2823,14 @@ void Worker::ProcessLockWait( const QueueLockWait& ev )
lev->type = LockEvent::Type::Wait;
lev->srcloc = 0;
InsertLockEvent( it->second, lev, ev.thread );
InsertLockEvent( *it->second, lev, ev.thread );
}
void Worker::ProcessLockObtain( const QueueLockObtain& ev )
{
assert( m_data.lockMap.find( ev.id ) != m_data.lockMap.end() );
auto& lock = m_data.lockMap[ev.id];
auto it = m_data.lockMap.find( ev.id );
assert( it != m_data.lockMap.end() );
auto& lock = *it->second;
auto lev = lock.type == LockType::Lockable ? m_slab.Alloc<LockEvent>() : m_slab.Alloc<LockEventShared>();
lev->time = TscTime( ev.time );
@ -2836,8 +2842,9 @@ void Worker::ProcessLockObtain( const QueueLockObtain& ev )
void Worker::ProcessLockRelease( const QueueLockRelease& ev )
{
assert( m_data.lockMap.find( ev.id ) != m_data.lockMap.end() );
auto& lock = m_data.lockMap[ev.id];
auto it = m_data.lockMap.find( ev.id );
assert( it != m_data.lockMap.end() );
auto& lock = *it->second;
auto lev = lock.type == LockType::Lockable ? m_slab.Alloc<LockEvent>() : m_slab.Alloc<LockEventShared>();
lev->time = TscTime( ev.time );
@ -2852,10 +2859,10 @@ void Worker::ProcessLockSharedWait( const QueueLockWait& ev )
auto it = m_data.lockMap.find( ev.id );
if( it == m_data.lockMap.end() )
{
LockMap lm;
lm.valid = false;
lm.type = ev.type;
it = m_data.lockMap.emplace( ev.id, std::move( lm ) ).first;
auto lm = m_slab.AllocInit<LockMap>();
lm->valid = false;
lm->type = ev.type;
it = m_data.lockMap.emplace( ev.id, lm ).first;
}
assert( ev.type == LockType::SharedLockable );
@ -2864,13 +2871,14 @@ void Worker::ProcessLockSharedWait( const QueueLockWait& ev )
lev->type = LockEvent::Type::WaitShared;
lev->srcloc = 0;
InsertLockEvent( it->second, lev, ev.thread );
InsertLockEvent( *it->second, lev, ev.thread );
}
void Worker::ProcessLockSharedObtain( const QueueLockObtain& ev )
{
assert( m_data.lockMap.find( ev.id ) != m_data.lockMap.end() );
auto& lock = m_data.lockMap[ev.id];
auto it = m_data.lockMap.find( ev.id );
assert( it != m_data.lockMap.end() );
auto& lock = *it->second;
assert( lock.type == LockType::SharedLockable );
auto lev = m_slab.Alloc<LockEventShared>();
@ -2883,8 +2891,9 @@ void Worker::ProcessLockSharedObtain( const QueueLockObtain& ev )
void Worker::ProcessLockSharedRelease( const QueueLockRelease& ev )
{
assert( m_data.lockMap.find( ev.id ) != m_data.lockMap.end() );
auto& lock = m_data.lockMap[ev.id];
auto it = m_data.lockMap.find( ev.id );
assert( it != m_data.lockMap.end() );
auto& lock = *it->second;
assert( lock.type == LockType::SharedLockable );
auto lev = m_slab.Alloc<LockEventShared>();
@ -2900,7 +2909,7 @@ void Worker::ProcessLockMark( const QueueLockMark& ev )
CheckSourceLocation( ev.srcloc );
auto lit = m_data.lockMap.find( ev.id );
assert( lit != m_data.lockMap.end() );
auto& lockmap = lit->second;
auto& lockmap = *lit->second;
auto tid = lockmap.threadMap.find( ev.thread );
assert( tid != lockmap.threadMap.end() );
const auto thread = tid->second;
@ -3906,21 +3915,21 @@ void Worker::Write( FileWrite& f )
for( auto& v : m_data.lockMap )
{
f.Write( &v.first, sizeof( v.first ) );
f.Write( &v.second.srcloc, sizeof( v.second.srcloc ) );
f.Write( &v.second.type, sizeof( v.second.type ) );
f.Write( &v.second.valid, sizeof( v.second.valid ) );
f.Write( &v.second.timeAnnounce, sizeof( v.second.timeAnnounce ) );
f.Write( &v.second.timeTerminate, sizeof( v.second.timeTerminate ) );
sz = v.second.threadList.size();
f.Write( &v.second->srcloc, sizeof( v.second->srcloc ) );
f.Write( &v.second->type, sizeof( v.second->type ) );
f.Write( &v.second->valid, sizeof( v.second->valid ) );
f.Write( &v.second->timeAnnounce, sizeof( v.second->timeAnnounce ) );
f.Write( &v.second->timeTerminate, sizeof( v.second->timeTerminate ) );
sz = v.second->threadList.size();
f.Write( &sz, sizeof( sz ) );
for( auto& t : v.second.threadList )
for( auto& t : v.second->threadList )
{
f.Write( &t, sizeof( t ) );
}
int64_t refTime = v.second.timeAnnounce;
sz = v.second.timeline.size();
int64_t refTime = v.second->timeAnnounce;
sz = v.second->timeline.size();
f.Write( &sz, sizeof( sz ) );
for( auto& lev : v.second.timeline )
for( auto& lev : v.second->timeline )
{
WriteTimeOffset( f, refTime, lev->time );
f.Write( &lev->srcloc, sizeof( lev->srcloc ) );

View File

@ -3,7 +3,6 @@
#include <atomic>
#include <limits>
#include <map>
#include <stdexcept>
#include <string>
#include <thread>
@ -170,7 +169,7 @@ private:
flat_hash_map<CallstackFrameId, CallstackFrameData*, CallstackFrameIdHash, CallstackFrameIdCompare> callstackFrameMap;
flat_hash_map<CallstackFrameData*, CallstackFrameId, RevFrameHash, RevFrameComp> revFrameMap;
std::map<uint32_t, LockMap> lockMap;
flat_hash_map<uint32_t, LockMap*, nohash<uint32_t>> lockMap;
flat_hash_map<uint64_t, uint16_t, nohash<uint64_t>> threadMap;
Vector<uint64_t> threadExpand;
@ -260,7 +259,7 @@ public:
int64_t GetFrameEnd( const FrameData& fd, size_t idx ) const;
std::pair <int, int> GetFrameRange( const FrameData& fd, int64_t from, int64_t to );
const std::map<uint32_t, LockMap>& GetLockMap() const { return m_data.lockMap; }
const flat_hash_map<uint32_t, LockMap*, nohash<uint32_t>>& GetLockMap() const { return m_data.lockMap; }
const Vector<MessageData*>& GetMessages() const { return m_data.messages; }
const Vector<GpuCtxData*>& GetGpuData() const { return m_data.gpuData; }
const Vector<PlotData*>& GetPlots() const { return m_data.plots.Data(); }