1
0
mirror of https://github.com/wolfpld/tracy.git synced 2025-03-20 07:40:02 +08:00

Store context switches.

This commit is contained in:
Bartosz Taudul
2019-08-13 00:13:50 +02:00
parent 90d26cb1b6
commit 419f74280d
3 changed files with 61 additions and 0 deletions
+41
View File
@@ -2611,6 +2611,9 @@ bool Worker::Process( const QueueItem& ev )
case QueueType::SysTimeReport:
ProcessSysTime( ev.sysTime );
break;
case QueueType::ContextSwitch:
ProcessContextSwitch( ev.contextSwitch );
break;
default:
assert( false );
break;
@@ -3629,6 +3632,44 @@ void Worker::ProcessSysTime( const QueueSysTime& ev )
}
}
void Worker::ProcessContextSwitch( const QueueContextSwitch& ev )
{
const auto time = TscTime( ev.time );
m_data.lastTime = std::max( m_data.lastTime, time );
if( ev.oldThread != 0 )
{
auto it = m_data.ctxSwitch.find( ev.oldThread );
if( it != m_data.ctxSwitch.end() )
{
auto& data = it->second->v;
assert( !data.empty() );
auto& item = data.back();
assert( item.start <= time );
item.end = time;
item.reason = ev.reason;
item.state = ev.state;
}
}
if( ev.newThread != 0 )
{
auto it = m_data.ctxSwitch.find( ev.newThread );
if( it == m_data.ctxSwitch.end() )
{
auto ctx = m_slab.AllocInit<ContextSwitch>();
it = m_data.ctxSwitch.emplace( ev.newThread, ctx ).first;
}
auto& data = it->second->v;
assert( data.empty() || (uint64_t)data.back().end <= time );
auto& item = data.push_next();
item.start = time;
item.end = -1;
item.cpu = ev.cpu;
item.reason = -1;
item.state = -1;
}
}
void Worker::MemAllocChanged( int64_t time )
{
const auto val = (double)m_data.memory.usage;