mirror of
https://github.com/wolfpld/tracy.git
synced 2024-11-10 02:31:48 +00:00
Remove one level of indirection.
This commit is contained in:
parent
cc8b357f09
commit
af3773dc9a
@ -20,11 +20,11 @@ public:
|
||||
{
|
||||
Magic magic;
|
||||
auto& token = s_token;
|
||||
auto item = s_queue.enqueue_begin( token, magic );
|
||||
auto item = token->enqueue_begin<moodycamel::CanAlloc>( magic );
|
||||
item->hdr.type = QueueType::LockAnnounce;
|
||||
item->lockAnnounce.id = m_id;
|
||||
item->lockAnnounce.srcloc = (uint64_t)srcloc;
|
||||
s_queue.enqueue_finish( token, magic );
|
||||
token->enqueue_finish( magic );
|
||||
}
|
||||
|
||||
Lockable( const Lockable& ) = delete;
|
||||
@ -37,12 +37,12 @@ public:
|
||||
{
|
||||
Magic magic;
|
||||
auto& token = s_token;
|
||||
auto item = s_queue.enqueue_begin( token, magic );
|
||||
auto item = token->enqueue_begin<moodycamel::CanAlloc>( magic );
|
||||
item->hdr.type = QueueType::LockWait;
|
||||
item->lockWait.id = m_id;
|
||||
item->lockWait.thread = thread;
|
||||
item->lockWait.time = Profiler::GetTime( cpu );
|
||||
s_queue.enqueue_finish( token, magic );
|
||||
token->enqueue_finish( magic );
|
||||
}
|
||||
|
||||
m_lockable.lock();
|
||||
@ -50,12 +50,12 @@ public:
|
||||
{
|
||||
Magic magic;
|
||||
auto& token = s_token;
|
||||
auto item = s_queue.enqueue_begin( token, magic );
|
||||
auto item = token->enqueue_begin<moodycamel::CanAlloc>( magic );
|
||||
item->hdr.type = QueueType::LockObtain;
|
||||
item->lockObtain.id = m_id;
|
||||
item->lockObtain.thread = thread;
|
||||
item->lockObtain.time = Profiler::GetTime( cpu );
|
||||
s_queue.enqueue_finish( token, magic );
|
||||
token->enqueue_finish( magic );
|
||||
}
|
||||
}
|
||||
|
||||
@ -66,12 +66,12 @@ public:
|
||||
uint32_t cpu;
|
||||
Magic magic;
|
||||
auto& token = s_token;
|
||||
auto item = s_queue.enqueue_begin( token, magic );
|
||||
auto item = token->enqueue_begin<moodycamel::CanAlloc>( magic );
|
||||
item->hdr.type = QueueType::LockRelease;
|
||||
item->lockRelease.id = m_id;
|
||||
item->lockRelease.thread = GetThreadHandle();
|
||||
item->lockRelease.time = Profiler::GetTime( cpu );
|
||||
s_queue.enqueue_finish( token, magic );
|
||||
token->enqueue_finish( magic );
|
||||
}
|
||||
|
||||
tracy_force_inline bool try_lock()
|
||||
@ -82,12 +82,12 @@ public:
|
||||
uint32_t cpu;
|
||||
Magic magic;
|
||||
auto& token = s_token;
|
||||
auto item = s_queue.enqueue_begin( token, magic );
|
||||
auto item = token->enqueue_begin<moodycamel::CanAlloc>( magic );
|
||||
item->hdr.type = QueueType::LockObtain;
|
||||
item->lockObtain.id = (uint64_t)&m_lockable;
|
||||
item->lockObtain.thread = GetThreadHandle();
|
||||
item->lockObtain.time = Profiler::GetTime( cpu );
|
||||
s_queue.enqueue_finish( token, magic );
|
||||
token->enqueue_finish( magic );
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@ -96,12 +96,12 @@ public:
|
||||
{
|
||||
Magic magic;
|
||||
auto& token = s_token;
|
||||
auto item = s_queue.enqueue_begin( token, magic );
|
||||
auto item = token->enqueue_begin<moodycamel::CanAlloc>( magic );
|
||||
item->hdr.type = QueueType::LockMark;
|
||||
item->lockMark.id = m_id;
|
||||
item->lockMark.thread = GetThreadHandle();
|
||||
item->lockMark.srcloc = (uint64_t)srcloc;
|
||||
s_queue.enqueue_finish( token, magic );
|
||||
token->enqueue_finish( magic );
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -54,13 +54,14 @@ static const char* GetProcessName()
|
||||
|
||||
enum { QueuePrealloc = 256 * 1024 };
|
||||
|
||||
moodycamel::ConcurrentQueue<QueueItem> init_order(101) s_queue( QueueItemSize * QueuePrealloc );
|
||||
thread_local moodycamel::ProducerToken init_order(102) s_token( s_queue );
|
||||
static moodycamel::ConcurrentQueue<QueueItem> init_order(101) s_queue( QueueItemSize * QueuePrealloc );
|
||||
static thread_local moodycamel::ProducerToken init_order(102) s_token_detail( s_queue );
|
||||
thread_local moodycamel::ConcurrentQueue<QueueItem>::ExplicitProducer* init_order(103) s_token = s_queue.get_explicit_producer( s_token_detail );
|
||||
|
||||
std::atomic<uint64_t> s_id( 0 );
|
||||
|
||||
#ifndef TRACY_DISABLE
|
||||
static Profiler init_order(103) s_profiler;
|
||||
static Profiler init_order(104) s_profiler;
|
||||
#endif
|
||||
|
||||
static Profiler* s_instance = nullptr;
|
||||
@ -226,7 +227,7 @@ void Profiler::SendSourceLocation( uint64_t ptr )
|
||||
item.srcloc.function = (uint64_t)srcloc->function;
|
||||
item.srcloc.line = srcloc->line;
|
||||
item.srcloc.color = srcloc->color;
|
||||
s_queue.enqueue( s_token, std::move( item ) );
|
||||
s_token->enqueue<moodycamel::CanAlloc>( std::move( item ) );
|
||||
}
|
||||
|
||||
bool Profiler::HandleServerQuery()
|
||||
@ -311,26 +312,27 @@ void Profiler::CalibrateDelay()
|
||||
static_assert( Events * 2 < QueuePrealloc, "Delay calibration loop will allocate memory in queue" );
|
||||
|
||||
uint32_t cpu;
|
||||
moodycamel::ProducerToken ptoken( s_queue );
|
||||
moodycamel::ProducerToken ptoken_detail( s_queue );
|
||||
moodycamel::ConcurrentQueue<QueueItem>::ExplicitProducer* ptoken = s_queue.get_explicit_producer( ptoken_detail );
|
||||
for( int i=0; i<Iterations; i++ )
|
||||
{
|
||||
static const tracy::SourceLocation __tracy_source_location { __FUNCTION__, __FILE__, (uint32_t)__LINE__, 0 };
|
||||
{
|
||||
Magic magic;
|
||||
auto item = s_queue.enqueue_begin( ptoken, magic );
|
||||
auto item = ptoken->enqueue_begin<moodycamel::CanAlloc>( magic );
|
||||
item->hdr.type = QueueType::ZoneBegin;
|
||||
item->zoneBegin.thread = GetThreadHandle();
|
||||
item->zoneBegin.time = GetTime( item->zoneBegin.cpu );
|
||||
item->zoneBegin.srcloc = (uint64_t)&__tracy_source_location;
|
||||
s_queue.enqueue_finish( ptoken, magic );
|
||||
ptoken->enqueue_finish( magic );
|
||||
}
|
||||
{
|
||||
Magic magic;
|
||||
auto item = s_queue.enqueue_begin( ptoken, magic );
|
||||
auto item = ptoken->enqueue_begin<moodycamel::CanAlloc>( magic );
|
||||
item->hdr.type = QueueType::ZoneEnd;
|
||||
item->zoneEnd.thread = 0;
|
||||
item->zoneEnd.time = GetTime( item->zoneEnd.cpu );
|
||||
s_queue.enqueue_finish( ptoken, magic );
|
||||
ptoken->enqueue_finish( magic );
|
||||
}
|
||||
}
|
||||
const auto f0 = GetTime( cpu );
|
||||
@ -345,20 +347,20 @@ void Profiler::CalibrateDelay()
|
||||
static const tracy::SourceLocation __tracy_source_location { __FUNCTION__, __FILE__, (uint32_t)__LINE__, 0 };
|
||||
{
|
||||
Magic magic;
|
||||
auto item = s_queue.enqueue_begin( ptoken, magic );
|
||||
auto item = ptoken->enqueue_begin<moodycamel::CanAlloc>( magic );
|
||||
item->hdr.type = QueueType::ZoneBegin;
|
||||
item->zoneBegin.thread = GetThreadHandle();
|
||||
item->zoneBegin.time = GetTime( item->zoneBegin.cpu );
|
||||
item->zoneBegin.srcloc = (uint64_t)&__tracy_source_location;
|
||||
s_queue.enqueue_finish( ptoken, magic );
|
||||
ptoken->enqueue_finish( magic );
|
||||
}
|
||||
{
|
||||
Magic magic;
|
||||
auto item = s_queue.enqueue_begin( ptoken, magic );
|
||||
auto item = ptoken->enqueue_begin<moodycamel::CanAlloc>( magic );
|
||||
item->hdr.type = QueueType::ZoneEnd;
|
||||
item->zoneEnd.thread = 0;
|
||||
item->zoneEnd.time = GetTime( item->zoneEnd.cpu );
|
||||
s_queue.enqueue_finish( ptoken, magic );
|
||||
ptoken->enqueue_finish( magic );
|
||||
}
|
||||
}
|
||||
const auto t1 = GetTime( cpu );
|
||||
|
@ -31,8 +31,7 @@ struct SourceLocation
|
||||
uint32_t color;
|
||||
};
|
||||
|
||||
extern moodycamel::ConcurrentQueue<QueueItem> s_queue;
|
||||
extern thread_local moodycamel::ProducerToken s_token;
|
||||
extern thread_local moodycamel::ConcurrentQueue<QueueItem>::ExplicitProducer* s_token;
|
||||
|
||||
using Magic = moodycamel::ConcurrentQueueDefaultTraits::index_t;
|
||||
|
||||
@ -71,10 +70,10 @@ public:
|
||||
uint32_t cpu;
|
||||
Magic magic;
|
||||
auto& token = s_token;
|
||||
auto item = s_queue.enqueue_begin( token, magic );
|
||||
auto item = token->enqueue_begin<moodycamel::CanAlloc>( magic );
|
||||
item->hdr.type = QueueType::FrameMarkMsg;
|
||||
item->frameMark.time = GetTime( cpu );
|
||||
s_queue.enqueue_finish( token, magic );
|
||||
token->enqueue_finish( magic );
|
||||
}
|
||||
|
||||
static bool ShouldExit();
|
||||
|
@ -19,23 +19,23 @@ public:
|
||||
m_thread = thread;
|
||||
Magic magic;
|
||||
auto& token = s_token;
|
||||
auto item = s_queue.enqueue_begin( token, magic );
|
||||
auto item = token->enqueue_begin<moodycamel::CanAlloc>( magic );
|
||||
item->hdr.type = QueueType::ZoneBegin;
|
||||
item->zoneBegin.time = Profiler::GetTime( item->zoneBegin.cpu );
|
||||
item->zoneBegin.thread = thread;
|
||||
item->zoneBegin.srcloc = (uint64_t)srcloc;
|
||||
s_queue.enqueue_finish( token, magic );
|
||||
token->enqueue_finish( magic );
|
||||
}
|
||||
|
||||
tracy_force_inline ~ScopedZone()
|
||||
{
|
||||
Magic magic;
|
||||
auto& token = s_token;
|
||||
auto item = s_queue.enqueue_begin( token, magic );
|
||||
auto item = token->enqueue_begin<moodycamel::CanAlloc>( magic );
|
||||
item->hdr.type = QueueType::ZoneEnd;
|
||||
item->zoneEnd.time = Profiler::GetTime( item->zoneEnd.cpu );
|
||||
item->zoneEnd.thread = m_thread;
|
||||
s_queue.enqueue_finish( token, magic );
|
||||
token->enqueue_finish( magic );
|
||||
}
|
||||
|
||||
tracy_force_inline void Text( const char* txt, size_t size )
|
||||
@ -45,22 +45,22 @@ public:
|
||||
memcpy( ptr, txt, size );
|
||||
ptr[size] = '\0';
|
||||
auto& token = s_token;
|
||||
auto item = s_queue.enqueue_begin( token, magic );
|
||||
auto item = token->enqueue_begin<moodycamel::CanAlloc>( magic );
|
||||
item->hdr.type = QueueType::ZoneText;
|
||||
item->zoneText.thread = m_thread;
|
||||
item->zoneText.text = (uint64_t)ptr;
|
||||
s_queue.enqueue_finish( token, magic );
|
||||
token->enqueue_finish( magic );
|
||||
}
|
||||
|
||||
tracy_force_inline void Name( const char* name )
|
||||
{
|
||||
Magic magic;
|
||||
auto& token = s_token;
|
||||
auto item = s_queue.enqueue_begin( token, magic );
|
||||
auto item = token->enqueue_begin<moodycamel::CanAlloc>( magic );
|
||||
item->hdr.type = QueueType::ZoneName;
|
||||
item->zoneName.thread = m_thread;
|
||||
item->zoneName.name = (uint64_t)name;
|
||||
s_queue.enqueue_finish( token, magic );
|
||||
token->enqueue_finish( magic );
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -262,6 +262,8 @@ namespace details {
|
||||
} max_align_t;
|
||||
}
|
||||
|
||||
enum AllocationMode { CanAlloc, CannotAlloc };
|
||||
|
||||
// Default traits for the ConcurrentQueue. To change some of the
|
||||
// traits without re-implementing all of them, inherit from this
|
||||
// struct and shadow the declarations you wish to be different;
|
||||
@ -1287,7 +1289,6 @@ private:
|
||||
friend struct ExplicitProducer;
|
||||
friend class ConcurrentQueueTests;
|
||||
|
||||
enum AllocationMode { CanAlloc, CannotAlloc };
|
||||
|
||||
|
||||
///////////////////////////////
|
||||
@ -1717,10 +1718,10 @@ private:
|
||||
};
|
||||
|
||||
|
||||
public:
|
||||
///////////////////////////
|
||||
// Explicit queue
|
||||
///////////////////////////
|
||||
|
||||
struct ExplicitProducer : public ProducerBase
|
||||
{
|
||||
explicit ExplicitProducer(ConcurrentQueue* parent) :
|
||||
@ -2447,6 +2448,12 @@ private:
|
||||
#endif
|
||||
};
|
||||
|
||||
ExplicitProducer* get_explicit_producer(producer_token_t const& token)
|
||||
{
|
||||
return static_cast<ExplicitProducer*>(token.producer);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
//////////////////////////////////
|
||||
// Implicit queue
|
||||
|
Loading…
Reference in New Issue
Block a user