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