Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update tracy client bindings to v0.10 #76

Merged
merged 1 commit into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.mkd
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,5 @@ The following table lists the version correspondence between the libraries.
| v0.9 | 0.19.0 | 0.15.0 | 0.10.1 |
| v0.9.1 | 0.21.0 | 0.15.2 | 0.10.2 |
| v0.9.1 | 0.21.0 | 0.16.0 | 0.10.3 |
| v0.10 | 0.22.0 | 0.16.4 | 0.10.4 |
<!-- AUTO-UPDATE -->
2 changes: 1 addition & 1 deletion tracy-client-sys/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "tracy-client-sys"
version = "0.21.2" # AUTO-BUMP
version = "0.22.0" # AUTO-BUMP
authors = ["Simonas Kazlauskas <tracy-client-sys@kazlauskas.me>"]
build = "build.rs"
license = "(MIT OR Apache-2.0) AND BSD-3-Clause"
Expand Down
14 changes: 14 additions & 0 deletions tracy-client-sys/src/generated.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
pub const TracyPlotFormatEnum_TracyPlotFormatNumber: TracyPlotFormatEnum = 0;
pub const TracyPlotFormatEnum_TracyPlotFormatMemory: TracyPlotFormatEnum = 1;
pub const TracyPlotFormatEnum_TracyPlotFormatPercentage: TracyPlotFormatEnum = 2;
pub const TracyPlotFormatEnum_TracyPlotFormatWatt: TracyPlotFormatEnum = 3;
type TracyPlotFormatEnum = ::std::os::raw::c_uint;
extern "C" {
pub fn ___tracy_set_thread_name(name: *const ::std::os::raw::c_char);
}
Expand Down Expand Up @@ -765,6 +770,15 @@ extern "C" {
extern "C" {
pub fn ___tracy_emit_plot_int(name: *const ::std::os::raw::c_char, val: i64);
}
extern "C" {
pub fn ___tracy_emit_plot_config(
name: *const ::std::os::raw::c_char,
type_: ::std::os::raw::c_int,
step: ::std::os::raw::c_int,
fill: ::std::os::raw::c_int,
color: u32,
);
}
extern "C" {
pub fn ___tracy_emit_message_appinfo(txt: *const ::std::os::raw::c_char, size: usize);
}
1 change: 1 addition & 0 deletions tracy-client-sys/tracy/TracyClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "common/tracy_lz4.cpp"
#include "client/TracyProfiler.cpp"
#include "client/TracyCallstack.cpp"
#include "client/TracySysPower.cpp"
#include "client/TracySysTime.cpp"
#include "client/TracySysTrace.cpp"
#include "common/TracySocket.cpp"
Expand Down
4 changes: 4 additions & 0 deletions tracy-client-sys/tracy/client/TracyCallstack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,9 @@ void InitCallstackCritical()
void InitCallstack()
{
cb_bts = backtrace_create_state( nullptr, 0, nullptr, nullptr );
#ifndef TRACY_DEMANGLE
___tracy_init_demangle_buffer();
#endif

#ifdef __linux
InitKernelSymbols();
Expand Down Expand Up @@ -761,7 +763,9 @@ debuginfod_client* GetDebuginfodClient()

void EndCallstack()
{
#ifndef TRACY_DEMANGLE
___tracy_free_demangle_buffer();
#endif
#ifdef TRACY_DEBUGINFOD
ClearDebugInfoVector( s_di_known );
debuginfod_end( s_debuginfod );
Expand Down
8 changes: 4 additions & 4 deletions tracy-client-sys/tracy/client/TracyLock.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class LockableCtx
, m_active( false )
#endif
{
assert( m_id != std::numeric_limits<uint32_t>::max() );
assert( m_id != (std::numeric_limits<uint32_t>::max)() );

auto item = Profiler::QueueSerial();
MemWrite( &item->hdr.type, QueueType::LockAnnounce );
Expand Down Expand Up @@ -154,7 +154,7 @@ class LockableCtx

tracy_force_inline void CustomName( const char* name, size_t size )
{
assert( size < std::numeric_limits<uint16_t>::max() );
assert( size < (std::numeric_limits<uint16_t>::max)() );
auto ptr = (char*)tracy_malloc( size );
memcpy( ptr, name, size );
auto item = Profiler::QueueSerial();
Expand Down Expand Up @@ -235,7 +235,7 @@ class SharedLockableCtx
, m_active( false )
#endif
{
assert( m_id != std::numeric_limits<uint32_t>::max() );
assert( m_id != (std::numeric_limits<uint32_t>::max)() );

auto item = Profiler::QueueSerial();
MemWrite( &item->hdr.type, QueueType::LockAnnounce );
Expand Down Expand Up @@ -450,7 +450,7 @@ class SharedLockableCtx

tracy_force_inline void CustomName( const char* name, size_t size )
{
assert( size < std::numeric_limits<uint16_t>::max() );
assert( size < (std::numeric_limits<uint16_t>::max)() );
auto ptr = (char*)tracy_malloc( size );
memcpy( ptr, name, size );
auto item = Profiler::QueueSerial();
Expand Down
32 changes: 26 additions & 6 deletions tracy-client-sys/tracy/client/TracyProfiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@
#endif

#ifdef __APPLE__
# define TRACY_DELAYED_INIT
# ifndef TRACY_DELAYED_INIT
# define TRACY_DELAYED_INIT
# endif
#else
# ifdef __GNUC__
# define init_order( val ) __attribute__ ((init_priority(val)))
Expand Down Expand Up @@ -1072,7 +1074,9 @@ static void CrashHandler( int signal, siginfo_t* info, void* /*ucontext*/ )
}
closedir( dp );

#ifdef TRACY_HAS_CALLSTACK
if( selfTid == s_symbolTid ) s_symbolThreadGone.store( true, std::memory_order_release );
#endif

TracyLfqPrepare( QueueType::Crash );
TracyLfqCommit;
Expand Down Expand Up @@ -1353,6 +1357,7 @@ Profiler::Profiler()
, m_queryImage( nullptr )
, m_queryData( nullptr )
, m_crashHandlerInstalled( false )
, m_programName( nullptr )
{
assert( !s_instance );
s_instance = this;
Expand Down Expand Up @@ -1711,13 +1716,24 @@ void Profiler::Worker()
if( m_sock ) break;
#ifndef TRACY_ON_DEMAND
ProcessSysTime();
# ifdef TRACY_HAS_SYSPOWER
m_sysPower.Tick();
# endif
#endif

if( m_broadcast )
{
const auto t = std::chrono::high_resolution_clock::now().time_since_epoch().count();
if( t - lastBroadcast > 3000000000 ) // 3s
{
m_programNameLock.lock();
if( m_programName )
{
broadcastMsg = GetBroadcastMessage( m_programName, strlen( m_programName ), broadcastLen, dataPort );
m_programName = nullptr;
}
m_programNameLock.unlock();

lastBroadcast = t;
const auto ts = std::chrono::duration_cast<std::chrono::seconds>( std::chrono::system_clock::now().time_since_epoch() ).count();
broadcastMsg.activeTime = int32_t( ts - m_epoch );
Expand Down Expand Up @@ -1828,6 +1844,9 @@ void Profiler::Worker()
for(;;)
{
ProcessSysTime();
#ifdef TRACY_HAS_SYSPOWER
m_sysPower.Tick();
#endif
const auto status = Dequeue( token );
const auto serialStatus = DequeueSerial();
if( status == DequeueStatus::ConnectionLost || serialStatus == DequeueStatus::ConnectionLost )
Expand Down Expand Up @@ -4149,6 +4168,7 @@ TRACY_API void ___tracy_emit_frame_image( const void* image, uint16_t w, uint16_
TRACY_API void ___tracy_emit_plot( const char* name, double val ) { tracy::Profiler::PlotData( name, val ); }
TRACY_API void ___tracy_emit_plot_float( const char* name, float val ) { tracy::Profiler::PlotData( name, val ); }
TRACY_API void ___tracy_emit_plot_int( const char* name, int64_t val ) { tracy::Profiler::PlotData( name, val ); }
TRACY_API void ___tracy_emit_plot_config( const char* name, int type, int step, int fill, uint32_t color ) { tracy::Profiler::ConfigurePlot( name, tracy::PlotFormatType(type), step, fill, color ); }
TRACY_API void ___tracy_emit_message( const char* txt, size_t size, int callstack ) { tracy::Profiler::Message( txt, size, callstack ); }
TRACY_API void ___tracy_emit_messageL( const char* txt, int callstack ) { tracy::Profiler::Message( txt, callstack ); }
TRACY_API void ___tracy_emit_messageC( const char* txt, size_t size, uint32_t color, int callstack ) { tracy::Profiler::MessageColor( txt, size, color, callstack ); }
Expand All @@ -4167,7 +4187,7 @@ TRACY_API void ___tracy_emit_gpu_zone_begin( const struct ___tracy_gpu_zone_begi
{
TracyLfqPrepareC( tracy::QueueType::GpuZoneBegin );
tracy::MemWrite( &item->gpuZoneBegin.cpuTime, tracy::Profiler::GetTime() );
tracy::MemWrite( &item->gpuNewContext.thread, tracy::GetThreadHandle() );
tracy::MemWrite( &item->gpuZoneBegin.thread, tracy::GetThreadHandle() );
tracy::MemWrite( &item->gpuZoneBegin.srcloc, data.srcloc );
tracy::MemWrite( &item->gpuZoneBegin.queryId, data.queryId );
tracy::MemWrite( &item->gpuZoneBegin.context, data.context );
Expand All @@ -4190,7 +4210,7 @@ TRACY_API void ___tracy_emit_gpu_zone_begin_alloc( const struct ___tracy_gpu_zon
{
TracyLfqPrepareC( tracy::QueueType::GpuZoneBeginAllocSrcLoc );
tracy::MemWrite( &item->gpuZoneBegin.cpuTime, tracy::Profiler::GetTime() );
tracy::MemWrite( &item->gpuNewContext.thread, tracy::GetThreadHandle() );
tracy::MemWrite( &item->gpuZoneBegin.thread, tracy::GetThreadHandle() );
tracy::MemWrite( &item->gpuZoneBegin.srcloc, data.srcloc );
tracy::MemWrite( &item->gpuZoneBegin.queryId, data.queryId );
tracy::MemWrite( &item->gpuZoneBegin.context, data.context );
Expand All @@ -4202,7 +4222,7 @@ TRACY_API void ___tracy_emit_gpu_zone_begin_alloc_callstack( const struct ___tra
tracy::GetProfiler().SendCallstack( data.depth );
TracyLfqPrepareC( tracy::QueueType::GpuZoneBeginAllocSrcLocCallstack );
tracy::MemWrite( &item->gpuZoneBegin.cpuTime, tracy::Profiler::GetTime() );
tracy::MemWrite( &item->gpuNewContext.thread, tracy::GetThreadHandle() );
tracy::MemWrite( &item->gpuZoneBegin.thread, tracy::GetThreadHandle() );
tracy::MemWrite( &item->gpuZoneBegin.srcloc, data.srcloc );
tracy::MemWrite( &item->gpuZoneBegin.queryId, data.queryId );
tracy::MemWrite( &item->gpuZoneBegin.context, data.context );
Expand Down Expand Up @@ -4292,7 +4312,7 @@ TRACY_API void ___tracy_emit_gpu_zone_begin_alloc_serial( const struct ___tracy_
auto item = tracy::Profiler::QueueSerial();
tracy::MemWrite( &item->hdr.type, tracy::QueueType::GpuZoneBeginAllocSrcLocSerial );
tracy::MemWrite( &item->gpuZoneBegin.cpuTime, tracy::Profiler::GetTime() );
tracy::MemWrite( &item->gpuNewContext.thread, tracy::GetThreadHandle() );
tracy::MemWrite( &item->gpuZoneBegin.thread, tracy::GetThreadHandle() );
tracy::MemWrite( &item->gpuZoneBegin.srcloc, data.srcloc );
tracy::MemWrite( &item->gpuZoneBegin.queryId, data.queryId );
tracy::MemWrite( &item->gpuZoneBegin.context, data.context );
Expand All @@ -4304,7 +4324,7 @@ TRACY_API void ___tracy_emit_gpu_zone_begin_alloc_callstack_serial( const struct
auto item = tracy::Profiler::QueueSerialCallstack( tracy::Callstack( data.depth ) );
tracy::MemWrite( &item->hdr.type, tracy::QueueType::GpuZoneBeginAllocSrcLocCallstackSerial );
tracy::MemWrite( &item->gpuZoneBegin.cpuTime, tracy::Profiler::GetTime() );
tracy::MemWrite( &item->gpuNewContext.thread, tracy::GetThreadHandle() );
tracy::MemWrite( &item->gpuZoneBegin.thread, tracy::GetThreadHandle() );
tracy::MemWrite( &item->gpuZoneBegin.srcloc, data.srcloc );
tracy::MemWrite( &item->gpuZoneBegin.queryId, data.queryId );
tracy::MemWrite( &item->gpuZoneBegin.context, data.context );
Expand Down
46 changes: 41 additions & 5 deletions tracy-client-sys/tracy/client/TracyProfiler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "tracy_concurrentqueue.h"
#include "tracy_SPSCQueue.h"
#include "TracyCallstack.hpp"
#include "TracySysPower.hpp"
#include "TracySysTime.hpp"
#include "TracyFastVector.hpp"
#include "../common/TracyQueue.hpp"
Expand Down Expand Up @@ -208,7 +209,22 @@ class Profiler
if( HardwareSupportsInvariantTSC() )
{
uint64_t rax, rdx;
#ifdef TRACY_PATCHABLE_NOPSLEDS
// Some external tooling (such as rr) wants to patch our rdtsc and replace it by a
// branch to control the external input seen by a program. This kind of patching is
// not generally possible depending on the surrounding code and can lead to significant
// slowdowns if the compiler generated unlucky code and rr and tracy are used together.
// To avoid this, use the rr-safe `nopl 0(%rax, %rax, 1); rdtsc` instruction sequence,
// which rr promises will be patchable independent of the surrounding code.
asm volatile (
// This is nopl 0(%rax, %rax, 1), but assemblers are inconsistent about whether
// they emit that as a 4 or 5 byte sequence and we need to be guaranteed to use
// the 5 byte one.
".byte 0x0f, 0x1f, 0x44, 0x00, 0x00\n\t"
"rdtsc" : "=a" (rax), "=d" (rdx) );
#else
asm volatile ( "rdtsc" : "=a" (rax), "=d" (rdx) );
#endif
return (int64_t)(( rdx << 32 ) + rax);
}
# else
Expand Down Expand Up @@ -288,7 +304,7 @@ class Profiler
{
#ifndef TRACY_NO_FRAME_IMAGE
auto& profiler = GetProfiler();
assert( profiler.m_frameCount.load( std::memory_order_relaxed ) < std::numeric_limits<uint32_t>::max() );
assert( profiler.m_frameCount.load( std::memory_order_relaxed ) < (std::numeric_limits<uint32_t>::max)() );
# ifdef TRACY_ON_DEMAND
if( !profiler.IsConnected() ) return;
# endif
Expand All @@ -305,6 +321,12 @@ class Profiler
fi->flip = flip;
profiler.m_fiQueue.commit_next();
profiler.m_fiLock.unlock();
#else
static_cast<void>(image); // unused
static_cast<void>(w); // unused
static_cast<void>(h); // unused
static_cast<void>(offset); // unused
static_cast<void>(flip); // unused
#endif
}

Expand Down Expand Up @@ -362,7 +384,7 @@ class Profiler

static tracy_force_inline void Message( const char* txt, size_t size, int callstack )
{
assert( size < std::numeric_limits<uint16_t>::max() );
assert( size < (std::numeric_limits<uint16_t>::max)() );
#ifdef TRACY_ON_DEMAND
if( !GetProfiler().IsConnected() ) return;
#endif
Expand Down Expand Up @@ -399,7 +421,7 @@ class Profiler

static tracy_force_inline void MessageColor( const char* txt, size_t size, uint32_t color, int callstack )
{
assert( size < std::numeric_limits<uint16_t>::max() );
assert( size < (std::numeric_limits<uint16_t>::max)() );
#ifdef TRACY_ON_DEMAND
if( !GetProfiler().IsConnected() ) return;
#endif
Expand Down Expand Up @@ -442,7 +464,7 @@ class Profiler

static tracy_force_inline void MessageAppInfo( const char* txt, size_t size )
{
assert( size < std::numeric_limits<uint16_t>::max() );
assert( size < (std::numeric_limits<uint16_t>::max)() );
auto ptr = (char*)tracy_malloc( size );
memcpy( ptr, txt, size );
TracyLfqPrepare( QueueType::MessageAppInfo );
Expand Down Expand Up @@ -676,6 +698,13 @@ class Profiler
return m_isConnected.load( std::memory_order_acquire );
}

tracy_force_inline void SetProgramName( const char* name )
{
m_programNameLock.lock();
m_programName = name;
m_programNameLock.unlock();
}

#ifdef TRACY_ON_DEMAND
tracy_force_inline uint64_t ConnectionId() const
{
Expand Down Expand Up @@ -730,7 +759,7 @@ class Profiler
static tracy_force_inline uint64_t AllocSourceLocation( uint32_t line, const char* source, size_t sourceSz, const char* function, size_t functionSz, const char* name, size_t nameSz )
{
const auto sz32 = uint32_t( 2 + 4 + 4 + functionSz + 1 + sourceSz + 1 + nameSz );
assert( sz32 <= std::numeric_limits<uint16_t>::max() );
assert( sz32 <= (std::numeric_limits<uint16_t>::max)() );
const auto sz = uint16_t( sz32 );
auto ptr = (char*)tracy_malloc( sz );
memcpy( ptr, &sz, 2 );
Expand Down Expand Up @@ -941,6 +970,10 @@ class Profiler
void ProcessSysTime() {}
#endif

#ifdef TRACY_HAS_SYSPOWER
SysPower m_sysPower;
#endif

ParameterCallback m_paramCallback;
void* m_paramCallbackData;
SourceContentsCallback m_sourceCallback;
Expand All @@ -959,6 +992,9 @@ class Profiler
} m_prevSignal;
#endif
bool m_crashHandlerInstalled;

const char* m_programName;
TracyMutex m_programNameLock;
};

}
Expand Down
4 changes: 2 additions & 2 deletions tracy-client-sys/tracy/client/TracyScoped.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class ScopedZone

tracy_force_inline void Text( const char* txt, size_t size )
{
assert( size < std::numeric_limits<uint16_t>::max() );
assert( size < (std::numeric_limits<uint16_t>::max)() );
if( !m_active ) return;
#ifdef TRACY_ON_DEMAND
if( GetProfiler().ConnectionId() != m_connectionId ) return;
Expand All @@ -123,7 +123,7 @@ class ScopedZone

tracy_force_inline void Name( const char* txt, size_t size )
{
assert( size < std::numeric_limits<uint16_t>::max() );
assert( size < (std::numeric_limits<uint16_t>::max)() );
if( !m_active ) return;
#ifdef TRACY_ON_DEMAND
if( GetProfiler().ConnectionId() != m_connectionId ) return;
Expand Down
Loading
Loading