Process section enter / leave events.

This commit is contained in:
Bartosz Taudul
2026-06-17 20:29:03 +02:00
parent d89055908b
commit 274e453bb6
3 changed files with 60 additions and 0 deletions

View File

@@ -683,6 +683,14 @@ struct ChildSample
uint64_t addr;
};
struct SectionItem
{
Int48 start, end;
StringIdx text;
uint32_t id;
};
#pragma pack( pop )

View File

@@ -7378,10 +7378,58 @@ void Worker::ProcessFiberLeave( const QueueFiberLeave& ev )
void Worker::ProcessSectionEnter( const QueueSectionEnter& ev )
{
const auto t = TscTime( RefTime( m_refTimeThread, ev.time ) );
if( m_data.lastTime < t ) m_data.lastTime = t;
const auto text = GetSingleStringIdx();
const auto ait = m_data.sectionsActive.find( ev.id );
if( ait != m_data.sectionsActive.end() )
{
m_data.sectionsActive.erase( ait );
auto it = std::ranges::find_if( m_data.sectionsPending, [id = ev.id]( const auto& s ) { return s.id == id; } );
assert( it != m_data.sectionsPending.end() );
assert( it->start.Val() < 0 );
assert( !it->text.Active() );
it->start.SetVal( t );
it->text.SetIdx( text );
m_data.sections.push_back( *it );
m_data.sectionsPending.erase( it );
}
else
{
m_data.sections.push_back( SectionItem {
.start = t,
.end = -1,
.text = StringIdx( text ),
.id = ev.id
} );
m_data.sectionsActive.insert( ev.id );
}
}
void Worker::ProcessSectionLeave( const QueueSectionLeave& ev )
{
const auto t = TscTime( RefTime( m_refTimeThread, ev.time ) );
if( m_data.lastTime < t ) m_data.lastTime = t;
const auto ait = m_data.sectionsActive.find( ev.id );
if( ait != m_data.sectionsActive.end() )
{
m_data.sectionsActive.erase( ait );
auto it = std::ranges::find_if( m_data.sections, [id = ev.id]( const auto& s ) { return s.id == id; } );
assert( it != m_data.sections.end() );
assert( it->end.Val() < 0 );
it->end.SetVal( t );
}
else
{
m_data.sectionsPending.push_back( SectionItem {
.start = -1,
.end = t,
.id = ev.id
} );
m_data.sectionsActive.insert( ev.id );
}
}

View File

@@ -407,6 +407,10 @@ private:
bool hasBranchRetirement = false;
unordered_flat_map<uint64_t, uint64_t> fiberToThreadMap;
Vector<SectionItem> sections;
Vector<SectionItem> sectionsPending;
unordered_flat_set<uint64_t> sectionsActive;
};
struct MbpsBlock