mirror of
https://github.com/wolfpld/tracy.git
synced 2024-11-22 14:44:34 +00:00
Use slab allocator to store event data.
This commit is contained in:
parent
de0b50aef9
commit
1c56347f1d
@ -11,7 +11,7 @@ struct Event
|
||||
int64_t start;
|
||||
int64_t end;
|
||||
|
||||
std::vector<uint64_t> child;
|
||||
std::vector<Event*> child;
|
||||
};
|
||||
|
||||
enum { EventSize = sizeof( Event ) };
|
||||
|
@ -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()
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include "../common/TracySocket.hpp"
|
||||
#include "../common/TracyQueue.hpp"
|
||||
#include "TracyEvent.hpp"
|
||||
#include "TracySlab.hpp"
|
||||
|
||||
namespace tracy
|
||||
{
|
||||
@ -41,8 +42,8 @@ private:
|
||||
void CheckString( uint64_t ptr );
|
||||
void AddString( uint64_t ptr, std::string&& str );
|
||||
|
||||
void NewZone( uint64_t idx );
|
||||
void UpdateZone( uint64_t idx );
|
||||
void NewZone( Event* zone );
|
||||
void UpdateZone( Event* zone );
|
||||
|
||||
void DrawImpl();
|
||||
|
||||
@ -57,14 +58,15 @@ private:
|
||||
// this block must be locked
|
||||
std::mutex m_lock;
|
||||
std::vector<float> m_mbps;
|
||||
std::vector<Event> m_data;
|
||||
std::vector<uint64_t> m_timeline;
|
||||
std::vector<Event*> m_timeline;
|
||||
std::unordered_map<uint64_t, std::string> m_strings;
|
||||
|
||||
// not used for vis - no need to lock
|
||||
std::unordered_map<uint64_t, QueueZoneEnd> m_pendingEndZone;
|
||||
std::unordered_map<uint64_t, uint64_t> m_openZones;
|
||||
std::unordered_map<uint64_t, Event*> m_openZones;
|
||||
std::unordered_set<uint64_t> m_pendingStrings;
|
||||
|
||||
Slab<EventSize*1024*1024> m_slab;
|
||||
};
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user