mirror of
https://github.com/wolfpld/tracy.git
synced 2024-11-27 00:04:35 +00:00
Send zone validation messages.
This is only performed for C API, as C++ scoped zones are always properly ordered, due to RAII. With manual submission of zone begin and end events there's no such guarantee.
This commit is contained in:
parent
970108fbbf
commit
8e52ab318b
@ -1752,21 +1752,34 @@ TracyCZoneCtx ___tracy_emit_zone_begin( const struct ___tracy_source_location_da
|
|||||||
ctx.active = active;
|
ctx.active = active;
|
||||||
#endif
|
#endif
|
||||||
if( !ctx.active ) return ctx;
|
if( !ctx.active ) return ctx;
|
||||||
|
const auto thread = tracy::GetThreadHandle();
|
||||||
|
const auto id = tracy::s_profiler.GetNextZoneId();
|
||||||
|
ctx.id = id;
|
||||||
|
|
||||||
tracy::Magic magic;
|
tracy::Magic magic;
|
||||||
auto& token = tracy::s_token.ptr;
|
auto& token = tracy::s_token.ptr;
|
||||||
auto& tail = token->get_tail_index();
|
auto& tail = token->get_tail_index();
|
||||||
auto item = token->enqueue_begin<tracy::moodycamel::CanAlloc>( magic );
|
{
|
||||||
tracy::MemWrite( &item->hdr.type, tracy::QueueType::ZoneBegin );
|
auto item = token->enqueue_begin<tracy::moodycamel::CanAlloc>( magic );
|
||||||
|
tracy::MemWrite( &item->hdr.type, tracy::QueueType::ZoneValidation );
|
||||||
|
tracy::MemWrite( &item->zoneValidation.thread, thread );
|
||||||
|
tracy::MemWrite( &item->zoneValidation.id, id );
|
||||||
|
tail.store( magic + 1, std::memory_order_release );
|
||||||
|
}
|
||||||
|
{
|
||||||
|
auto item = token->enqueue_begin<tracy::moodycamel::CanAlloc>( magic );
|
||||||
|
tracy::MemWrite( &item->hdr.type, tracy::QueueType::ZoneBegin );
|
||||||
#ifdef TRACY_RDTSCP_OPT
|
#ifdef TRACY_RDTSCP_OPT
|
||||||
tracy::MemWrite( &item->zoneBegin.time, tracy::Profiler::GetTime( item->zoneBegin.cpu ) );
|
tracy::MemWrite( &item->zoneBegin.time, tracy::Profiler::GetTime( item->zoneBegin.cpu ) );
|
||||||
#else
|
#else
|
||||||
uint32_t cpu;
|
uint32_t cpu;
|
||||||
tracy::MemWrite( &item->zoneBegin.time, tracy::Profiler::GetTime( cpu ) );
|
tracy::MemWrite( &item->zoneBegin.time, tracy::Profiler::GetTime( cpu ) );
|
||||||
tracy::MemWrite( &item->zoneBegin.cpu, cpu );
|
tracy::MemWrite( &item->zoneBegin.cpu, cpu );
|
||||||
#endif
|
#endif
|
||||||
tracy::MemWrite( &item->zoneBegin.thread, tracy::GetThreadHandle() );
|
tracy::MemWrite( &item->zoneBegin.thread, thread );
|
||||||
tracy::MemWrite( &item->zoneBegin.srcloc, (uint64_t)srcloc );
|
tracy::MemWrite( &item->zoneBegin.srcloc, (uint64_t)srcloc );
|
||||||
tail.store( magic + 1, std::memory_order_release );
|
tail.store( magic + 1, std::memory_order_release );
|
||||||
|
}
|
||||||
return ctx;
|
return ctx;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1780,21 +1793,33 @@ TracyCZoneCtx ___tracy_emit_zone_begin_callstack( const struct ___tracy_source_l
|
|||||||
#endif
|
#endif
|
||||||
if( !ctx.active ) return ctx;
|
if( !ctx.active ) return ctx;
|
||||||
const auto thread = tracy::GetThreadHandle();
|
const auto thread = tracy::GetThreadHandle();
|
||||||
|
const auto id = tracy::s_profiler.GetNextZoneId();
|
||||||
|
ctx.id = id;
|
||||||
|
|
||||||
tracy::Magic magic;
|
tracy::Magic magic;
|
||||||
auto& token = tracy::s_token.ptr;
|
auto& token = tracy::s_token.ptr;
|
||||||
auto& tail = token->get_tail_index();
|
auto& tail = token->get_tail_index();
|
||||||
auto item = token->enqueue_begin<tracy::moodycamel::CanAlloc>( magic );
|
{
|
||||||
tracy::MemWrite( &item->hdr.type, tracy::QueueType::ZoneBeginCallstack );
|
auto item = token->enqueue_begin<tracy::moodycamel::CanAlloc>( magic );
|
||||||
|
tracy::MemWrite( &item->hdr.type, tracy::QueueType::ZoneValidation );
|
||||||
|
tracy::MemWrite( &item->zoneValidation.thread, thread );
|
||||||
|
tracy::MemWrite( &item->zoneValidation.id, id );
|
||||||
|
tail.store( magic + 1, std::memory_order_release );
|
||||||
|
}
|
||||||
|
{
|
||||||
|
auto item = token->enqueue_begin<tracy::moodycamel::CanAlloc>( magic );
|
||||||
|
tracy::MemWrite( &item->hdr.type, tracy::QueueType::ZoneBeginCallstack );
|
||||||
#ifdef TRACY_RDTSCP_OPT
|
#ifdef TRACY_RDTSCP_OPT
|
||||||
tracy::MemWrite( &item->zoneBegin.time, tracy::Profiler::GetTime( item->zoneBegin.cpu ) );
|
tracy::MemWrite( &item->zoneBegin.time, tracy::Profiler::GetTime( item->zoneBegin.cpu ) );
|
||||||
#else
|
#else
|
||||||
uint32_t cpu;
|
uint32_t cpu;
|
||||||
tracy::MemWrite( &item->zoneBegin.time, tracy::Profiler::GetTime( cpu ) );
|
tracy::MemWrite( &item->zoneBegin.time, tracy::Profiler::GetTime( cpu ) );
|
||||||
tracy::MemWrite( &item->zoneBegin.cpu, cpu );
|
tracy::MemWrite( &item->zoneBegin.cpu, cpu );
|
||||||
#endif
|
#endif
|
||||||
tracy::MemWrite( &item->zoneBegin.thread, thread );
|
tracy::MemWrite( &item->zoneBegin.thread, thread );
|
||||||
tracy::MemWrite( &item->zoneBegin.srcloc, (uint64_t)srcloc );
|
tracy::MemWrite( &item->zoneBegin.srcloc, (uint64_t)srcloc );
|
||||||
tail.store( magic + 1, std::memory_order_release );
|
tail.store( magic + 1, std::memory_order_release );
|
||||||
|
}
|
||||||
|
|
||||||
tracy::s_profiler.SendCallstack( depth, thread );
|
tracy::s_profiler.SendCallstack( depth, thread );
|
||||||
return ctx;
|
return ctx;
|
||||||
@ -1803,20 +1828,30 @@ TracyCZoneCtx ___tracy_emit_zone_begin_callstack( const struct ___tracy_source_l
|
|||||||
void ___tracy_emit_zone_end( TracyCZoneCtx ctx )
|
void ___tracy_emit_zone_end( TracyCZoneCtx ctx )
|
||||||
{
|
{
|
||||||
if( !ctx.active ) return;
|
if( !ctx.active ) return;
|
||||||
|
const auto thread = tracy::GetThreadHandle();
|
||||||
tracy::Magic magic;
|
tracy::Magic magic;
|
||||||
auto& token = tracy::s_token.ptr;
|
auto& token = tracy::s_token.ptr;
|
||||||
auto& tail = token->get_tail_index();
|
auto& tail = token->get_tail_index();
|
||||||
auto item = token->enqueue_begin<tracy::moodycamel::CanAlloc>( magic );
|
{
|
||||||
tracy::MemWrite( &item->hdr.type, tracy::QueueType::ZoneEnd );
|
auto item = token->enqueue_begin<tracy::moodycamel::CanAlloc>( magic );
|
||||||
|
tracy::MemWrite( &item->hdr.type, tracy::QueueType::ZoneValidation );
|
||||||
|
tracy::MemWrite( &item->zoneValidation.thread, thread );
|
||||||
|
tracy::MemWrite( &item->zoneValidation.id, ctx.id );
|
||||||
|
tail.store( magic + 1, std::memory_order_release );
|
||||||
|
}
|
||||||
|
{
|
||||||
|
auto item = token->enqueue_begin<tracy::moodycamel::CanAlloc>( magic );
|
||||||
|
tracy::MemWrite( &item->hdr.type, tracy::QueueType::ZoneEnd );
|
||||||
#ifdef TRACY_RDTSCP_OPT
|
#ifdef TRACY_RDTSCP_OPT
|
||||||
tracy::MemWrite( &item->zoneEnd.time, tracy::Profiler::GetTime( item->zoneEnd.cpu ) );
|
tracy::MemWrite( &item->zoneEnd.time, tracy::Profiler::GetTime( item->zoneEnd.cpu ) );
|
||||||
#else
|
#else
|
||||||
uint32_t cpu;
|
uint32_t cpu;
|
||||||
tracy::MemWrite( &item->zoneEnd.time, tracy::Profiler::GetTime( cpu ) );
|
tracy::MemWrite( &item->zoneEnd.time, tracy::Profiler::GetTime( cpu ) );
|
||||||
tracy::MemWrite( &item->zoneEnd.cpu, cpu );
|
tracy::MemWrite( &item->zoneEnd.cpu, cpu );
|
||||||
#endif
|
#endif
|
||||||
tracy::MemWrite( &item->zoneEnd.thread, tracy::GetThreadHandle() );
|
tracy::MemWrite( &item->zoneEnd.thread, thread );
|
||||||
tail.store( magic + 1, std::memory_order_release );
|
tail.store( magic + 1, std::memory_order_release );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
Loading…
Reference in New Issue
Block a user