Calculate cpu thread data statistics.

This commit is contained in:
Bartosz Taudul 2019-08-18 01:50:49 +02:00
parent 1498417a8d
commit 103645c2fa
3 changed files with 37 additions and 1 deletions

View File

@ -442,6 +442,13 @@ struct CpuData
Vector<ContextSwitchCpu> cs; Vector<ContextSwitchCpu> cs;
}; };
struct CpuThreadData
{
int64_t runningTime = 0;
uint32_t runningRegions = 0;
uint32_t migrations = 0;
};
} }
#endif #endif

View File

@ -4138,7 +4138,16 @@ void Worker::ProcessContextSwitch( const QueueContextSwitch& ev )
item.SetReason( ev.reason ); item.SetReason( ev.reason );
item.SetState( ev.state ); item.SetState( ev.state );
it->second->runningTime += time - item.Start(); const auto dt = time - item.Start();
it->second->runningTime += dt;
auto tdit = m_data.cpuThreadData.find( ev.oldThread );
if( tdit == m_data.cpuThreadData.end() )
{
tdit = m_data.cpuThreadData.emplace( ev.oldThread, CpuThreadData {} ).first;
}
tdit->second.runningRegions++;
tdit->second.runningTime += dt;
} }
if( !cs.empty() ) if( !cs.empty() )
{ {
@ -4157,13 +4166,22 @@ void Worker::ProcessContextSwitch( const QueueContextSwitch& ev )
} }
auto& data = it->second->v; auto& data = it->second->v;
ContextSwitchData* item = nullptr; ContextSwitchData* item = nullptr;
bool migration = false;
if( !data.empty() && data.back().Reason() == ContextSwitchData::Wakeup ) if( !data.empty() && data.back().Reason() == ContextSwitchData::Wakeup )
{ {
item = &data.back(); item = &data.back();
if( data.size() > 1 )
{
migration = data[data.size()-2].Cpu() != ev.cpu;
}
} }
else else
{ {
assert( data.empty() || (uint64_t)data.back().End() <= time ); assert( data.empty() || (uint64_t)data.back().End() <= time );
if( !data.empty() )
{
migration = data.back().Cpu() != ev.cpu;
}
item = &data.push_next(); item = &data.push_next();
item->wakeup = time; item->wakeup = time;
} }
@ -4183,6 +4201,16 @@ void Worker::ProcessContextSwitch( const QueueContextSwitch& ev )
{ {
CheckExternalName( ev.newThread ); CheckExternalName( ev.newThread );
} }
if( migration )
{
auto tdit = m_data.cpuThreadData.find( ev.newThread );
if( tdit == m_data.cpuThreadData.end() )
{
tdit = m_data.cpuThreadData.emplace( ev.newThread, CpuThreadData {} ).first;
}
tdit->second.migrations++;
}
} }
} }

View File

@ -213,6 +213,7 @@ private:
CpuData cpuData[256]; CpuData cpuData[256];
flat_hash_map<uint64_t, uint64_t, nohash<uint64_t>> tidToPid; flat_hash_map<uint64_t, uint64_t, nohash<uint64_t>> tidToPid;
flat_hash_map<uint64_t, CpuThreadData, nohash<uint64_t>> cpuThreadData;
}; };
struct MbpsBlock struct MbpsBlock