Select optimized path before entering loop.

This commit is contained in:
Bartosz Taudul 2021-06-20 14:22:14 +02:00
parent 5d86002f82
commit 22352dd29b
No known key found for this signature in database
GPG Key ID: B7FE2008B7575DF3

View File

@ -2134,6 +2134,9 @@ void Worker::GetCpuUsage( int64_t t0, double tstep, size_t num, std::vector<std:
if( out.size() < num ) out.resize( num ); if( out.size() < num ) out.resize( num );
auto ptr = out.data(); auto ptr = out.data();
#ifndef TRACY_NO_STATISTICS
if( !m_data.ctxUsage.empty() )
{
for( size_t i=0; i<num; i++ ) for( size_t i=0; i<num; i++ )
{ {
const auto time = int64_t( t0 + tstep * i ); const auto time = int64_t( t0 + tstep * i );
@ -2144,9 +2147,6 @@ void Worker::GetCpuUsage( int64_t t0, double tstep, size_t num, std::vector<std:
} }
else else
{ {
#ifndef TRACY_NO_STATISTICS
if( !m_data.ctxUsage.empty() )
{
const auto test = ( time << 16 ) | 0xFFFF; const auto test = ( time << 16 ) | 0xFFFF;
auto it = std::upper_bound( m_data.ctxUsage.begin(), m_data.ctxUsage.end(), test, [] ( const auto& l, const auto& r ) { return l < r._time_other_own; } ); auto it = std::upper_bound( m_data.ctxUsage.begin(), m_data.ctxUsage.end(), test, [] ( const auto& l, const auto& r ) { return l < r._time_other_own; } );
if( it == m_data.ctxUsage.begin() || it == m_data.ctxUsage.end() ) if( it == m_data.ctxUsage.begin() || it == m_data.ctxUsage.end() )
@ -2161,8 +2161,21 @@ void Worker::GetCpuUsage( int64_t t0, double tstep, size_t num, std::vector<std:
ptr->second = it->Other(); ptr->second = it->Other();
} }
} }
ptr++;
}
}
else else
#endif #endif
{
for( size_t i=0; i<num; i++ )
{
const auto time = int64_t( t0 + tstep * i );
if( time < 0 || time > m_data.lastTime )
{
ptr->first = 0;
ptr->second = 0;
}
else
{ {
int cntOwn = 0; int cntOwn = 0;
int cntOther = 0; int cntOther = 0;
@ -2188,10 +2201,10 @@ void Worker::GetCpuUsage( int64_t t0, double tstep, size_t num, std::vector<std:
ptr->first = cntOwn; ptr->first = cntOwn;
ptr->second = cntOther; ptr->second = cntOther;
} }
}
ptr++; ptr++;
} }
} }
}
const ContextSwitch* const Worker::GetContextSwitchDataImpl( uint64_t thread ) const ContextSwitch* const Worker::GetContextSwitchDataImpl( uint64_t thread )
{ {