mirror of
https://github.com/wolfpld/tracy.git
synced 2024-11-30 01:04:36 +00:00
Construct queue items directly in queue memory.
This commit is contained in:
parent
99b8c4c77e
commit
f46781808c
@ -32,37 +32,12 @@ static thread_local moodycamel::ProducerToken s_token( s_queue );
|
||||
|
||||
static std::atomic<uint64_t> s_id( 0 );
|
||||
|
||||
static inline uint64_t GetNewId()
|
||||
{
|
||||
return s_id.fetch_add( 1, std::memory_order_relaxed );
|
||||
}
|
||||
|
||||
#ifndef TRACY_DISABLE
|
||||
static Profiler s_profiler;
|
||||
#endif
|
||||
|
||||
static Profiler* s_instance = nullptr;
|
||||
|
||||
static inline uint64_t ZoneBeginImpl( moodycamel::ProducerToken& token, QueueZoneBegin&& data )
|
||||
{
|
||||
auto id = GetNewId();
|
||||
QueueItem item;
|
||||
item.hdr.type = QueueType::ZoneBegin;
|
||||
item.hdr.id = id;
|
||||
item.zoneBegin = std::move( data );
|
||||
s_queue.enqueue( token, std::move( item ) );
|
||||
return id;
|
||||
}
|
||||
|
||||
static inline void ZoneEndImpl( moodycamel::ProducerToken& token, uint64_t id, QueueZoneEnd&& data )
|
||||
{
|
||||
QueueItem item;
|
||||
item.hdr.type = QueueType::ZoneEnd;
|
||||
item.hdr.id = id;
|
||||
item.zoneEnd = std::move( data );
|
||||
s_queue.enqueue( token, std::move( item ) );
|
||||
}
|
||||
|
||||
Profiler::Profiler()
|
||||
: m_mainThread( GetThreadHandle() )
|
||||
, m_shutdown( false )
|
||||
@ -93,40 +68,27 @@ Profiler::~Profiler()
|
||||
s_instance = nullptr;
|
||||
}
|
||||
|
||||
uint64_t Profiler::ZoneBegin( QueueZoneBegin&& data )
|
||||
QueueItem* Profiler::StartItem()
|
||||
{
|
||||
return ZoneBeginImpl( s_token, std::move( data ) );
|
||||
return s_queue.enqueue_begin( s_token );
|
||||
}
|
||||
|
||||
void Profiler::ZoneEnd( uint64_t id, QueueZoneEnd&& data )
|
||||
void Profiler::FinishItem()
|
||||
{
|
||||
ZoneEndImpl( s_token, id, std::move( data ) );
|
||||
s_queue.enqueue_finish( s_token );
|
||||
}
|
||||
|
||||
void Profiler::ZoneText( uint64_t id, QueueZoneText&& data )
|
||||
uint64_t Profiler::GetNewId()
|
||||
{
|
||||
QueueItem item;
|
||||
item.hdr.type = QueueType::ZoneText;
|
||||
item.hdr.id = id;
|
||||
item.zoneText = std::move( data );
|
||||
s_queue.enqueue( s_token, std::move( item ) );
|
||||
}
|
||||
|
||||
void Profiler::ZoneName( uint64_t id, QueueZoneName&& data )
|
||||
{
|
||||
QueueItem item;
|
||||
item.hdr.type = QueueType::ZoneName;
|
||||
item.hdr.id = id;
|
||||
item.zoneName = std::move( data );
|
||||
s_queue.enqueue( s_token, std::move( item ) );
|
||||
return s_id.fetch_add( 1, std::memory_order_relaxed );
|
||||
}
|
||||
|
||||
void Profiler::FrameMark()
|
||||
{
|
||||
QueueItem item;
|
||||
item.hdr.type = QueueType::FrameMarkMsg;
|
||||
item.hdr.id = (uint64_t)GetTime();
|
||||
s_queue.enqueue( s_token, std::move( item ) );
|
||||
auto item = s_queue.enqueue_begin( s_token );
|
||||
item->hdr.type = QueueType::FrameMarkMsg;
|
||||
item->hdr.id = (uint64_t)GetTime();
|
||||
s_queue.enqueue_finish( s_token );
|
||||
}
|
||||
|
||||
bool Profiler::ShouldExit()
|
||||
@ -337,9 +299,24 @@ void Profiler::CalibrateDelay()
|
||||
moodycamel::ProducerToken ptoken( s_queue );
|
||||
for( int i=0; i<Iterations; i++ )
|
||||
{
|
||||
static const tracy::SourceLocation __tracy_source_location { __FUNCTION__, __FILE__, __LINE__, 0 };
|
||||
const auto id = ZoneBeginImpl( ptoken, QueueZoneBegin { Profiler::GetTime(), (uint64_t)&__tracy_source_location, GetThreadHandle() } );
|
||||
ZoneEndImpl( ptoken, id, QueueZoneEnd { Profiler::GetTime() } );
|
||||
static const tracy::SourceLocation __tracy_source_location { __FUNCTION__, __FILE__, (uint32_t)__LINE__, 0 };
|
||||
const auto id = GetNewId();
|
||||
{
|
||||
auto item = s_queue.enqueue_begin( ptoken );
|
||||
item->hdr.type = QueueType::ZoneBegin;
|
||||
item->hdr.id = id;
|
||||
item->zoneBegin.time = GetTime();
|
||||
item->zoneBegin.srcloc = (uint64_t)&__tracy_source_location;
|
||||
item->zoneBegin.thread = GetThreadHandle();
|
||||
s_queue.enqueue_finish( ptoken );
|
||||
}
|
||||
{
|
||||
auto item = s_queue.enqueue_begin( ptoken );
|
||||
item->hdr.type = QueueType::ZoneEnd;
|
||||
item->hdr.id = id;
|
||||
item->zoneEnd.time = GetTime();
|
||||
s_queue.enqueue_finish( ptoken );
|
||||
}
|
||||
}
|
||||
const auto f0 = GetTime();
|
||||
for( int i=0; i<Iterations; i++ )
|
||||
@ -350,9 +327,24 @@ void Profiler::CalibrateDelay()
|
||||
const auto t0 = GetTime();
|
||||
for( int i=0; i<Iterations; i++ )
|
||||
{
|
||||
static const tracy::SourceLocation __tracy_source_location { __FUNCTION__, __FILE__, __LINE__, 0 };
|
||||
const auto id = ZoneBeginImpl( ptoken, QueueZoneBegin { Profiler::GetTime(), (uint64_t)&__tracy_source_location, GetThreadHandle() } );
|
||||
ZoneEndImpl( ptoken, id, QueueZoneEnd { Profiler::GetTime() } );
|
||||
static const tracy::SourceLocation __tracy_source_location { __FUNCTION__, __FILE__, (uint32_t)__LINE__, 0 };
|
||||
const auto id = GetNewId();
|
||||
{
|
||||
auto item = s_queue.enqueue_begin( ptoken );
|
||||
item->hdr.type = QueueType::ZoneBegin;
|
||||
item->hdr.id = id;
|
||||
item->zoneBegin.time = GetTime();
|
||||
item->zoneBegin.srcloc = (uint64_t)&__tracy_source_location;
|
||||
item->zoneBegin.thread = GetThreadHandle();
|
||||
s_queue.enqueue_finish( ptoken );
|
||||
}
|
||||
{
|
||||
auto item = s_queue.enqueue_begin( ptoken );
|
||||
item->hdr.type = QueueType::ZoneEnd;
|
||||
item->hdr.id = id;
|
||||
item->zoneEnd.time = GetTime();
|
||||
s_queue.enqueue_finish( ptoken );
|
||||
}
|
||||
}
|
||||
const auto t1 = GetTime();
|
||||
const auto dt = t1 - t0;
|
||||
|
@ -42,10 +42,10 @@ public:
|
||||
#endif
|
||||
}
|
||||
|
||||
static uint64_t ZoneBegin( QueueZoneBegin&& data );
|
||||
static void ZoneEnd( uint64_t id, QueueZoneEnd&& data );
|
||||
static void ZoneText( uint64_t id, QueueZoneText&& data );
|
||||
static void ZoneName( uint64_t id, QueueZoneName&& data );
|
||||
static QueueItem* StartItem();
|
||||
static void FinishItem();
|
||||
static uint64_t GetNewId();
|
||||
|
||||
static void FrameMark();
|
||||
|
||||
static bool ShouldExit();
|
||||
|
@ -14,13 +14,24 @@ class ScopedZone
|
||||
{
|
||||
public:
|
||||
ScopedZone( const SourceLocation* srcloc )
|
||||
: m_id( Profiler::ZoneBegin( QueueZoneBegin { Profiler::GetTime(), (uint64_t)srcloc, GetThreadHandle() } ) )
|
||||
: m_id( Profiler::GetNewId() )
|
||||
{
|
||||
auto item = Profiler::StartItem();
|
||||
item->hdr.type = QueueType::ZoneBegin;
|
||||
item->hdr.id = m_id;
|
||||
item->zoneBegin.time = Profiler::GetTime();
|
||||
item->zoneBegin.srcloc = (uint64_t)srcloc;
|
||||
item->zoneBegin.thread = GetThreadHandle();
|
||||
Profiler::FinishItem();
|
||||
}
|
||||
|
||||
~ScopedZone()
|
||||
{
|
||||
Profiler::ZoneEnd( m_id, QueueZoneEnd { Profiler::GetTime() } );
|
||||
auto item = Profiler::StartItem();
|
||||
item->hdr.type = QueueType::ZoneEnd;
|
||||
item->hdr.id = m_id;
|
||||
item->zoneEnd.time = Profiler::GetTime();
|
||||
Profiler::FinishItem();
|
||||
}
|
||||
|
||||
void Text( const char* txt, size_t size )
|
||||
@ -28,12 +39,20 @@ public:
|
||||
auto ptr = new char[size+1];
|
||||
memcpy( ptr, txt, size );
|
||||
ptr[size] = '\0';
|
||||
Profiler::ZoneText( m_id, QueueZoneText { (uint64_t)ptr } );
|
||||
auto item = Profiler::StartItem();
|
||||
item->hdr.type = QueueType::ZoneText;
|
||||
item->hdr.id = m_id;
|
||||
item->zoneText.text = (uint64_t)ptr;
|
||||
Profiler::FinishItem();
|
||||
}
|
||||
|
||||
void Name( const char* name )
|
||||
{
|
||||
Profiler::ZoneName( m_id, QueueZoneName { (uint64_t)name } );
|
||||
auto item = Profiler::StartItem();
|
||||
item->hdr.type = QueueType::ZoneName;
|
||||
item->hdr.id = m_id;
|
||||
item->zoneName.name = (uint64_t)name;
|
||||
Profiler::FinishItem();
|
||||
}
|
||||
|
||||
private:
|
||||
|
Loading…
Reference in New Issue
Block a user