Reintroduce lock announce events.

This commit is contained in:
Bartosz Taudul 2017-12-10 21:37:39 +01:00
parent ea604d484d
commit 3567d7edd8
5 changed files with 68 additions and 16 deletions

View File

@ -18,9 +18,18 @@ class Lockable
public: public:
tracy_force_inline Lockable( const SourceLocation* srcloc ) tracy_force_inline Lockable( const SourceLocation* srcloc )
: m_id( s_lockCounter.fetch_add( 1, std::memory_order_relaxed ) ) : m_id( s_lockCounter.fetch_add( 1, std::memory_order_relaxed ) )
, m_lckloc( (uint64_t)srcloc )
{ {
assert( m_id != std::numeric_limits<uint32_t>::max() ); assert( m_id != std::numeric_limits<uint32_t>::max() );
Magic magic;
auto& token = s_token.ptr;
auto& tail = token->get_tail_index();
auto item = token->enqueue_begin<moodycamel::CanAlloc>( magic );
item->hdr.type = QueueType::LockAnnounce;
item->lockAnnounce.id = m_id;
item->lockAnnounce.lckloc = (uint64_t)srcloc;
item->lockAnnounce.type = LockType::Lockable;
tail.store( magic + 1, std::memory_order_release );
} }
Lockable( const Lockable& ) = delete; Lockable( const Lockable& ) = delete;
@ -38,7 +47,6 @@ public:
item->lockWait.id = m_id; item->lockWait.id = m_id;
item->lockWait.thread = thread; item->lockWait.thread = thread;
item->lockWait.time = Profiler::GetTime(); item->lockWait.time = Profiler::GetTime();
item->lockWait.lckloc = m_lckloc;
tail.store( magic + 1, std::memory_order_release ); tail.store( magic + 1, std::memory_order_release );
} }
@ -106,7 +114,6 @@ public:
private: private:
T m_lockable; T m_lockable;
uint32_t m_id; uint32_t m_id;
uint64_t m_lckloc;
}; };
}; };

View File

@ -16,6 +16,7 @@ enum class QueueType : uint8_t
ZoneEnd, ZoneEnd,
FrameMarkMsg, FrameMarkMsg,
SourceLocation, SourceLocation,
LockAnnounce,
LockWait, LockWait,
LockObtain, LockObtain,
LockRelease, LockRelease,
@ -79,12 +80,23 @@ struct QueueZoneText
uint64_t text; // ptr uint64_t text; // ptr
}; };
enum class LockType : uint8_t
{
Lockable
};
struct QueueLockAnnounce
{
uint32_t id;
uint64_t lckloc; // ptr
LockType type;
};
struct QueueLockWait struct QueueLockWait
{ {
uint32_t id; uint32_t id;
int64_t time; int64_t time;
uint64_t thread; uint64_t thread;
uint64_t lckloc; // ptr
}; };
struct QueueLockObtain struct QueueLockObtain
@ -190,6 +202,7 @@ struct QueueItem
QueueFrameMark frameMark; QueueFrameMark frameMark;
QueueSourceLocation srcloc; QueueSourceLocation srcloc;
QueueZoneText zoneText; QueueZoneText zoneText;
QueueLockAnnounce lockAnnounce;
QueueLockWait lockWait; QueueLockWait lockWait;
QueueLockObtain lockObtain; QueueLockObtain lockObtain;
QueueLockRelease lockRelease; QueueLockRelease lockRelease;
@ -218,6 +231,7 @@ static const size_t QueueDataSize[] = {
sizeof( QueueHeader ) + sizeof( QueueZoneEnd ), sizeof( QueueHeader ) + sizeof( QueueZoneEnd ),
sizeof( QueueHeader ) + sizeof( QueueFrameMark ), sizeof( QueueHeader ) + sizeof( QueueFrameMark ),
sizeof( QueueHeader ) + sizeof( QueueSourceLocation ), sizeof( QueueHeader ) + sizeof( QueueSourceLocation ),
sizeof( QueueHeader ) + sizeof( QueueLockAnnounce ),
sizeof( QueueHeader ) + sizeof( QueueLockWait ), sizeof( QueueHeader ) + sizeof( QueueLockWait ),
sizeof( QueueHeader ) + sizeof( QueueLockObtain ), sizeof( QueueHeader ) + sizeof( QueueLockObtain ),
sizeof( QueueHeader ) + sizeof( QueueLockRelease ), sizeof( QueueHeader ) + sizeof( QueueLockRelease ),

View File

@ -177,7 +177,9 @@ struct LockMap
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;
LockType type;
bool visible; bool visible;
bool valid;
}; };
struct LockHighlight struct LockHighlight

