Skip to content

Commit

Permalink
Merge pull request #957 from foxtran/feature/merge-calls-callstack
Browse files Browse the repository at this point in the history
Simplify API by decreasing a number of entry points
  • Loading branch information
wolfpld authored Jan 2, 2025
2 parents 3863664 + b9c7cd1 commit 8b0b234
Show file tree
Hide file tree
Showing 6 changed files with 290 additions and 353 deletions.
3 changes: 3 additions & 0 deletions public/client/TracyCallstack.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace tracy
{
static constexpr bool has_callstack() { return false; }
static tracy_force_inline void* Callstack( int /*depth*/ ) { return nullptr; }
}

Expand Down Expand Up @@ -38,6 +39,8 @@ static tracy_force_inline void* Callstack( int /*depth*/ ) { return nullptr; }
namespace tracy
{

static constexpr bool has_callstack() { return true; }

struct CallstackSymbolData
{
const char* file;
Expand Down
94 changes: 76 additions & 18 deletions public/client/TracyProfiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1474,7 +1474,7 @@ Profiler::Profiler()
#ifndef _WIN32
pipe(m_pipe);
# if defined __APPLE__ || defined BSD
// FreeBSD/XNU don't have F_SETPIPE_SZ, so use the default
// FreeBSD/XNU don't have F_SETPIPE_SZ, so use the default
m_pipeBufSize = 16384;
# else
m_pipeBufSize = (int)(ptrdiff_t)SafeSendBufferSize;
Expand Down Expand Up @@ -3161,7 +3161,7 @@ char* Profiler::SafeCopyProlog( const char* data, size_t size )
void Profiler::SafeCopyEpilog( char* buf )
{
if( buf != m_safeSendBuffer ) tracy_free( buf );

#ifndef NDEBUG
m_inUse.store( false );
#endif
Expand Down Expand Up @@ -4121,7 +4121,7 @@ void Profiler::HandleSymbolCodeQuery( uint64_t symbol, uint32_t size )
}
else
{
auto&& lambda = [ this, symbol ]( const char* buf, size_t size ) {
auto&& lambda = [ this, symbol ]( const char* buf, size_t size ) {
SendLongString( symbol, buf, size, QueueType::SymbolCode );
};

Expand Down Expand Up @@ -4295,13 +4295,17 @@ TRACY_API TracyCZoneCtx ___tracy_emit_zone_begin_callstack( const struct ___trac
TracyQueueCommitC( zoneValidationThread );
}
#endif
tracy::GetProfiler().SendCallstack( depth );
auto zoneQueue = tracy::QueueType::ZoneBegin;
if( depth > 0 && tracy::has_callstack() )
{
TracyQueuePrepareC( tracy::QueueType::ZoneBeginCallstack );
tracy::MemWrite( &item->zoneBegin.time, tracy::Profiler::GetTime() );
tracy::MemWrite( &item->zoneBegin.srcloc, (uint64_t)srcloc );
TracyQueueCommitC( zoneBeginThread );
tracy::GetProfiler().SendCallstack( depth );
zoneQueue = tracy::QueueType::ZoneBeginCallstack;
}
TracyQueuePrepareC( zoneQueue );
tracy::MemWrite( &item->zoneBegin.time, tracy::Profiler::GetTime() );
tracy::MemWrite( &item->zoneBegin.srcloc, (uint64_t)srcloc );
TracyQueueCommitC( zoneBeginThread );

return ctx;
}

Expand Down Expand Up @@ -4360,13 +4364,17 @@ TRACY_API TracyCZoneCtx ___tracy_emit_zone_begin_alloc_callstack( uint64_t srclo
TracyQueueCommitC( zoneValidationThread );
}
#endif
tracy::GetProfiler().SendCallstack( depth );
auto zoneQueue = tracy::QueueType::ZoneBeginAllocSrcLoc;
if( depth > 0 && tracy::has_callstack() )
{
TracyQueuePrepareC( tracy::QueueType::ZoneBeginAllocSrcLocCallstack );
tracy::MemWrite( &item->zoneBegin.time, tracy::Profiler::GetTime() );
tracy::MemWrite( &item->zoneBegin.srcloc, srcloc );
TracyQueueCommitC( zoneBeginThread );
tracy::GetProfiler().SendCallstack( depth );
zoneQueue = tracy::QueueType::ZoneBeginAllocSrcLocCallstack;
}
TracyQueuePrepareC( zoneQueue );
tracy::MemWrite( &item->zoneBegin.time, tracy::Profiler::GetTime() );
tracy::MemWrite( &item->zoneBegin.srcloc, srcloc );
TracyQueueCommitC( zoneBeginThread );

return ctx;
}

Expand Down Expand Up @@ -4465,15 +4473,65 @@ TRACY_API void ___tracy_emit_zone_value( TracyCZoneCtx ctx, uint64_t value )
}

TRACY_API void ___tracy_emit_memory_alloc( const void* ptr, size_t size, int secure ) { tracy::Profiler::MemAlloc( ptr, size, secure != 0 ); }
TRACY_API void ___tracy_emit_memory_alloc_callstack( const void* ptr, size_t size, int depth, int secure ) { tracy::Profiler::MemAllocCallstack( ptr, size, depth, secure != 0 ); }
TRACY_API void ___tracy_emit_memory_alloc_callstack( const void* ptr, size_t size, int depth, int secure )
{
if( depth > 0 && tracy::has_callstack() )
{
tracy::Profiler::MemAllocCallstack( ptr, size, depth, secure != 0 );
}
else
{
tracy::Profiler::MemAlloc( ptr, size, secure != 0 );
}
}
TRACY_API void ___tracy_emit_memory_free( const void* ptr, int secure ) { tracy::Profiler::MemFree( ptr, secure != 0 ); }
TRACY_API void ___tracy_emit_memory_free_callstack( const void* ptr, int depth, int secure ) { tracy::Profiler::MemFreeCallstack( ptr, depth, secure != 0 ); }
TRACY_API void ___tracy_emit_memory_free_callstack( const void* ptr, int depth, int secure )
{
if( depth > 0 && tracy::has_callstack() )
{
tracy::Profiler::MemFreeCallstack( ptr, depth, secure != 0 );
}
else
{
tracy::Profiler::MemFree( ptr, secure != 0 );
}
}
TRACY_API void ___tracy_emit_memory_discard( const char* name, int secure ) { tracy::Profiler::MemDiscard( name, secure != 0 ); }
TRACY_API void ___tracy_emit_memory_discard_callstack( const char* name, int secure, int depth ) { tracy::Profiler::MemDiscardCallstack( name, secure != 0, depth ); }
TRACY_API void ___tracy_emit_memory_discard_callstack( const char* name, int secure, int depth )
{
if( depth > 0 && tracy::has_callstack() )
{
tracy::Profiler::MemDiscardCallstack( name, secure != 0, depth );
}
else
{
tracy::Profiler::MemDiscard( name, secure != 0 );
}
}
TRACY_API void ___tracy_emit_memory_alloc_named( const void* ptr, size_t size, int secure, const char* name ) { tracy::Profiler::MemAllocNamed( ptr, size, secure != 0, name ); }
TRACY_API void ___tracy_emit_memory_alloc_callstack_named( const void* ptr, size_t size, int depth, int secure, const char* name ) { tracy::Profiler::MemAllocCallstackNamed( ptr, size, depth, secure != 0, name ); }
TRACY_API void ___tracy_emit_memory_alloc_callstack_named( const void* ptr, size_t size, int depth, int secure, const char* name )
{
if( depth > 0 && tracy::has_callstack() )
{
tracy::Profiler::MemAllocCallstackNamed( ptr, size, depth, secure != 0, name );
}
else
{
tracy::Profiler::MemAllocNamed( ptr, size, secure != 0, name );
}
}
TRACY_API void ___tracy_emit_memory_free_named( const void* ptr, int secure, const char* name ) { tracy::Profiler::MemFreeNamed( ptr, secure != 0, name ); }
TRACY_API void ___tracy_emit_memory_free_callstack_named( const void* ptr, int depth, int secure, const char* name ) { tracy::Profiler::MemFreeCallstackNamed( ptr, depth, secure != 0, name ); }
TRACY_API void ___tracy_emit_memory_free_callstack_named( const void* ptr, int depth, int secure, const char* name )
{
if( depth > 0 && tracy::has_callstack() )
{
tracy::Profiler::MemFreeCallstackNamed( ptr, depth, secure != 0, name );
}
else
{
tracy::Profiler::MemFreeNamed( ptr, secure != 0, name );
}
}
TRACY_API void ___tracy_emit_frame_mark( const char* name ) { tracy::Profiler::SendFrameMark( name ); }
TRACY_API void ___tracy_emit_frame_mark_start( const char* name ) { tracy::Profiler::SendFrameMark( name, tracy::QueueType::FrameMarkMsgStart ); }
TRACY_API void ___tracy_emit_frame_mark_end( const char* name ) { tracy::Profiler::SendFrameMark( name, tracy::QueueType::FrameMarkMsgEnd ); }
Expand Down
Loading

0 comments on commit 8b0b234

Please sign in to comment.