1
0
mirror of https://github.com/wolfpld/tracy.git synced 2025-03-20 07:40:02 +08:00

Move TLS accesses close together.

This commit is contained in:
Bartosz Taudul
2019-06-24 19:38:44 +02:00
parent c4f0965851
commit 06a41708a7
6 changed files with 55 additions and 33 deletions
+16 -8
View File
@@ -124,12 +124,13 @@ public:
#endif
Magic magic;
const auto thread = GetThreadHandle();
auto token = GetToken();
auto& tail = token->get_tail_index();
auto item = token->enqueue_begin<tracy::moodycamel::CanAlloc>( magic );
MemWrite( &item->hdr.type, QueueType::LockRelease );
MemWrite( &item->lockRelease.id, m_id );
MemWrite( &item->lockRelease.thread, GetThreadHandle() );
MemWrite( &item->lockRelease.thread, thread );
MemWrite( &item->lockRelease.time, Profiler::GetTime() );
tail.store( magic + 1, std::memory_order_release );
}
@@ -156,12 +157,13 @@ public:
if( ret )
{
Magic magic;
const auto thread = GetThreadHandle();
auto token = GetToken();
auto& tail = token->get_tail_index();
auto item = token->enqueue_begin<tracy::moodycamel::CanAlloc>( magic );
MemWrite( &item->hdr.type, QueueType::LockObtain );
MemWrite( &item->lockObtain.id, m_id );
MemWrite( &item->lockObtain.thread, GetThreadHandle() );
MemWrite( &item->lockObtain.thread, thread );
MemWrite( &item->lockObtain.time, Profiler::GetTime() );
tail.store( magic + 1, std::memory_order_release );
}
@@ -183,12 +185,13 @@ public:
#endif
Magic magic;
const auto thread = GetThreadHandle();
auto token = GetToken();
auto& tail = token->get_tail_index();
auto item = token->enqueue_begin<tracy::moodycamel::CanAlloc>( magic );
MemWrite( &item->hdr.type, QueueType::LockMark );
MemWrite( &item->lockMark.id, m_id );
MemWrite( &item->lockMark.thread, GetThreadHandle() );
MemWrite( &item->lockMark.thread, thread );
MemWrite( &item->lockMark.srcloc, (uint64_t)srcloc );
tail.store( magic + 1, std::memory_order_release );
}
@@ -317,12 +320,13 @@ public:
#endif
Magic magic;
const auto thread = GetThreadHandle();
auto token = GetToken();
auto& tail = token->get_tail_index();
auto item = token->enqueue_begin<tracy::moodycamel::CanAlloc>( magic );
MemWrite( &item->hdr.type, QueueType::LockRelease );
MemWrite( &item->lockRelease.id, m_id );
MemWrite( &item->lockRelease.thread, GetThreadHandle() );
MemWrite( &item->lockRelease.thread, thread );
MemWrite( &item->lockRelease.time, Profiler::GetTime() );
tail.store( magic + 1, std::memory_order_release );
}
@@ -349,12 +353,13 @@ public:
if( ret )
{
Magic magic;
const auto thread = GetThreadHandle();
auto token = GetToken();
auto& tail = token->get_tail_index();
auto item = token->enqueue_begin<tracy::moodycamel::CanAlloc>( magic );
MemWrite( &item->hdr.type, QueueType::LockObtain );
MemWrite( &item->lockObtain.id, m_id );
MemWrite( &item->lockObtain.thread, GetThreadHandle() );
MemWrite( &item->lockObtain.thread, thread );
MemWrite( &item->lockObtain.time, Profiler::GetTime() );
tail.store( magic + 1, std::memory_order_release );
}
@@ -424,12 +429,13 @@ public:
#endif
Magic magic;
const auto thread = GetThreadHandle();
auto token = GetToken();
auto& tail = token->get_tail_index();
auto item = token->enqueue_begin<tracy::moodycamel::CanAlloc>( magic );
MemWrite( &item->hdr.type, QueueType::LockSharedRelease );
MemWrite( &item->lockRelease.id, m_id );
MemWrite( &item->lockRelease.thread, GetThreadHandle() );
MemWrite( &item->lockRelease.thread, thread );
MemWrite( &item->lockRelease.time, Profiler::GetTime() );
tail.store( magic + 1, std::memory_order_release );
}
@@ -456,12 +462,13 @@ public:
if( ret )
{
Magic magic;
const auto thread = GetThreadHandle();
auto token = GetToken();
auto& tail = token->get_tail_index();
auto item = token->enqueue_begin<tracy::moodycamel::CanAlloc>( magic );
MemWrite( &item->hdr.type, QueueType::LockSharedObtain );
MemWrite( &item->lockObtain.id, m_id );
MemWrite( &item->lockObtain.thread, GetThreadHandle() );
MemWrite( &item->lockObtain.thread, thread );
MemWrite( &item->lockObtain.time, Profiler::GetTime() );
tail.store( magic + 1, std::memory_order_release );
}
@@ -483,12 +490,13 @@ public:
#endif
Magic magic;
const auto thread = GetThreadHandle();
auto token = GetToken();
auto& tail = token->get_tail_index();
auto item = token->enqueue_begin<tracy::moodycamel::CanAlloc>( magic );
MemWrite( &item->hdr.type, QueueType::LockMark );
MemWrite( &item->lockMark.id, m_id );
MemWrite( &item->lockMark.thread, GetThreadHandle() );
MemWrite( &item->lockMark.thread, thread );
MemWrite( &item->lockMark.srcloc, (uint64_t)srcloc );
tail.store( magic + 1, std::memory_order_release );
}
+7 -7
View File
@@ -492,8 +492,8 @@ LONG WINAPI CrashFilter( PEXCEPTION_POINTERS pExp )
}
{
const auto thread = GetThreadHandle();
Magic magic;
const auto thread = GetThreadHandle();
auto token = GetToken();
auto& tail = token->get_tail_index();
auto item = token->enqueue_begin<tracy::moodycamel::CanAlloc>( magic );
@@ -730,8 +730,8 @@ static void CrashHandler( int signal, siginfo_t* info, void* /*ucontext*/ )
}
{
const auto thread = GetThreadHandle();
Magic magic;
const auto thread = GetThreadHandle();
auto token = GetToken();
auto& tail = token->get_tail_index();
auto item = token->enqueue_begin<tracy::moodycamel::CanAlloc>( magic );
@@ -2065,11 +2065,11 @@ TracyCZoneCtx ___tracy_emit_zone_begin( const struct ___tracy_source_location_da
ctx.active = active;
#endif
if( !ctx.active ) return ctx;
const auto thread = tracy::GetThreadHandle();
const auto id = tracy::GetProfiler().GetNextZoneId();
ctx.id = id;
tracy::Magic magic;
const auto thread = tracy::GetThreadHandle();
auto token = tracy::GetToken();
auto& tail = token->get_tail_index();
#ifndef TRACY_NO_VERIFY
@@ -2107,11 +2107,11 @@ TracyCZoneCtx ___tracy_emit_zone_begin_callstack( const struct ___tracy_source_l
ctx.active = active;
#endif
if( !ctx.active ) return ctx;
const auto thread = tracy::GetThreadHandle();
const auto id = tracy::GetProfiler().GetNextZoneId();
ctx.id = id;
tracy::Magic magic;
const auto thread = tracy::GetThreadHandle();
auto token = tracy::GetToken();
auto& tail = token->get_tail_index();
#ifndef TRACY_NO_VERIFY
@@ -2145,8 +2145,8 @@ TracyCZoneCtx ___tracy_emit_zone_begin_callstack( const struct ___tracy_source_l
void ___tracy_emit_zone_end( TracyCZoneCtx ctx )
{
if( !ctx.active ) return;
const auto thread = tracy::GetThreadHandle();
tracy::Magic magic;
const auto thread = tracy::GetThreadHandle();
auto token = tracy::GetToken();
auto& tail = token->get_tail_index();
#ifndef TRACY_NO_VERIFY
@@ -2176,8 +2176,8 @@ void ___tracy_emit_zone_end( TracyCZoneCtx ctx )
void ___tracy_emit_zone_text( TracyCZoneCtx ctx, const char* txt, size_t size )
{
if( !ctx.active ) return;
const auto thread = tracy::GetThreadHandle();
tracy::Magic magic;
const auto thread = tracy::GetThreadHandle();
auto token = tracy::GetToken();
auto ptr = (char*)tracy::tracy_malloc( size+1 );
memcpy( ptr, txt, size );
@@ -2204,8 +2204,8 @@ void ___tracy_emit_zone_text( TracyCZoneCtx ctx, const char* txt, size_t size )
void ___tracy_emit_zone_name( TracyCZoneCtx ctx, const char* txt, size_t size )
{
if( !ctx.active ) return;
const auto thread = tracy::GetThreadHandle();
tracy::Magic magic;
const auto thread = tracy::GetThreadHandle();
auto token = tracy::GetToken();
auto ptr = (char*)tracy::tracy_malloc( size+1 );
memcpy( ptr, txt, size );
+8 -4
View File
@@ -251,6 +251,7 @@ public:
if( !GetProfiler().IsConnected() ) return;
#endif
Magic magic;
const auto thread = GetThreadHandle();
auto token = GetToken();
auto ptr = (char*)tracy_malloc( size+1 );
memcpy( ptr, txt, size );
@@ -259,7 +260,7 @@ public:
auto item = token->enqueue_begin<tracy::moodycamel::CanAlloc>( magic );
MemWrite( &item->hdr.type, QueueType::Message );
MemWrite( &item->message.time, GetTime() );
MemWrite( &item->message.thread, GetThreadHandle() );
MemWrite( &item->message.thread, thread );
MemWrite( &item->message.text, (uint64_t)ptr );
tail.store( magic + 1, std::memory_order_release );
}
@@ -270,12 +271,13 @@ public:
if( !GetProfiler().IsConnected() ) return;
#endif
Magic magic;
const auto thread = GetThreadHandle();
auto token = GetToken();
auto& tail = token->get_tail_index();
auto item = token->enqueue_begin<tracy::moodycamel::CanAlloc>( magic );
MemWrite( &item->hdr.type, QueueType::MessageLiteral );
MemWrite( &item->message.time, GetTime() );
MemWrite( &item->message.thread, GetThreadHandle() );
MemWrite( &item->message.thread, thread );
MemWrite( &item->message.text, (uint64_t)txt );
tail.store( magic + 1, std::memory_order_release );
}
@@ -286,6 +288,7 @@ public:
if( !GetProfiler().IsConnected() ) return;
#endif
Magic magic;
const auto thread = GetThreadHandle();
auto token = GetToken();
auto ptr = (char*)tracy_malloc( size+1 );
memcpy( ptr, txt, size );
@@ -294,7 +297,7 @@ public:
auto item = token->enqueue_begin<tracy::moodycamel::CanAlloc>( magic );
MemWrite( &item->hdr.type, QueueType::MessageColor );
MemWrite( &item->messageColor.time, GetTime() );
MemWrite( &item->messageColor.thread, GetThreadHandle() );
MemWrite( &item->messageColor.thread, thread );
MemWrite( &item->messageColor.text, (uint64_t)ptr );
MemWrite( &item->messageColor.r, uint8_t( ( color ) & 0xFF ) );
MemWrite( &item->messageColor.g, uint8_t( ( color >> 8 ) & 0xFF ) );
@@ -308,12 +311,13 @@ public:
if( !GetProfiler().IsConnected() ) return;
#endif
Magic magic;
const auto thread = GetThreadHandle();
auto token = GetToken();
auto& tail = token->get_tail_index();
auto item = token->enqueue_begin<tracy::moodycamel::CanAlloc>( magic );
MemWrite( &item->hdr.type, QueueType::MessageLiteralColor );
MemWrite( &item->messageColor.time, GetTime() );
MemWrite( &item->messageColor.thread, GetThreadHandle() );
MemWrite( &item->messageColor.thread, thread );
MemWrite( &item->messageColor.text, (uint64_t)txt );
MemWrite( &item->messageColor.r, uint8_t( ( color ) & 0xFF ) );
MemWrite( &item->messageColor.g, uint8_t( ( color >> 8 ) & 0xFF ) );