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

Process all data available in ring buffers.

This commit is contained in:
Bartosz Taudul 2021-06-10 02:07:29 +02:00
parent 5b7cd06840
commit ca2130d56c
No known key found for this signature in database
GPG Key ID: B7FE2008B7575DF3
2 changed files with 137 additions and 128 deletions

View File

@ -59,12 +59,6 @@ public:
ioctl( m_fd, PERF_EVENT_IOC_ENABLE, 0 );
}
bool HasData() const
{
const auto head = LoadHead();
return head > m_tail;
}
void Read( void* dst, uint64_t offset, uint64_t cnt )
{
auto src = ( m_tail + offset ) % Size;
@ -100,12 +94,17 @@ public:
return ( quot << m_metadata->time_shift ) + ( rem << m_metadata->time_shift ) / m_metadata->time_mult;
}
private:
uint64_t LoadHead() const
{
return std::atomic_load_explicit( (const volatile std::atomic<uint64_t>*)&m_metadata->data_head, std::memory_order_acquire );
}
uint64_t GetTail() const
{
return m_tail;
}
private:
void StoreTail()
{
std::atomic_store_explicit( (volatile std::atomic<uint64_t>*)&m_metadata->data_tail, m_tail, std::memory_order_release );

View File

@ -933,14 +933,21 @@ static void SetupSampling( int64_t& samplingPeriod )
for( int i=0; i<s_numBuffers; i++ )
{
if( !traceActive.load( std::memory_order_relaxed ) ) break;
if( !s_ring[i].HasData() ) continue;
const auto head = s_ring[i].LoadHead();
const auto tail = s_ring[i].GetTail();
if( head == tail ) continue;
assert( head > tail );
hadData = true;
const auto end = head - tail;
uint64_t pos = 0;
while( pos < end )
{
perf_event_header hdr;
s_ring[i].Read( &hdr, 0, sizeof( perf_event_header ) );
s_ring[i].Read( &hdr, pos, sizeof( perf_event_header ) );
if( hdr.type == PERF_RECORD_SAMPLE )
{
auto offset = sizeof( perf_event_header );
auto offset = pos + sizeof( perf_event_header );
const auto id = s_ring[i].GetId();
if( id == EventCallstack )
{
@ -1068,7 +1075,10 @@ static void SetupSampling( int64_t& samplingPeriod )
}
}
}
s_ring[i].Advance( hdr.size );
pos += hdr.size;
}
assert( pos == end );
s_ring[i].Advance( end );
}
if( !traceActive.load( std::memory_order_relaxed) ) break;
if( !hadData )