mirror of
https://github.com/wolfpld/tracy.git
synced 2024-11-10 10:41:50 +00:00
Stay in fast loop until there's something to draw.
This commit is contained in:
parent
257f9818ed
commit
d1789f1e3a
@ -2308,180 +2308,176 @@ int View::DrawLocks( uint64_t tid, bool hover, double pxns, const ImVec2& wpos,
|
|||||||
|
|
||||||
while( vbegin < vend )
|
while( vbegin < vend )
|
||||||
{
|
{
|
||||||
if( state == LockState::Nothing )
|
if( state == LockState::Nothing || ( m_onlyContendedLocks && state == LockState::HasLock ) )
|
||||||
{
|
{
|
||||||
LockState nextState;
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
vbegin = GetNextLockEvent( vbegin, vend, state, nextState, thread );
|
vbegin = GetNextLockEvent( vbegin, vend, state, state, thread );
|
||||||
}
|
}
|
||||||
while( nextState == LockState::Nothing && vbegin < vend );
|
while( vbegin < vend && ( state == LockState::Nothing || ( m_onlyContendedLocks && state == LockState::HasLock ) ) );
|
||||||
if( nextState == LockState::Nothing ) break;
|
if( vbegin >= vend ) break;
|
||||||
state = nextState;
|
state = state;
|
||||||
}
|
}
|
||||||
|
|
||||||
LockState nextState;
|
LockState nextState;
|
||||||
auto next = GetNextLockEvent( vbegin, vend, state, nextState, thread );
|
auto next = GetNextLockEvent( vbegin, vend, state, nextState, thread );
|
||||||
|
|
||||||
assert( state != LockState::Nothing );
|
assert( state != LockState::Nothing && ( !m_onlyContendedLocks || state != LockState::HasLock ) );
|
||||||
if( !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;
|
highlight.blocked = state == LockState::HasBlockingLock;
|
||||||
const auto t0 = (*vbegin)->time;
|
if( !highlight.blocked )
|
||||||
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;
|
highlight.id = v.first;
|
||||||
if( !highlight.blocked )
|
highlight.begin = t0;
|
||||||
{
|
highlight.end = t1;
|
||||||
highlight.id = v.first;
|
highlight.thread = thread;
|
||||||
highlight.begin = t0;
|
highlight.blocked = false;
|
||||||
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::milliseconds>( 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
|
else
|
||||||
{
|
{
|
||||||
const auto coutline = state == LockState::HasLock ? 0xFF3BA33B : ( state == LockState::HasBlockingLock ? 0xFF3BA3A3 : 0xFF3B3BD6 );
|
auto b = vbegin;
|
||||||
draw->AddRect( wpos + ImVec2( std::max( px0, -10.0 ), offset ), wpos + ImVec2( std::min( px1, double( w + 10 ) ), offset + ty ), coutline, 2.f );
|
while( b != tl.begin() )
|
||||||
}
|
{
|
||||||
if( dsz >= MinVisSize )
|
if( (*b)->lockingThread != (*vbegin)->lockingThread )
|
||||||
{
|
{
|
||||||
draw->AddRectFilled( wpos + ImVec2( px0, offset ), wpos + ImVec2( std::min( px0+dsz, px1 ), offset + ty ), 0x882222DD, 2.f );
|
break;
|
||||||
}
|
}
|
||||||
if( rsz >= MinVisSize )
|
b--;
|
||||||
{
|
}
|
||||||
draw->AddLine( wpos + ImVec2( px0 + rsz, offset + ty/2 ), wpos + ImVec2( px0 - rsz, offset + ty/2 ), 0xAAFFFFFF );
|
b++;
|
||||||
draw->AddLine( wpos + ImVec2( px0 + rsz, offset + ty/4 ), wpos + ImVec2( px0 + rsz, offset + 3*ty/4 ), 0xAAFFFFFF );
|
highlight.begin = (*b)->time;
|
||||||
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 );
|
auto e = next;
|
||||||
draw->AddLine( wpos + ImVec2( px1 + rsz, offset + ty/4 ), wpos + ImVec2( px1 + rsz, offset + 3*ty/4 ), 0xAAFFFFFF );
|
while( e != tl.end() )
|
||||||
draw->AddLine( wpos + ImVec2( px1 - rsz, offset + ty/4 ), wpos + ImVec2( px1 - rsz, offset + 3*ty/4 ), 0xAAFFFFFF );
|
{
|
||||||
|
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::milliseconds>( 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;
|
vbegin = next;
|
||||||
|
Loading…
Reference in New Issue
Block a user