Add allocated srcloc zone begin emit functions to C API.

This commit is contained in:
Bartosz Taudul 2019-12-06 00:22:49 +01:00
parent 68ff33d0ba
commit 399b87fecc
2 changed files with 76 additions and 0 deletions

View File

@ -81,6 +81,8 @@ typedef /*const*/ struct ___tracy_c_zone_context TracyCZoneCtx;
TRACY_API TracyCZoneCtx ___tracy_emit_zone_begin( const struct ___tracy_source_location_data* srcloc, int active ); TRACY_API TracyCZoneCtx ___tracy_emit_zone_begin( const struct ___tracy_source_location_data* srcloc, int active );
TRACY_API TracyCZoneCtx ___tracy_emit_zone_begin_callstack( const struct ___tracy_source_location_data* srcloc, int depth, int active ); TRACY_API TracyCZoneCtx ___tracy_emit_zone_begin_callstack( const struct ___tracy_source_location_data* srcloc, int depth, int active );
TRACY_API TracyCZoneCtx ___tracy_emit_zone_begin_alloc( uint64_t srcloc, int active );
TRACY_API TracyCZoneCtx ___tracy_emit_zone_begin_alloc_callstack( uint64_t srcloc, int depth, int active );
TRACY_API void ___tracy_emit_zone_end( TracyCZoneCtx ctx ); TRACY_API void ___tracy_emit_zone_end( TracyCZoneCtx ctx );
TRACY_API void ___tracy_emit_zone_text( TracyCZoneCtx ctx, const char* txt, size_t size ); TRACY_API void ___tracy_emit_zone_text( TracyCZoneCtx ctx, const char* txt, size_t size );
TRACY_API void ___tracy_emit_zone_name( TracyCZoneCtx ctx, const char* txt, size_t size ); TRACY_API void ___tracy_emit_zone_name( TracyCZoneCtx ctx, const char* txt, size_t size );

View File

@ -2767,6 +2767,80 @@ TRACY_API TracyCZoneCtx ___tracy_emit_zone_begin_callstack( const struct ___trac
return ctx; return ctx;
} }
TRACY_API TracyCZoneCtx ___tracy_emit_zone_begin_alloc( uint64_t srcloc, int active )
{
___tracy_c_zone_context ctx;
#ifdef TRACY_ON_DEMAND
ctx.active = active && tracy::GetProfiler().IsConnected();
#else
ctx.active = active;
#endif
if( !ctx.active ) return ctx;
const auto id = tracy::GetProfiler().GetNextZoneId();
ctx.id = id;
#ifndef TRACY_NO_VERIFY
{
tracy::Magic magic;
auto token = tracy::GetToken();
auto& tail = token->get_tail_index();
auto item = token->enqueue_begin( magic );
tracy::MemWrite( &item->hdr.type, tracy::QueueType::ZoneValidation );
tracy::MemWrite( &item->zoneValidation.id, id );
tail.store( magic + 1, std::memory_order_release );
}
#endif
{
tracy::Magic magic;
auto token = tracy::GetToken();
auto& tail = token->get_tail_index();
auto item = token->enqueue_begin( magic );
tracy::MemWrite( &item->hdr.type, tracy::QueueType::ZoneBeginAllocSrcLoc );
tracy::MemWrite( &item->zoneBegin.time, tracy::Profiler::GetTime() );
tracy::MemWrite( &item->zoneBegin.srcloc, srcloc );
tail.store( magic + 1, std::memory_order_release );
}
return ctx;
}
TRACY_API TracyCZoneCtx ___tracy_emit_zone_begin_alloc_callstack( uint64_t srcloc, int depth, int active )
{
___tracy_c_zone_context ctx;
#ifdef TRACY_ON_DEMAND
ctx.active = active && tracy::GetProfiler().IsConnected();
#else
ctx.active = active;
#endif
if( !ctx.active ) return ctx;
const auto id = tracy::GetProfiler().GetNextZoneId();
ctx.id = id;
#ifndef TRACY_NO_VERIFY
{
tracy::Magic magic;
auto token = tracy::GetToken();
auto& tail = token->get_tail_index();
auto item = token->enqueue_begin( magic );
tracy::MemWrite( &item->hdr.type, tracy::QueueType::ZoneValidation );
tracy::MemWrite( &item->zoneValidation.id, id );
tail.store( magic + 1, std::memory_order_release );
}
#endif
{
tracy::Magic magic;
auto token = tracy::GetToken();
auto& tail = token->get_tail_index();
auto item = token->enqueue_begin( magic );
tracy::MemWrite( &item->hdr.type, tracy::QueueType::ZoneBeginAllocSrcLocCallstack );
tracy::MemWrite( &item->zoneBegin.time, tracy::Profiler::GetTime() );
tracy::MemWrite( &item->zoneBegin.srcloc, srcloc );
tail.store( magic + 1, std::memory_order_release );
}
tracy::GetProfiler().SendCallstack( depth );
return ctx;
}
TRACY_API void ___tracy_emit_zone_end( TracyCZoneCtx ctx ) TRACY_API void ___tracy_emit_zone_end( TracyCZoneCtx ctx )
{ {
if( !ctx.active ) return; if( !ctx.active ) return;