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

Use slab allocator to store event data.

This commit is contained in:
Bartosz Taudul
2017-09-15 19:56:55 +02:00
parent de0b50aef9
commit 1c56347f1d
3 changed files with 26 additions and 25 deletions
+18 -19
View File
@@ -175,22 +175,23 @@ void View::Process( const QueueItem& ev )
void View::ProcessZoneBegin( uint64_t id, const QueueZoneBegin& ev )
{
auto it = m_pendingEndZone.find( id );
const auto idx = m_data.size();
auto zone = m_slab.Alloc<Event>();
CheckString( ev.filename );
CheckString( ev.function );
zone->start = ev.time;
std::unique_lock<std::mutex> lock( m_lock );
if( it == m_pendingEndZone.end() )
{
m_data.emplace_back( Event { ev.time, -1 } );
NewZone( idx );
zone->end = -1;
NewZone( zone );
lock.unlock();
m_openZones.emplace( id, idx );
m_openZones.emplace( id, zone );
}
else
{
assert( ev.time <= it->second.time );
m_data.emplace_back( Event { ev.time, it->second.time } );
NewZone( idx );
zone->end = it->second.time;
NewZone( zone );
lock.unlock();
m_pendingEndZone.erase( it );
}
@@ -205,11 +206,11 @@ void View::ProcessZoneEnd( uint64_t id, const QueueZoneEnd& ev )
}
else
{
const auto idx = it->second;
auto zone = it->second;
std::unique_lock<std::mutex> lock( m_lock );
assert( ev.time >= m_data[idx].start );
m_data[idx].end = ev.time;
UpdateZone( idx );
assert( ev.time >= zone->start );
zone->end = ev.time;
UpdateZone( zone );
lock.unlock();
m_openZones.erase( it );
}
@@ -234,15 +235,14 @@ void View::AddString( uint64_t ptr, std::string&& str )
m_strings.emplace( ptr, std::move( str ) );
}
void View::NewZone( uint64_t idx )
void View::NewZone( Event* zone )
{
if( !m_timeline.empty() )
{
auto& zone = m_data[idx];
const auto lastend = m_data[m_timeline.back()].end;
if( lastend != -1 && lastend < zone.start )
const auto lastend = m_timeline.back()->end;
if( lastend != -1 && lastend < zone->start )
{
m_timeline.emplace_back( idx );
m_timeline.emplace_back( zone );
}
else
{
@@ -251,14 +251,13 @@ void View::NewZone( uint64_t idx )
}
else
{
m_timeline.emplace_back( idx );
m_timeline.emplace_back( zone );
}
}
void View::UpdateZone( uint64_t idx )
void View::UpdateZone( Event* zone )
{
auto& zone = m_data[idx++];
assert( zone.end != -1 );
assert( zone->end != -1 );
}
void View::Draw()