Direct checks for context switch end validity.

This commit is contained in:
Bartosz Taudul 2020-02-10 01:26:31 +01:00
parent ae0392a0e5
commit 76afef9117
3 changed files with 14 additions and 7 deletions

View File

@ -131,6 +131,11 @@ public:
return val;
}
tracy_force_inline bool IsNonNegative() const
{
return ( m_val[5] >> 7 ) == 0;
}
private:
uint8_t m_val[6];
};
@ -355,6 +360,7 @@ struct ContextSwitchData
tracy_force_inline void SetStart( int64_t start ) { assert( start < (int64_t)( 1ull << 47 ) ); memcpy( ((char*)&_start_cpu)+2, &start, 4 ); memcpy( ((char*)&_start_cpu)+6, ((char*)&start)+4, 2 ); }
tracy_force_inline int64_t End() const { return int64_t( _end_reason_state ) >> 16; }
tracy_force_inline void SetEnd( int64_t end ) { assert( end < (int64_t)( 1ull << 47 ) ); memcpy( ((char*)&_end_reason_state)+2, &end, 4 ); memcpy( ((char*)&_end_reason_state)+6, ((char*)&end)+4, 2 ); }
tracy_force_inline bool IsEndValid() const { return ( _end_reason_state >> 63 ) == 0; }
tracy_force_inline uint8_t Cpu() const { return uint8_t( _start_cpu & 0xFF ); }
tracy_force_inline void SetCpu( uint8_t cpu ) { memcpy( &_start_cpu, &cpu, 1 ); }
tracy_force_inline int8_t Reason() const { return int8_t( (_end_reason_state >> 8) & 0xFF ); }
@ -378,6 +384,7 @@ struct ContextSwitchCpu
tracy_force_inline void SetStart( int64_t start ) { assert( start < (int64_t)( 1ull << 47 ) ); memcpy( ((char*)&_start_thread)+2, &start, 4 ); memcpy( ((char*)&_start_thread)+6, ((char*)&start)+4, 2 ); }
tracy_force_inline int64_t End() const { return _end.Val(); }
tracy_force_inline void SetEnd( int64_t end ) { assert( end < (int64_t)( 1ull << 47 ) ); _end.SetVal( end ); }
tracy_force_inline bool IsEndValid() const { return _end.IsNonNegative(); }
tracy_force_inline uint16_t Thread() const { return uint16_t( _start_thread ); }
tracy_force_inline void SetThread( uint16_t thread ) { memcpy( &_start_thread, &thread, 2 ); }

View File

@ -2664,7 +2664,7 @@ void View::DrawZones()
{
const auto& back = ctx->v.back();
first = ctx->v.begin()->Start();
last = back.End() >= 0 ? back.End() : back.Start();
last = back.IsEndValid() ? back.End() : back.Start();
}
if( !v->timeline.empty() )
{
@ -3095,7 +3095,7 @@ void View::DrawContextSwitches( const ContextSwitch* ctx, bool hover, double pxn
}
}
const auto end = ev.End() >= 0 ? ev.End() : m_worker.GetLastTime();
const auto end = ev.IsEndValid() ? ev.End() : m_worker.GetLastTime();
const auto zsz = std::max( ( end - ev.Start() ) * pxns, pxns * 0.5 );
if( zsz < MinCtxSize )
{
@ -3111,7 +3111,7 @@ void View::DrawContextSwitches( const ContextSwitch* ctx, bool hover, double pxn
if( it == prevIt ) ++it;
num += std::distance( prevIt, it );
if( it == citend ) break;
const auto nend = it->End() >= 0 ? it->End() : m_worker.GetLastTime();
const auto nend = it->IsEndValid() ? it->End() : m_worker.GetLastTime();
const auto pxnext = ( nend - m_vd.zvStart ) * pxns;
if( pxnext - px1 >= MinCtxSize * 2 ) break;
px1 = pxnext;
@ -4718,7 +4718,7 @@ int View::DrawCpuData( int offset, double pxns, const ImVec2& wpos, bool hover,
if( it == prevIt ) ++it;
num += std::distance( prevIt, it );
if( it == eit ) break;
const auto nend = it->End() >= 0 ? it->End() : m_worker.GetLastTime();
const auto nend = it->IsEndValid() ? it->End() : m_worker.GetLastTime();
const auto pxnext = ( nend - m_vd.zvStart ) * pxns;
if( pxnext - px1 >= MinVisSize * 2 ) break;
px1 = pxnext;

View File

@ -1779,7 +1779,7 @@ void Worker::GetCpuUsageAtTime( int64_t time, int& own, int& other ) const
if( !cs.empty() )
{
auto it = std::lower_bound( cs.begin(), cs.end(), time, [] ( const auto& l, const auto& r ) { return (uint64_t)l.End() < (uint64_t)r; } );
if( it != cs.end() && it->Start() <= time && it->End() >= 0 )
if( it != cs.end() && it->Start() <= time && it->IsEndValid() )
{
if( GetPidFromTid( DecompressThreadExternal( it->Thread() ) ) == m_pid )
{
@ -4766,7 +4766,7 @@ void Worker::ProcessThreadWakeup( const QueueThreadWakeup& ev )
it = m_data.ctxSwitch.emplace( ev.thread, ctx ).first;
}
auto& data = it->second->v;
if( !data.empty() && data.back().End() < 0 ) return; // wakeup of a running thread
if( !data.empty() && !data.back().IsEndValid() ) return; // wakeup of a running thread
auto& item = data.push_next();
item.SetWakeup( time );
item.SetStart( time );
@ -4989,7 +4989,7 @@ void Worker::ReconstructContextSwitchUsage()
other++;
assert( other <= cpucnt );
}
if( cpus[i].it->End() < 0 )
if( !cpus[i].it->IsEndValid() )
{
cpus[i].it++;
assert( cpus[i].it = cpus[i].end );