View File

@ -296,6 +296,8 @@ View::View( FileRead& f )
uint64_t tsz; uint64_t tsz;
f.Read( &id, sizeof( id ) ); f.Read( &id, sizeof( id ) );
f.Read( &lockmap.srcloc, sizeof( lockmap.srcloc ) ); f.Read( &lockmap.srcloc, sizeof( lockmap.srcloc ) );
f.Read( &lockmap.type, sizeof( lockmap.type ) );
f.Read( &lockmap.valid, sizeof( lockmap.valid ) );
f.Read( &tsz, sizeof( tsz ) ); f.Read( &tsz, sizeof( tsz ) );
for( uint64_t i=0; i<tsz; i++ ) for( uint64_t i=0; i<tsz; i++ )
{ {
@ -588,6 +590,9 @@ void View::Process( const QueueItem& ev )
case QueueType::ZoneText: case QueueType::ZoneText:
ProcessZoneText( ev.zoneText ); ProcessZoneText( ev.zoneText );
break; break;
case QueueType::LockAnnounce:
ProcessLockAnnounce( ev.lockAnnounce );
break;
case QueueType::LockWait: case QueueType::LockWait:
ProcessLockWait( ev.lockWait ); ProcessLockWait( ev.lockWait );
break; break;
@ -713,6 +718,28 @@ void View::ProcessZoneText( const QueueZoneText& ev )
m_pendingCustomStrings.erase( it ); m_pendingCustomStrings.erase( it );
} }
void View::ProcessLockAnnounce( const QueueLockAnnounce& ev )
{
auto it = m_lockMap.find( ev.id );
if( it == m_lockMap.end() )
{
LockMap lm;
lm.srcloc = ShrinkSourceLocation( ev.lckloc );
lm.type = ev.type;
lm.visible = true;
lm.valid = true;
m_lockMap.emplace( ev.id, std::move( lm ) );
}
else
{
it->second.srcloc = ShrinkSourceLocation( ev.lckloc );
it->second.type = ev.type;
it->second.visible = true;
it->second.valid = true;
}
CheckSourceLocation( ev.lckloc );
}
void View::ProcessLockWait( const QueueLockWait& ev ) void View::ProcessLockWait( const QueueLockWait& ev )
{ {
auto lev = m_slab.Alloc<LockEvent>(); auto lev = m_slab.Alloc<LockEvent>();
@ -724,16 +751,10 @@ void View::ProcessLockWait( const QueueLockWait& ev )
if( it == m_lockMap.end() ) if( it == m_lockMap.end() )
{ {
LockMap lm; LockMap lm;
lm.srcloc = ShrinkSourceLocation( ev.lckloc ); lm.valid = false;
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 );
}
else if( it->second.srcloc == 0 )
{
it->second.srcloc = ShrinkSourceLocation( ev.lckloc );
CheckSourceLocation( ev.lckloc );
} }
InsertLockEvent( it->second, lev, ev.thread ); InsertLockEvent( it->second, lev, ev.thread );
} }
@ -744,6 +765,7 @@ void View::ProcessLockObtain( const QueueLockObtain& ev )
lev->type = (uint8_t)LockEvent::Type::Obtain; lev->type = (uint8_t)LockEvent::Type::Obtain;
lev->srcloc = 0; lev->srcloc = 0;
assert( m_lockMap.find( ev.id ) != m_lockMap.end() );
InsertLockEvent( m_lockMap[ev.id], lev, ev.thread ); InsertLockEvent( m_lockMap[ev.id], lev, ev.thread );
} }
@ -754,6 +776,7 @@ void View::ProcessLockRelease( const QueueLockRelease& ev )
lev->type = (uint8_t)LockEvent::Type::Release; lev->type = (uint8_t)LockEvent::Type::Release;
lev->srcloc = 0; lev->srcloc = 0;
assert( m_lockMap.find( ev.id ) != m_lockMap.end() );
InsertLockEvent( m_lockMap[ev.id], lev, ev.thread ); InsertLockEvent( m_lockMap[ev.id], lev, ev.thread );
} }
@ -2859,7 +2882,7 @@ int View::DrawLocks( uint64_t tid, bool hover, double pxns, const ImVec2& wpos,
for( auto& v : m_lockMap ) for( auto& v : m_lockMap )
{ {
auto& lockmap = v.second; auto& lockmap = v.second;
if( !lockmap.visible ) continue; if( !lockmap.visible || !lockmap.valid ) continue;
auto it = lockmap.threadMap.find( tid ); auto it = lockmap.threadMap.find( tid );
if( it == lockmap.threadMap.end() ) continue; if( it == lockmap.threadMap.end() ) continue;
@ -3596,11 +3619,14 @@ void View::DrawOptions()
ImGui::Checkbox( "Only contended", &m_onlyContendedLocks ); ImGui::Checkbox( "Only contended", &m_onlyContendedLocks );
ImGui::Indent( tw ); ImGui::Indent( tw );
for( auto& l : m_lockMap ) for( auto& l : m_lockMap )
{
if( l.second.valid )
{ {
char buf[1024]; char buf[1024];
sprintf( buf, "%" PRIu32 ": %s", l.first, GetString( GetSourceLocation( l.second.srcloc ).function ) ); sprintf( buf, "%" PRIu32 ": %s", l.first, GetString( GetSourceLocation( l.second.srcloc ).function ) );
ImGui::Checkbox( buf , &l.second.visible ); ImGui::Checkbox( buf , &l.second.visible );
} }
}
ImGui::Unindent( tw ); ImGui::Unindent( tw );
ImGui::Separator(); ImGui::Separator();
ImGui::Checkbox( "Draw plots", &m_drawPlots ); ImGui::Checkbox( "Draw plots", &m_drawPlots );
@ -3951,6 +3977,8 @@ void View::Write( FileWrite& f )
{ {
f.Write( &v.first, sizeof( v.first ) ); f.Write( &v.first, sizeof( v.first ) );
f.Write( &v.second.srcloc, sizeof( v.second.srcloc ) ); 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 ) );
sz = v.second.threadList.size(); sz = v.second.threadList.size();
f.Write( &sz, sizeof( sz ) ); f.Write( &sz, sizeof( sz ) );
for( auto& t : v.second.threadList ) for( auto& t : v.second.threadList )

View File

@ -74,6 +74,7 @@ private:
tracy_force_inline void ProcessZoneEnd( const QueueZoneEnd& ev ); tracy_force_inline void ProcessZoneEnd( const QueueZoneEnd& ev );
tracy_force_inline void ProcessFrameMark( const QueueFrameMark& ev ); tracy_force_inline void ProcessFrameMark( const QueueFrameMark& ev );
tracy_force_inline void ProcessZoneText( const QueueZoneText& ev ); tracy_force_inline void ProcessZoneText( const QueueZoneText& ev );
tracy_force_inline void ProcessLockAnnounce( const QueueLockAnnounce& ev );
tracy_force_inline void ProcessLockWait( const QueueLockWait& ev ); tracy_force_inline void ProcessLockWait( const QueueLockWait& ev );
tracy_force_inline void ProcessLockObtain( const QueueLockObtain& ev ); tracy_force_inline void ProcessLockObtain( const QueueLockObtain& ev );
tracy_force_inline void ProcessLockRelease( const QueueLockRelease& ev ); tracy_force_inline void ProcessLockRelease( const QueueLockRelease& ev );