1
0
mirror of https://github.com/wolfpld/tracy synced 2025-04-29 20:33:52 +00:00

Calculate how long thread was in running time.

This commit is contained in:
Bartosz Taudul 2019-08-14 17:11:42 +02:00
parent 72918cda19
commit 3e01ca3269
2 changed files with 10 additions and 1 deletions

View File

@ -379,6 +379,7 @@ struct FrameImage
struct ContextSwitch struct ContextSwitch
{ {
Vector<ContextSwitchData> v; Vector<ContextSwitchData> v;
int64_t runningTime = 0;
}; };
} }

View File

@ -1161,15 +1161,21 @@ Worker::Worker( FileRead& f, EventType::Type eventMask )
f.Read2( thread, csz ); f.Read2( thread, csz );
auto data = m_slab.AllocInit<ContextSwitch>(); auto data = m_slab.AllocInit<ContextSwitch>();
data->v.reserve_exact( csz, m_slab ); data->v.reserve_exact( csz, m_slab );
int64_t runningTime = 0;
int64_t refTime = 0; int64_t refTime = 0;
auto ptr = data->v.data(); auto ptr = data->v.data();
for( uint64_t j=0; j<csz; j++ ) for( uint64_t j=0; j<csz; j++ )
{ {
ptr->start = ReadTimeOffset( f, refTime ); ptr->start = ReadTimeOffset( f, refTime );
ptr->end = ReadTimeOffset( f, refTime ); int64_t diff;
f.Read( diff );
if( diff > 0 ) runningTime += diff;
refTime += diff;
ptr->end = refTime;
f.Read( &ptr->cpu, sizeof( ptr->cpu ) + sizeof( ptr->reason ) + sizeof( ptr->state ) ); f.Read( &ptr->cpu, sizeof( ptr->cpu ) + sizeof( ptr->reason ) + sizeof( ptr->state ) );
ptr++; ptr++;
} }
data->runningTime = runningTime;
m_data.ctxSwitch.emplace( thread, data ); m_data.ctxSwitch.emplace( thread, data );
} }
} }
@ -3728,6 +3734,8 @@ void Worker::ProcessContextSwitch( const QueueContextSwitch& ev )
item.end = time; item.end = time;
item.reason = ev.reason; item.reason = ev.reason;
item.state = ev.state; item.state = ev.state;
it->second->runningTime += time - item.start;
} }
} }
if( ev.newThread != 0 ) if( ev.newThread != 0 )