Collect per-cpu context switch data.

This commit is contained in:
Bartosz Taudul 2019-08-16 16:28:58 +02:00
parent 9e0fe226df
commit 69527d2f71
3 changed files with 42 additions and 0 deletions

View File

@ -252,6 +252,30 @@ struct ContextSwitchData
enum { ContextSwitchDataSize = sizeof( ContextSwitchData ) };
// Thread can't be compressed here, because we want to ignore external threads and we can't
// determine whether thread is local or external when context information arrives (thread data
// might come after context switch data).
struct ContextSwitchCpu
{
int64_t Start() const { return int64_t( _start_thread1 ) >> 16; }
void SetStart( int64_t start ) { assert( start < ( 1ll << 47 ) ); _start_thread1 = ( _start_thread1 & 0xFFFF ) | uint64_t( start << 16 ); }
int64_t End() const { return int64_t( _end_thread2 ) >> 16; }
void SetEnd( int64_t end ) { assert( end < ( 1ll << 47 ) ); _end_thread2 = ( _end_thread2 & 0xFFFF ) | uint64_t( end << 16 ); }
uint64_t Thread() const { return uint64_t( uint16_t( _start_thread1 ) ) | ( uint64_t( uint16_t( _end_thread2 ) ) << 16 ) | ( uint64_t( _thread3 ) << 32 ); }
void SetThread( uint64_t thread ) {
_start_thread1 = ( _start_thread1 & 0xFFFFFFFFFFFF0000 ) | uint16_t( thread );
_end_thread2 = ( _end_thread2 & 0xFFFFFFFFFFFF0000 ) | uint16_t( thread >> 16 );
_thread3 = uint32_t( thread >> 32 );
}
uint64_t _start_thread1;
uint64_t _end_thread2;
uint32_t _thread3;
};
enum { ContextSwitchCpuSize = sizeof( ContextSwitchCpu ) };
struct MessageData
{
int64_t time;
@ -409,6 +433,11 @@ struct ContextSwitch
int64_t runningTime = 0;
};
struct CpuData
{
Vector<ContextSwitchCpu> cs;
};
}
#endif

View File

@ -3963,6 +3963,7 @@ void Worker::ProcessContextSwitch( const QueueContextSwitch& ev )
const auto time = TscTime( ev.time - m_data.baseTime );
m_data.lastTime = std::max( m_data.lastTime, time );
auto& cs = m_data.cpuData[ev.cpu].cs;
if( ev.oldThread != 0 )
{
auto it = m_data.ctxSwitch.find( ev.oldThread );
@ -3978,6 +3979,12 @@ void Worker::ProcessContextSwitch( const QueueContextSwitch& ev )
it->second->runningTime += time - item.Start();
}
if( !cs.empty() )
{
auto& cx = cs.back();
assert( cx.Thread() == ev.oldThread );
cx.SetEnd( time );
}
}
if( ev.newThread != 0 )
{
@ -3995,6 +4002,10 @@ void Worker::ProcessContextSwitch( const QueueContextSwitch& ev )
item.SetCpu( ev.cpu );
item.SetReason( -1 );
item.SetState( -1 );
auto& cx = cs.push_next();
cx.SetStart( time );
cx.SetThread( ev.newThread );
}
}

View File

@ -208,6 +208,8 @@ private:
flat_hash_map<uint64_t, ContextSwitch*, nohash<uint64_t>> ctxSwitch;
std::pair<uint64_t, ContextSwitch*> ctxSwitchLast;
CpuData cpuData[256];
};
struct MbpsBlock