mirror of
https://github.com/wolfpld/tracy.git
synced 2024-11-22 22: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 start;
|
||||||
int64_t end;
|
int64_t end;
|
||||||
|
|
||||||
std::vector<uint64_t> child;
|
std::vector<Event*> child;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum { EventSize = sizeof( Event ) };
|
enum { EventSize = sizeof( Event ) };
|
||||||
|
@ -175,22 +175,23 @@ void View::Process( const QueueItem& ev )
|
|||||||
void View::ProcessZoneBegin( uint64_t id, const QueueZoneBegin& ev )
|
void View::ProcessZoneBegin( uint64_t id, const QueueZoneBegin& ev )
|
||||||
{
|
{
|
||||||
auto it = m_pendingEndZone.find( id );
|
auto it = m_pendingEndZone.find( id );
|
||||||
const auto idx = m_data.size();
|
auto zone = m_slab.Alloc<Event>();
|
||||||
CheckString( ev.filename );
|
CheckString( ev.filename );
|
||||||
CheckString( ev.function );
|
CheckString( ev.function );
|
||||||
|
zone->start = ev.time;
|
||||||
std::unique_lock<std::mutex> lock( m_lock );
|
std::unique_lock<std::mutex> lock( m_lock );
|
||||||
if( it == m_pendingEndZone.end() )
|
if( it == m_pendingEndZone.end() )
|
||||||
{
|
{
|
||||||
m_data.emplace_back( Event { ev.time, -1 } );
|
zone->end = -1;
|
||||||
NewZone( idx );
|
NewZone( zone );
|
||||||
lock.unlock();
|
lock.unlock();
|
||||||
m_openZones.emplace( id, idx );
|
m_openZones.emplace( id, zone );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
assert( ev.time <= it->second.time );
|
assert( ev.time <= it->second.time );
|
||||||
m_data.emplace_back( Event { ev.time, it->second.time } );
|
zone->end = it->second.time;
|
||||||
NewZone( idx );
|
NewZone( zone );
|
||||||
lock.unlock();
|
lock.unlock();
|
||||||
m_pendingEndZone.erase( it );
|
m_pendingEndZone.erase( it );
|
||||||
}
|
}
|
||||||
@ -205,11 +206,11 @@ void View::ProcessZoneEnd( uint64_t id, const QueueZoneEnd& ev )
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
const auto idx = it->second;
|
auto zone = it->second;
|
||||||
std::unique_lock<std::mutex> lock( m_lock );
|
std::unique_lock<std::mutex> lock( m_lock );
|
||||||
assert( ev.time >= m_data[idx].start );
|
assert( ev.time >= zone->start );
|
||||||
m_data[idx].end = ev.time;
|
zone->end = ev.time;
|
||||||
UpdateZone( idx );
|
UpdateZone( zone );
|
||||||
lock.unlock();
|
lock.unlock();
|
||||||
m_openZones.erase( it );
|
m_openZones.erase( it );
|
||||||
}
|
}
|
||||||
@ -234,15 +235,14 @@ void View::AddString( uint64_t ptr, std::string&& str )
|
|||||||
m_strings.emplace( ptr, std::move( str ) );
|
m_strings.emplace( ptr, std::move( str ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
void View::NewZone( uint64_t idx )
|
void View::NewZone( Event* zone )
|
||||||
{
|
{
|
||||||
if( !m_timeline.empty() )
|
if( !m_timeline.empty() )
|
||||||
{
|
{
|
||||||
auto& zone = m_data[idx];
|
const auto lastend = m_timeline.back()->end;
|
||||||
const auto lastend = m_data[m_timeline.back()].end;
|
if( lastend != -1 && lastend < zone->start )
|
||||||
if( lastend != -1 && lastend < zone.start )
|
|
||||||
{
|
{
|
||||||
m_timeline.emplace_back( idx );
|
m_timeline.emplace_back( zone );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -251,14 +251,13 @@ void View::NewZone( uint64_t idx )
|
|||||||
}
|
}
|
||||||
else
|
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()
|
void View::Draw()
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
#include "../common/TracySocket.hpp"
|
#include "../common/TracySocket.hpp"
|
||||||
#include "../common/TracyQueue.hpp"
|
#include "../common/TracyQueue.hpp"
|
||||||
#include "TracyEvent.hpp"
|
#include "TracyEvent.hpp"
|
||||||
|
#include "TracySlab.hpp"
|
||||||
|
|
||||||
namespace tracy
|
namespace tracy
|
||||||
{
|
{
|
||||||
@ -41,8 +42,8 @@ private:
|
|||||||
void CheckString( uint64_t ptr );
|
void CheckString( uint64_t ptr );
|
||||||
void AddString( uint64_t ptr, std::string&& str );
|
void AddString( uint64_t ptr, std::string&& str );
|
||||||
|
|
||||||
void NewZone( uint64_t idx );
|
void NewZone( Event* zone );
|
||||||
void UpdateZone( uint64_t idx );
|
void UpdateZone( Event* zone );
|
||||||
|
|
||||||
void DrawImpl();
|
void DrawImpl();
|
||||||
|
|
||||||
@ -57,14 +58,15 @@ private:
|
|||||||
// this block must be locked
|
// this block must be locked
|
||||||
std::mutex m_lock;
|
std::mutex m_lock;
|
||||||
std::vector<float> m_mbps;
|
std::vector<float> m_mbps;
|
||||||
std::vector<Event> m_data;
|
std::vector<Event*> m_timeline;
|
||||||
std::vector<uint64_t> m_timeline;
|
|
||||||
std::unordered_map<uint64_t, std::string> m_strings;
|
std::unordered_map<uint64_t, std::string> m_strings;
|
||||||
|
|
||||||
// not used for vis - no need to lock
|
// not used for vis - no need to lock
|
||||||
std::unordered_map<uint64_t, QueueZoneEnd> m_pendingEndZone;
|
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;
|
std::unordered_set<uint64_t> m_pendingStrings;
|
||||||
|
|
||||||
|
Slab<EventSize*1024*1024> m_slab;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user