mirror of
https://github.com/wolfpld/tracy.git
synced 2025-03-20 07:40:02 +08:00
Preprocess CPU usage.
Things of note: Worker::GetCpuUsage() functionality was moved to TimelineItemCpuData::PreprocessCpuUsage().
This commit is contained in:
@@ -2052,88 +2052,6 @@ uint64_t Worker::GetPidFromTid( uint64_t tid ) const
|
||||
return it->second;
|
||||
}
|
||||
|
||||
void Worker::GetCpuUsage( int64_t t0, double tstep, size_t num, std::vector<std::pair<int, int>>& out )
|
||||
{
|
||||
if( out.size() < num ) out.resize( num );
|
||||
|
||||
if( t0 > m_data.lastTime || int64_t( t0 + tstep * num ) < 0 )
|
||||
{
|
||||
memset( out.data(), 0, sizeof( int ) * 2 * num );
|
||||
return;
|
||||
}
|
||||
|
||||
#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++ )
|
||||
{
|
||||
const auto time = int64_t( t0 + tstep * i );
|
||||
if( time < 0 || time > m_data.lastTime )
|
||||
{
|
||||
ptr->first = 0;
|
||||
ptr->second = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
const auto test = ( time << 16 ) | 0xFFFF;
|
||||
auto it = std::upper_bound( itBegin, 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() )
|
||||
{
|
||||
ptr->first = 0;
|
||||
ptr->second = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
--it;
|
||||
ptr->first = it->Own();
|
||||
ptr->second = it->Other();
|
||||
}
|
||||
itBegin = it;
|
||||
}
|
||||
ptr++;
|
||||
}
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
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 itBegin = cs.begin();
|
||||
auto ptr = out.data();
|
||||
for( size_t i=0; i<num; i++ )
|
||||
{
|
||||
const auto time = int64_t( t0 + tstep * i );
|
||||
if( time > m_data.lastTime ) break;
|
||||
if( time >= 0 )
|
||||
{
|
||||
auto it = std::lower_bound( itBegin, cs.end(), time, [] ( const auto& l, const auto& r ) { return (uint64_t)l.End() < (uint64_t)r; } );
|
||||
if( it == cs.end() ) break;
|
||||
if( it->IsEndValid() && it->Start() <= time )
|
||||
{
|
||||
if( GetPidFromTid( DecompressThreadExternal( it->Thread() ) ) == m_pid )
|
||||
{
|
||||
ptr->first++;
|
||||
}
|
||||
else
|
||||
{
|
||||
ptr->second++;
|
||||
}
|
||||
}
|
||||
itBegin = it;
|
||||
}
|
||||
ptr++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const ContextSwitch* const Worker::GetContextSwitchDataImpl( uint64_t thread )
|
||||
{
|
||||
auto it = m_data.ctxSwitch.find( thread );
|
||||
|
||||
Reference in New Issue
Block a user