mirror of
https://github.com/wolfpld/tracy.git
synced 2024-11-27 00:04:35 +00:00
Implement counting CPU usage (ctx switch) at a given time.
This commit is contained in:
parent
3ce6b1205f
commit
3ae5c125f6
@ -1844,6 +1844,30 @@ uint64_t Worker::GetPidFromTid( uint64_t tid ) const
|
||||
return it->second;
|
||||
}
|
||||
|
||||
void Worker::GetCpuUsageAtTime( int64_t time, int& own, int& other ) const
|
||||
{
|
||||
own = other = 0;
|
||||
for( int i=0; i<m_data.cpuDataCount; i++ )
|
||||
{
|
||||
auto& cs = m_data.cpuData[i].cs;
|
||||
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() != -1 )
|
||||
{
|
||||
if( GetPidFromTid( DecompressThreadExternal( it->Thread() ) ) == m_pid )
|
||||
{
|
||||
own++;
|
||||
}
|
||||
else
|
||||
{
|
||||
other++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const ContextSwitch* const Worker::GetContextSwitchDataImpl( uint64_t thread )
|
||||
{
|
||||
auto it = m_data.ctxSwitch.find( thread );
|
||||
|
@ -309,6 +309,7 @@ public:
|
||||
int GetCpuDataCpuCount() const { return m_data.cpuDataCount; }
|
||||
uint64_t GetPidFromTid( uint64_t tid ) const;
|
||||
const flat_hash_map<uint64_t, CpuThreadData, nohash<uint64_t>>& GetCpuThreadData() const { return m_data.cpuThreadData; }
|
||||
void GetCpuUsageAtTime( int64_t time, int& own, int& other ) const;
|
||||
|
||||
int64_t GetFrameTime( const FrameData& fd, size_t idx ) const;
|
||||
int64_t GetFrameBegin( const FrameData& fd, size_t idx ) const;
|
||||
|
Loading…
Reference in New Issue
Block a user