Switch loop order for better cache locality on the slow path.

This commit is contained in:
Bartosz Taudul 2021-06-20 14:30:43 +02:00
parent a9a16b4d94
commit a10d71b766
No known key found for this signature in database
GPG Key ID: B7FE2008B7575DF3

View File

@ -2133,10 +2133,10 @@ void Worker::GetCpuUsage( int64_t t0, double tstep, size_t num, std::vector<std:
{
if( out.size() < num ) out.resize( num );
auto ptr = out.data();
#ifndef TRACY_NO_STATISTICS
if( !m_data.ctxUsage.empty() )
{
auto ptr = out.data();
auto itBegin = m_data.ctxUsage.begin();
for( size_t i=0; i<num; i++ )
{
@ -2169,43 +2169,36 @@ void Worker::GetCpuUsage( int64_t t0, double tstep, size_t num, std::vector<std:
else
#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 cntOther = 0;
memset( out.data(), 0, sizeof( int ) * 2 * num );
for( int i=0; i<m_data.cpuDataCount; i++ )
{
auto& cs = m_data.cpuData[i].cs;
if( !cs.empty() )
{
auto ptr = out.data();
for( size_t i=0; i<num; i++ )
{
const auto time = int64_t( t0 + tstep * i );
if( time >= 0 && time <= m_data.lastTime )
{
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->IsEndValid() && it->Start() <= time )
{
if( GetPidFromTid( DecompressThreadExternal( it->Thread() ) ) == m_pid )
{
cntOwn++;
ptr->first++;
}
else
{
cntOther++;
ptr->second++;
}
}
}
}
ptr->first = cntOwn;
ptr->second = cntOther;
}
ptr++;
}
}
}
}
}
const ContextSwitch* const Worker::GetContextSwitchDataImpl( uint64_t thread )