From d1789f1e3a83be7c8c4f768ec7828378ea023eb5 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Sat, 28 Oct 2017 14:08:10 +0200 Subject: [PATCH] Stay in fast loop until there's something to draw. --- server/TracyView.cpp | 312 +++++++++++++++++++++---------------------- 1 file changed, 154 insertions(+), 158 deletions(-) diff --git a/server/TracyView.cpp b/server/TracyView.cpp index eccab335..57138552 100644 --- a/server/TracyView.cpp +++ b/server/TracyView.cpp @@ -2308,180 +2308,176 @@ int View::DrawLocks( uint64_t tid, bool hover, double pxns, const ImVec2& wpos, while( vbegin < vend ) { - if( state == LockState::Nothing ) + if( state == LockState::Nothing || ( m_onlyContendedLocks && state == LockState::HasLock ) ) { - LockState nextState; do { - vbegin = GetNextLockEvent( vbegin, vend, state, nextState, thread ); + vbegin = GetNextLockEvent( vbegin, vend, state, state, thread ); } - while( nextState == LockState::Nothing && vbegin < vend ); - if( nextState == LockState::Nothing ) break; - state = nextState; + while( vbegin < vend && ( state == LockState::Nothing || ( m_onlyContendedLocks && state == LockState::HasLock ) ) ); + if( vbegin >= vend ) break; + state = state; } LockState nextState; auto next = GetNextLockEvent( vbegin, vend, state, nextState, thread ); - assert( state != LockState::Nothing ); - if( !m_onlyContendedLocks || state != LockState::HasLock ) + assert( state != LockState::Nothing && ( !m_onlyContendedLocks || state != LockState::HasLock ) ); + drawn = true; + const auto t0 = (*vbegin)->time; + const auto t1 = next == tl.end() ? GetLastTime() : (*next)->time; + const auto px0 = ( t0 - m_zvStart ) * pxns; + const auto px1 = ( t1 - m_zvStart ) * pxns; + + bool itemHovered = hover && ImGui::IsMouseHoveringRect( wpos + ImVec2( std::max( px0, -10.0 ), offset ), wpos + ImVec2( std::min( px1, double( w + 10 ) ), offset + ty ) ); + if( itemHovered ) { - drawn = true; - const auto t0 = (*vbegin)->time; - const auto t1 = next == tl.end() ? GetLastTime() : (*next)->time; - const auto px0 = ( t0 - m_zvStart ) * pxns; - const auto px1 = ( t1 - m_zvStart ) * pxns; - - bool itemHovered = hover && ImGui::IsMouseHoveringRect( wpos + ImVec2( std::max( px0, -10.0 ), offset ), wpos + ImVec2( std::min( px1, double( w + 10 ) ), offset + ty ) ); - if( itemHovered ) + highlight.blocked = state == LockState::HasBlockingLock; + if( !highlight.blocked ) { - highlight.blocked = state == LockState::HasBlockingLock; - if( !highlight.blocked ) - { - highlight.id = v.first; - highlight.begin = t0; - highlight.end = t1; - highlight.thread = thread; - highlight.blocked = false; - } - else - { - auto b = vbegin; - while( b != tl.begin() ) - { - if( (*b)->lockingThread != (*vbegin)->lockingThread ) - { - break; - } - b--; - } - b++; - highlight.begin = (*b)->time; - - auto e = next; - while( e != tl.end() ) - { - if( (*e)->lockingThread != (*next)->lockingThread ) - { - highlight.id = v.first; - highlight.end = (*e)->time; - highlight.thread = thread; - break; - } - e++; - } - } - - ImGui::BeginTooltip(); - ImGui::Text( "Lock #%" PRIu64, v.first ); - ImGui::Text( "%s", GetString( srcloc.function ) ); - ImGui::Text( "%s:%i", GetString( srcloc.file ), srcloc.line ); - ImGui::Text( "Time: %s", TimeToString( t1 - t0 ) ); - ImGui::Separator(); - - uint64_t markloc = 0; - auto it = vbegin; - for(;;) - { - if( (*it)->thread == thread ) - { - if( ( (*it)->lockingThread == thread || IsThreadWaiting( (*it)->waitList, thread ) ) && (*it)->srcloc != 0 ) - { - markloc = (*it)->srcloc; - break; - } - } - if( it == tl.begin() ) break; - --it; - } - if( markloc != 0 ) - { - auto& marklocdata = GetSourceLocation( markloc ); - ImGui::Text( "Lock event location:" ); - ImGui::Text( "%s", GetString( marklocdata.function ) ); - ImGui::Text( "%s:%i", GetString( marklocdata.file ), marklocdata.line ); - ImGui::Separator(); - } - - switch( state ) - { - case LockState::HasLock: - if( (*vbegin)->lockCount == 1 ) - { - ImGui::Text( "Thread \"%s\" has lock. No other threads are waiting.", GetThreadString( tid ) ); - } - else - { - ImGui::Text( "Thread \"%s\" has %i locks. No other threads are waiting.", GetThreadString( tid ), (*vbegin)->lockCount ); - } - if( (*vbegin)->waitList != 0 ) - { - assert( !AreOtherWaiting( (*next)->waitList, thread ) ); - ImGui::Text( "Recursive lock acquire in thread." ); - } - break; - case LockState::HasBlockingLock: - { - if( (*vbegin)->lockCount == 1 ) - { - ImGui::Text( "Thread \"%s\" has lock. Blocked threads (%i):", GetThreadString( tid ), CountBits( (*vbegin)->waitList ) ); - } - else - { - ImGui::Text( "Thread \"%s\" has %i locks. Blocked threads (%i):", GetThreadString( tid ), (*vbegin)->lockCount, CountBits( (*vbegin)->waitList ) ); - } - auto waitList = (*vbegin)->waitList; - int t = 0; - while( waitList != 0 ) - { - if( waitList & 0x1 ) - { - ImGui::Text( "\"%s\"", GetThreadString( lockmap.threadList[t] ) ); - } - waitList >>= 1; - t++; - } - break; - } - case LockState::WaitLock: - { - ImGui::Text( "Thread \"%s\" is blocked by other thread:", GetThreadString( tid ) ); - ImGui::Text( "\"%s\"", GetThreadString( lockmap.threadList[(*vbegin)->lockingThread] ) ); - break; - } - default: - assert( false ); - break; - } - ImGui::EndTooltip(); - } - - const auto cfilled = state == LockState::HasLock ? 0xFF228A22 : ( state == LockState::HasBlockingLock ? 0xFF228A8A : 0xFF2222BD ); - draw->AddRectFilled( wpos + ImVec2( std::max( px0, -10.0 ), offset ), wpos + ImVec2( std::min( px1, double( w + 10 ) ), offset + ty ), cfilled, 2.f ); - if( m_lockHighlight.thread != thread && ( state == LockState::HasBlockingLock ) != m_lockHighlight.blocked && next != tl.end() && m_lockHighlight.id == v.first && m_lockHighlight.begin <= (*vbegin)->time && m_lockHighlight.end >= (*next)->time ) - { - const auto t = uint8_t( ( sin( std::chrono::duration_cast( std::chrono::system_clock::now().time_since_epoch() ).count() * 0.01 ) * 0.5 + 0.5 ) * 255 ); - draw->AddRect( wpos + ImVec2( std::max( px0, -10.0 ), offset ), wpos + ImVec2( std::min( px1, double( w + 10 ) ), offset + ty ), 0x00FFFFFF | ( t << 24 ), 2.f, -1, 2.f ); + highlight.id = v.first; + highlight.begin = t0; + highlight.end = t1; + highlight.thread = thread; + highlight.blocked = false; } else { - const auto coutline = state == LockState::HasLock ? 0xFF3BA33B : ( state == LockState::HasBlockingLock ? 0xFF3BA3A3 : 0xFF3B3BD6 ); - draw->AddRect( wpos + ImVec2( std::max( px0, -10.0 ), offset ), wpos + ImVec2( std::min( px1, double( w + 10 ) ), offset + ty ), coutline, 2.f ); - } - if( dsz >= MinVisSize ) - { - draw->AddRectFilled( wpos + ImVec2( px0, offset ), wpos + ImVec2( std::min( px0+dsz, px1 ), offset + ty ), 0x882222DD, 2.f ); - } - if( rsz >= MinVisSize ) - { - draw->AddLine( wpos + ImVec2( px0 + rsz, offset + ty/2 ), wpos + ImVec2( px0 - rsz, offset + ty/2 ), 0xAAFFFFFF ); - draw->AddLine( wpos + ImVec2( px0 + rsz, offset + ty/4 ), wpos + ImVec2( px0 + rsz, offset + 3*ty/4 ), 0xAAFFFFFF ); - draw->AddLine( wpos + ImVec2( px0 - rsz, offset + ty/4 ), wpos + ImVec2( px0 - rsz, offset + 3*ty/4 ), 0xAAFFFFFF ); + auto b = vbegin; + while( b != tl.begin() ) + { + if( (*b)->lockingThread != (*vbegin)->lockingThread ) + { + break; + } + b--; + } + b++; + highlight.begin = (*b)->time; - draw->AddLine( wpos + ImVec2( px1 + rsz, offset + ty/2 ), wpos + ImVec2( px1 - rsz, offset + ty/2 ), 0xAAFFFFFF ); - draw->AddLine( wpos + ImVec2( px1 + rsz, offset + ty/4 ), wpos + ImVec2( px1 + rsz, offset + 3*ty/4 ), 0xAAFFFFFF ); - draw->AddLine( wpos + ImVec2( px1 - rsz, offset + ty/4 ), wpos + ImVec2( px1 - rsz, offset + 3*ty/4 ), 0xAAFFFFFF ); + auto e = next; + while( e != tl.end() ) + { + if( (*e)->lockingThread != (*next)->lockingThread ) + { + highlight.id = v.first; + highlight.end = (*e)->time; + highlight.thread = thread; + break; + } + e++; + } } + + ImGui::BeginTooltip(); + ImGui::Text( "Lock #%" PRIu64, v.first ); + ImGui::Text( "%s", GetString( srcloc.function ) ); + ImGui::Text( "%s:%i", GetString( srcloc.file ), srcloc.line ); + ImGui::Text( "Time: %s", TimeToString( t1 - t0 ) ); + ImGui::Separator(); + + uint64_t markloc = 0; + auto it = vbegin; + for(;;) + { + if( (*it)->thread == thread ) + { + if( ( (*it)->lockingThread == thread || IsThreadWaiting( (*it)->waitList, thread ) ) && (*it)->srcloc != 0 ) + { + markloc = (*it)->srcloc; + break; + } + } + if( it == tl.begin() ) break; + --it; + } + if( markloc != 0 ) + { + auto& marklocdata = GetSourceLocation( markloc ); + ImGui::Text( "Lock event location:" ); + ImGui::Text( "%s", GetString( marklocdata.function ) ); + ImGui::Text( "%s:%i", GetString( marklocdata.file ), marklocdata.line ); + ImGui::Separator(); + } + + switch( state ) + { + case LockState::HasLock: + if( (*vbegin)->lockCount == 1 ) + { + ImGui::Text( "Thread \"%s\" has lock. No other threads are waiting.", GetThreadString( tid ) ); + } + else + { + ImGui::Text( "Thread \"%s\" has %i locks. No other threads are waiting.", GetThreadString( tid ), (*vbegin)->lockCount ); + } + if( (*vbegin)->waitList != 0 ) + { + assert( !AreOtherWaiting( (*next)->waitList, thread ) ); + ImGui::Text( "Recursive lock acquire in thread." ); + } + break; + case LockState::HasBlockingLock: + { + if( (*vbegin)->lockCount == 1 ) + { + ImGui::Text( "Thread \"%s\" has lock. Blocked threads (%i):", GetThreadString( tid ), CountBits( (*vbegin)->waitList ) ); + } + else + { + ImGui::Text( "Thread \"%s\" has %i locks. Blocked threads (%i):", GetThreadString( tid ), (*vbegin)->lockCount, CountBits( (*vbegin)->waitList ) ); + } + auto waitList = (*vbegin)->waitList; + int t = 0; + while( waitList != 0 ) + { + if( waitList & 0x1 ) + { + ImGui::Text( "\"%s\"", GetThreadString( lockmap.threadList[t] ) ); + } + waitList >>= 1; + t++; + } + break; + } + case LockState::WaitLock: + { + ImGui::Text( "Thread \"%s\" is blocked by other thread:", GetThreadString( tid ) ); + ImGui::Text( "\"%s\"", GetThreadString( lockmap.threadList[(*vbegin)->lockingThread] ) ); + break; + } + default: + assert( false ); + break; + } + ImGui::EndTooltip(); + } + + const auto cfilled = state == LockState::HasLock ? 0xFF228A22 : ( state == LockState::HasBlockingLock ? 0xFF228A8A : 0xFF2222BD ); + draw->AddRectFilled( wpos + ImVec2( std::max( px0, -10.0 ), offset ), wpos + ImVec2( std::min( px1, double( w + 10 ) ), offset + ty ), cfilled, 2.f ); + if( m_lockHighlight.thread != thread && ( state == LockState::HasBlockingLock ) != m_lockHighlight.blocked && next != tl.end() && m_lockHighlight.id == v.first && m_lockHighlight.begin <= (*vbegin)->time && m_lockHighlight.end >= (*next)->time ) + { + const auto t = uint8_t( ( sin( std::chrono::duration_cast( std::chrono::system_clock::now().time_since_epoch() ).count() * 0.01 ) * 0.5 + 0.5 ) * 255 ); + draw->AddRect( wpos + ImVec2( std::max( px0, -10.0 ), offset ), wpos + ImVec2( std::min( px1, double( w + 10 ) ), offset + ty ), 0x00FFFFFF | ( t << 24 ), 2.f, -1, 2.f ); + } + else + { + const auto coutline = state == LockState::HasLock ? 0xFF3BA33B : ( state == LockState::HasBlockingLock ? 0xFF3BA3A3 : 0xFF3B3BD6 ); + draw->AddRect( wpos + ImVec2( std::max( px0, -10.0 ), offset ), wpos + ImVec2( std::min( px1, double( w + 10 ) ), offset + ty ), coutline, 2.f ); + } + if( dsz >= MinVisSize ) + { + draw->AddRectFilled( wpos + ImVec2( px0, offset ), wpos + ImVec2( std::min( px0+dsz, px1 ), offset + ty ), 0x882222DD, 2.f ); + } + if( rsz >= MinVisSize ) + { + draw->AddLine( wpos + ImVec2( px0 + rsz, offset + ty/2 ), wpos + ImVec2( px0 - rsz, offset + ty/2 ), 0xAAFFFFFF ); + draw->AddLine( wpos + ImVec2( px0 + rsz, offset + ty/4 ), wpos + ImVec2( px0 + rsz, offset + 3*ty/4 ), 0xAAFFFFFF ); + draw->AddLine( wpos + ImVec2( px0 - rsz, offset + ty/4 ), wpos + ImVec2( px0 - rsz, offset + 3*ty/4 ), 0xAAFFFFFF ); + + draw->AddLine( wpos + ImVec2( px1 + rsz, offset + ty/2 ), wpos + ImVec2( px1 - rsz, offset + ty/2 ), 0xAAFFFFFF ); + draw->AddLine( wpos + ImVec2( px1 + rsz, offset + ty/4 ), wpos + ImVec2( px1 + rsz, offset + 3*ty/4 ), 0xAAFFFFFF ); + draw->AddLine( wpos + ImVec2( px1 - rsz, offset + ty/4 ), wpos + ImVec2( px1 - rsz, offset + 3*ty/4 ), 0xAAFFFFFF ); } vbegin = next;