mirror of
https://github.com/wolfpld/tracy.git
synced 2025-03-20 07:40:02 +08:00
Switch loop order for better cache locality on the slow path.
This commit is contained in:
parent
a9a16b4d94
commit
a10d71b766
@ -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 );
|
if( out.size() < num ) out.resize( num );
|
||||||
|
|
||||||
auto ptr = out.data();
|
|
||||||
#ifndef TRACY_NO_STATISTICS
|
#ifndef TRACY_NO_STATISTICS
|
||||||
if( !m_data.ctxUsage.empty() )
|
if( !m_data.ctxUsage.empty() )
|
||||||
{
|
{
|
||||||
|
auto ptr = out.data();
|
||||||
auto itBegin = m_data.ctxUsage.begin();
|
auto itBegin = m_data.ctxUsage.begin();
|
||||||
for( size_t i=0; i<num; i++ )
|
for( size_t i=0; i<num; i++ )
|
||||||
{
|
{
|
||||||
@ -2169,41 +2169,34 @@ void Worker::GetCpuUsage( int64_t t0, double tstep, size_t num, std::vector<std:
|
|||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
for( size_t i=0; i<num; i++ )
|
memset( out.data(), 0, sizeof( int ) * 2 * num );
|
||||||
|
for( int i=0; i<m_data.cpuDataCount; i++ )
|
||||||
{
|
{
|
||||||
const auto time = int64_t( t0 + tstep * i );
|
auto& cs = m_data.cpuData[i].cs;
|
||||||
if( time < 0 || time > m_data.lastTime )
|
if( !cs.empty() )
|
||||||
{
|
{
|
||||||
ptr->first = 0;
|
auto ptr = out.data();
|
||||||
ptr->second = 0;
|
for( size_t i=0; i<num; i++ )
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
int cntOwn = 0;
|
|
||||||
int cntOther = 0;
|
|
||||||
for( int i=0; i<m_data.cpuDataCount; i++ )
|
|
||||||
{
|
{
|
||||||
auto& cs = m_data.cpuData[i].cs;
|
const auto time = int64_t( t0 + tstep * i );
|
||||||
if( !cs.empty() )
|
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; } );
|
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( it != cs.end() && it->IsEndValid() && it->Start() <= time )
|
||||||
{
|
{
|
||||||
if( GetPidFromTid( DecompressThreadExternal( it->Thread() ) ) == m_pid )
|
if( GetPidFromTid( DecompressThreadExternal( it->Thread() ) ) == m_pid )
|
||||||
{
|
{
|
||||||
cntOwn++;
|
ptr->first++;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
cntOther++;
|
ptr->second++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
ptr++;
|
||||||
}
|
}
|
||||||
ptr->first = cntOwn;
|
|
||||||
ptr->second = cntOther;
|
|
||||||
}
|
}
|
||||||
ptr++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user