mirror of
https://github.com/wolfpld/tracy
synced 2025-04-29 04:23:51 +00:00
Add ZoneText and ZoneName to the C API.
This commit is contained in:
parent
49e270d8a6
commit
92f3a4bba0
8
TracyC.h
8
TracyC.h
@ -1,6 +1,7 @@
|
|||||||
#ifndef __TRACYC_HPP__
|
#ifndef __TRACYC_HPP__
|
||||||
#define __TRACYC_HPP__
|
#define __TRACYC_HPP__
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
@ -16,6 +17,8 @@ typedef const void* TracyCZoneCtx;
|
|||||||
#define TracyCZoneC(c,x,y)
|
#define TracyCZoneC(c,x,y)
|
||||||
#define TracyCZoneNC(c,x,y,z)
|
#define TracyCZoneNC(c,x,y,z)
|
||||||
#define TracyCZoneEnd(c)
|
#define TracyCZoneEnd(c)
|
||||||
|
#define TracyCZoneText(c,x,y)
|
||||||
|
#define TracyCZoneName(c,x,y)
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
@ -46,6 +49,8 @@ typedef const struct ___tracy_c_zone_context TracyCZoneCtx;
|
|||||||
TracyCZoneCtx ___tracy_emit_zone_begin( const struct ___tracy_source_location_data* srcloc, int active );
|
TracyCZoneCtx ___tracy_emit_zone_begin( const struct ___tracy_source_location_data* srcloc, int active );
|
||||||
TracyCZoneCtx ___tracy_emit_zone_begin_callstack( const struct ___tracy_source_location_data* srcloc, int depth, int active );
|
TracyCZoneCtx ___tracy_emit_zone_begin_callstack( const struct ___tracy_source_location_data* srcloc, int depth, int active );
|
||||||
void ___tracy_emit_zone_end( TracyCZoneCtx ctx );
|
void ___tracy_emit_zone_end( TracyCZoneCtx ctx );
|
||||||
|
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 defined TRACY_HAS_CALLSTACK && defined TRACY_CALLSTACK
|
#if defined TRACY_HAS_CALLSTACK && defined TRACY_CALLSTACK
|
||||||
# define TracyCZone( ctx, active ) static const struct ___tracy_source_location_data TracyConcat(__tracy_source_location,__LINE__) = { NULL, __FUNCTION__, __FILE__, (uint32_t)__LINE__, 0 }; TracyCZoneCtx ctx = ___tracy_emit_zone_begin_callstack( &TracyConcat(__tracy_source_location,__LINE__), TRACY_CALLSTACK, active );
|
# define TracyCZone( ctx, active ) static const struct ___tracy_source_location_data TracyConcat(__tracy_source_location,__LINE__) = { NULL, __FUNCTION__, __FILE__, (uint32_t)__LINE__, 0 }; TracyCZoneCtx ctx = ___tracy_emit_zone_begin_callstack( &TracyConcat(__tracy_source_location,__LINE__), TRACY_CALLSTACK, active );
|
||||||
@ -61,6 +66,9 @@ void ___tracy_emit_zone_end( TracyCZoneCtx ctx );
|
|||||||
|
|
||||||
#define TracyCZoneEnd( ctx ) ___tracy_emit_zone_end( ctx );
|
#define TracyCZoneEnd( ctx ) ___tracy_emit_zone_end( ctx );
|
||||||
|
|
||||||
|
#define TracyCZoneText( ctx, txt, size ) ___tracy_emit_zone_text( ctx, txt, size );
|
||||||
|
#define TracyCZoneName( ctx, txt, size ) ___tracy_emit_zone_name( ctx, txt, size );
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
@ -1860,6 +1860,62 @@ 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;
|
||||||
|
auto& token = tracy::s_token.ptr;
|
||||||
|
auto ptr = (char*)tracy::tracy_malloc( size+1 );
|
||||||
|
memcpy( ptr, txt, size );
|
||||||
|
ptr[size] = '\0';
|
||||||
|
auto& tail = token->get_tail_index();
|
||||||
|
#ifndef TRACY_NO_VERIFY
|
||||||
|
{
|
||||||
|
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 );
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
auto item = token->enqueue_begin<tracy::moodycamel::CanAlloc>( magic );
|
||||||
|
tracy::MemWrite( &item->hdr.type, tracy::QueueType::ZoneText );
|
||||||
|
tracy::MemWrite( &item->zoneText.thread, thread );
|
||||||
|
tracy::MemWrite( &item->zoneText.text, (uint64_t)ptr );
|
||||||
|
tail.store( magic + 1, std::memory_order_release );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
auto& token = tracy::s_token.ptr;
|
||||||
|
auto ptr = (char*)tracy::tracy_malloc( size+1 );
|
||||||
|
memcpy( ptr, txt, size );
|
||||||
|
ptr[size] = '\0';
|
||||||
|
auto& tail = token->get_tail_index();
|
||||||
|
#ifndef TRACY_NO_VERIFY
|
||||||
|
{
|
||||||
|
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 );
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
auto item = token->enqueue_begin<tracy::moodycamel::CanAlloc>( magic );
|
||||||
|
tracy::MemWrite( &item->hdr.type, tracy::QueueType::ZoneName );
|
||||||
|
tracy::MemWrite( &item->zoneText.thread, thread );
|
||||||
|
tracy::MemWrite( &item->zoneText.text, (uint64_t)ptr );
|
||||||
|
tail.store( magic + 1, std::memory_order_release );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -2339,6 +2339,20 @@ void Worker::ZoneEndFailure( uint64_t thread )
|
|||||||
m_failureData.srcloc = 0;
|
m_failureData.srcloc = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Worker::ZoneTextFailure( uint64_t thread )
|
||||||
|
{
|
||||||
|
m_failure = Failure::ZoneText;
|
||||||
|
m_failureData.thread = thread;
|
||||||
|
m_failureData.srcloc = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Worker::ZoneNameFailure( uint64_t thread )
|
||||||
|
{
|
||||||
|
m_failure = Failure::ZoneName;
|
||||||
|
m_failureData.thread = thread;
|
||||||
|
m_failureData.srcloc = 0;
|
||||||
|
}
|
||||||
|
|
||||||
void Worker::MemFreeFailure( uint64_t thread )
|
void Worker::MemFreeFailure( uint64_t thread )
|
||||||
{
|
{
|
||||||
m_failure = Failure::MemFree;
|
m_failure = Failure::MemFree;
|
||||||
@ -2414,11 +2428,15 @@ void Worker::ProcessFrameMarkEnd( const QueueFrameMark& ev )
|
|||||||
void Worker::ProcessZoneText( const QueueZoneText& ev )
|
void Worker::ProcessZoneText( const QueueZoneText& ev )
|
||||||
{
|
{
|
||||||
auto tit = m_threadMap.find( ev.thread );
|
auto tit = m_threadMap.find( ev.thread );
|
||||||
assert( tit != m_threadMap.end() );
|
if( tit == m_threadMap.end() || tit->second->stack.empty() || tit->second->nextZoneId != tit->second->zoneIdStack.back() )
|
||||||
|
{
|
||||||
|
ZoneTextFailure( ev.thread );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
auto td = tit->second;
|
auto td = tit->second;
|
||||||
|
td->nextZoneId = 0;
|
||||||
auto& stack = td->stack;
|
auto& stack = td->stack;
|
||||||
assert( !stack.empty() );
|
|
||||||
auto zone = stack.back();
|
auto zone = stack.back();
|
||||||
auto it = m_pendingCustomStrings.find( ev.text );
|
auto it = m_pendingCustomStrings.find( ev.text );
|
||||||
assert( it != m_pendingCustomStrings.end() );
|
assert( it != m_pendingCustomStrings.end() );
|
||||||
@ -2429,11 +2447,15 @@ void Worker::ProcessZoneText( const QueueZoneText& ev )
|
|||||||
void Worker::ProcessZoneName( const QueueZoneText& ev )
|
void Worker::ProcessZoneName( const QueueZoneText& ev )
|
||||||
{
|
{
|
||||||
auto tit = m_threadMap.find( ev.thread );
|
auto tit = m_threadMap.find( ev.thread );
|
||||||
assert( tit != m_threadMap.end() );
|
if( tit == m_threadMap.end() || tit->second->stack.empty() || tit->second->nextZoneId != tit->second->zoneIdStack.back() )
|
||||||
|
{
|
||||||
|
ZoneNameFailure( ev.thread );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
auto td = tit->second;
|
auto td = tit->second;
|
||||||
|
td->nextZoneId = 0;
|
||||||
auto& stack = td->stack;
|
auto& stack = td->stack;
|
||||||
assert( !stack.empty() );
|
|
||||||
auto zone = stack.back();
|
auto zone = stack.back();
|
||||||
auto it = m_pendingCustomStrings.find( ev.text );
|
auto it = m_pendingCustomStrings.find( ev.text );
|
||||||
assert( it != m_pendingCustomStrings.end() );
|
assert( it != m_pendingCustomStrings.end() );
|
||||||
@ -3666,6 +3688,8 @@ static const char* s_failureReasons[] = {
|
|||||||
"<unknown reason>",
|
"<unknown reason>",
|
||||||
"Invalid order of zone begin and end events.",
|
"Invalid order of zone begin and end events.",
|
||||||
"Received zone end event without a matching zone begin event.",
|
"Received zone end event without a matching zone begin event.",
|
||||||
|
"Zone text transfer destination doesn't match active zone.",
|
||||||
|
"Zone name transfer destination doesn't match active zone.",
|
||||||
"Memory free event without a matching allocation."
|
"Memory free event without a matching allocation."
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -182,6 +182,8 @@ public:
|
|||||||
None,
|
None,
|
||||||
ZoneStack,
|
ZoneStack,
|
||||||
ZoneEnd,
|
ZoneEnd,
|
||||||
|
ZoneText,
|
||||||
|
ZoneName,
|
||||||
MemFree,
|
MemFree,
|
||||||
|
|
||||||
NUM_FAILURES
|
NUM_FAILURES
|
||||||
@ -337,6 +339,8 @@ private:
|
|||||||
|
|
||||||
void ZoneStackFailure( uint64_t thread, const ZoneEvent* ev );
|
void ZoneStackFailure( uint64_t thread, const ZoneEvent* ev );
|
||||||
void ZoneEndFailure( uint64_t thread );
|
void ZoneEndFailure( uint64_t thread );
|
||||||
|
void ZoneTextFailure( uint64_t thread );
|
||||||
|
void ZoneNameFailure( uint64_t thread );
|
||||||
void MemFreeFailure( uint64_t thread );
|
void MemFreeFailure( uint64_t thread );
|
||||||
|
|
||||||
tracy_force_inline void CheckSourceLocation( uint64_t ptr );
|
tracy_force_inline void CheckSourceLocation( uint64_t ptr );
|
||||||
|
Loading…
x
Reference in New Issue
Block a user