1
0
mirror of https://github.com/wolfpld/tracy synced 2025-05-05 06:33:52 +00:00

Properly use zone stack when inserting new zones.

CPU zones stack was also moved to thread data struct.
This commit is contained in:
Bartosz Taudul 2017-11-19 01:16:21 +01:00
parent 65a62d9611
commit b3e0d2660d
3 changed files with 18 additions and 36 deletions

View File

@ -132,6 +132,7 @@ struct ThreadData
bool showFull; bool showFull;
bool visible; bool visible;
Vector<ZoneEvent*> timeline; Vector<ZoneEvent*> timeline;
Vector<ZoneEvent*> stack;
Vector<MessageData*> messages; Vector<MessageData*> messages;
}; };

View File

@ -490,9 +490,9 @@ void View::Worker()
continue; continue;
} }
bool done = true; bool done = true;
for( auto& v : m_zoneStack ) for( auto& v : m_threads )
{ {
if( !v.second.empty() ) if( !v->stack.empty() )
{ {
done = false; done = false;
break; break;
@ -633,7 +633,6 @@ void View::ProcessZoneBegin( const QueueZoneBegin& ev )
zone->cpu_start = ev.cpu == 0xFFFFFFFF ? -1 : (int8_t)ev.cpu; zone->cpu_start = ev.cpu == 0xFFFFFFFF ? -1 : (int8_t)ev.cpu;
NewZone( zone, ev.thread ); NewZone( zone, ev.thread );
m_zoneStack[ev.thread].push_back( zone );
} }
void View::ProcessZoneBeginAllocSrcLoc( const QueueZoneBegin& ev ) void View::ProcessZoneBeginAllocSrcLoc( const QueueZoneBegin& ev )
@ -651,14 +650,17 @@ void View::ProcessZoneBeginAllocSrcLoc( const QueueZoneBegin& ev )
zone->srcloc = it->second; zone->srcloc = it->second;
NewZone( zone, ev.thread ); NewZone( zone, ev.thread );
m_zoneStack[ev.thread].push_back( zone );
m_pendingSourceLocationPayload.erase( it ); m_pendingSourceLocationPayload.erase( it );
} }
void View::ProcessZoneEnd( const QueueZoneEnd& ev ) void View::ProcessZoneEnd( const QueueZoneEnd& ev )
{ {
auto& stack = m_zoneStack[ev.thread]; auto tit = m_threadMap.find( ev.thread );
assert( tit != m_threadMap.end() );
auto td = m_threads[tit->second];
auto& stack = td->stack;
assert( !stack.empty() ); assert( !stack.empty() );
auto zone = stack.back(); auto zone = stack.back();
stack.pop_back(); stack.pop_back();
@ -667,7 +669,6 @@ void View::ProcessZoneEnd( const QueueZoneEnd& ev )
assert( ev.cpu == 0xFFFFFFFF || ev.cpu <= std::numeric_limits<int8_t>::max() ); assert( ev.cpu == 0xFFFFFFFF || ev.cpu <= std::numeric_limits<int8_t>::max() );
zone->cpu_end = ev.cpu == 0xFFFFFFFF ? -1 : (int8_t)ev.cpu; zone->cpu_end = ev.cpu == 0xFFFFFFFF ? -1 : (int8_t)ev.cpu;
assert( zone->end >= zone->start ); assert( zone->end >= zone->start );
UpdateZone( zone );
} }
void View::ProcessFrameMark( const QueueFrameMark& ev ) void View::ProcessFrameMark( const QueueFrameMark& ev )
@ -681,7 +682,11 @@ void View::ProcessFrameMark( const QueueFrameMark& ev )
void View::ProcessZoneText( const QueueZoneText& ev ) void View::ProcessZoneText( const QueueZoneText& ev )
{ {
auto& stack = m_zoneStack[ev.thread]; auto tit = m_threadMap.find( ev.thread );
assert( tit != m_threadMap.end() );
auto td = m_threads[tit->second];
auto& stack = td->stack;
assert( !stack.empty() ); assert( !stack.empty() );
auto zone = stack.back(); auto zone = stack.back();
auto it = m_pendingCustomStrings.find( ev.text ); auto it = m_pendingCustomStrings.find( ev.text );
@ -1109,35 +1114,15 @@ void View::NewZone( ZoneEvent* zone, uint64_t thread )
m_zonesCnt++; m_zonesCnt++;
auto td = NoticeThread( thread ); auto td = NoticeThread( thread );
td->count++; td->count++;
Vector<ZoneEvent*>* timeline = &td->timeline; if( td->stack.empty() )
InsertZone( zone, *timeline );
}
void View::UpdateZone( ZoneEvent* zone )
{
assert( zone->end != -1 );
assert( std::upper_bound( zone->child.begin(), zone->child.end(), zone->end, [] ( const auto& l, const auto& r ) { return l < r->start; } ) == zone->child.end() );
}
void View::InsertZone( ZoneEvent* zone, Vector<ZoneEvent*>& vec )
{
if( !vec.empty() )
{ {
const auto lastend = vec.back()->end; td->stack.push_back( zone );
if( lastend != -1 && lastend <= zone->start ) td->timeline.push_back( zone );
{
vec.push_back( zone );
} }
else else
{ {
assert( std::upper_bound( vec.begin(), vec.end(), zone->start, [] ( const auto& l, const auto& r ) { return l < r->start; } ) == vec.end() ); td->stack.back()->child.push_back( zone );
assert( vec.back()->end == -1 || vec.back()->end >= zone->end ); td->stack.push_back( zone );
InsertZone( zone, vec.back()->child );
}
}
else
{
vec.push_back( zone );
} }
} }

View File

@ -89,9 +89,6 @@ private:
ThreadData* NoticeThread( uint64_t thread ); ThreadData* NoticeThread( uint64_t thread );
void NewZone( ZoneEvent* zone, uint64_t thread ); void NewZone( ZoneEvent* zone, uint64_t thread );
void UpdateZone( ZoneEvent* zone );
void InsertZone( ZoneEvent* zone, Vector<ZoneEvent*>& vec );
void InsertLockEvent( LockMap& lockmap, LockEvent* lev, uint64_t thread ); void InsertLockEvent( LockMap& lockmap, LockEvent* lev, uint64_t thread );
void UpdateLockCount( LockMap& lockmap, size_t pos ); void UpdateLockCount( LockMap& lockmap, size_t pos );
@ -187,7 +184,6 @@ private:
std::vector<float> m_mbps; std::vector<float> m_mbps;
// not used for vis - no need to lock // not used for vis - no need to lock
flat_hash_map<uint64_t, std::vector<ZoneEvent*>, power_of_two_std_hash<uint64_t>> m_zoneStack;
flat_hash_set<uint64_t, power_of_two_std_hash<uint64_t>> m_pendingStrings; flat_hash_set<uint64_t, power_of_two_std_hash<uint64_t>> m_pendingStrings;
flat_hash_set<uint64_t, power_of_two_std_hash<uint64_t>> m_pendingThreads; flat_hash_set<uint64_t, power_of_two_std_hash<uint64_t>> m_pendingThreads;
flat_hash_set<uint64_t, power_of_two_std_hash<uint64_t>> m_pendingSourceLocation; flat_hash_set<uint64_t, power_of_two_std_hash<uint64_t>> m_pendingSourceLocation;