Skip to content

Commit 7996682

Browse files
committed
Update tracy version to 0.1
1 parent 9eb85f8 commit 7996682

27 files changed

+1369
-866
lines changed

external/sources/tracy/meson.build

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
project('tracy', ['cpp'])
1+
project('tracy', ['cpp'], version: '0.10.0')
22

33
if get_option('tracy_enable')
44
add_project_arguments('-DTRACY_ENABLE', language : 'cpp')
@@ -64,6 +64,10 @@ if get_option('tracy_no_system_tracing')
6464
add_project_arguments('-DTRACY_NO_SYSTEM_TRACING', language : 'cpp')
6565
endif
6666

67+
if get_option('tracy_patchable_nopsleds')
68+
add_project_arguments('-DTRACY_PATCHABLE_NOPSLEDS', language : 'cpp')
69+
endif
70+
6771
if get_option('tracy_delayed_init')
6872
add_project_arguments('-DTRACY_DELAYED_INIT', language : 'cpp')
6973
endif
@@ -161,18 +165,17 @@ if tracy_shared_libs
161165
include_directories : tracy_public_include_dirs,
162166
override_options : override_options,
163167
install : true)
164-
install_headers(includes)
165-
install_headers(common_includes, subdir : 'common')
166-
install_headers(client_includes, subdir : 'client')
167168
else
168169
tracy = static_library('tracy', tracy_src, tracy_header_files,
169170
dependencies : [ threads_dep ],
170171
include_directories : tracy_public_include_dirs,
171172
override_options : override_options,
172-
install : false)
173+
install : true)
173174
endif
174175

175-
176+
install_headers(includes)
177+
install_headers(common_includes, subdir : 'common')
178+
install_headers(client_includes, subdir : 'client')
176179

177180
tracy_dep_compile_args = []
178181

external/sources/tracy/meson_options.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
option('tracy_enable', type : 'boolean', yield: true, value : true, description : 'Enable profiling')
2-
option('tracy_on_demand', type : 'boolean', value : false, yield: true, description : 'On-demand profiling')
3-
option('tracy_callstack', type : 'boolean', value : false, yield: true, description : 'Enfore callstack collection for tracy regions')
1+
option('tracy_enable', type : 'boolean', value : true, description : 'Enable profiling')
2+
option('tracy_on_demand', type : 'boolean', value : false, description : 'On-demand profiling')
3+
option('tracy_callstack', type : 'boolean', value : false, description : 'Enfore callstack collection for tracy regions')
44
option('tracy_no_callstack', type : 'boolean', value : false, description : 'Disable all callstack related functionality')
55
option('tracy_no_callstack_inlines', type : 'boolean', value : false, description : 'Disables the inline functions in callstacks')
66
option('tracy_only_localhost', type : 'boolean', value : false, description : 'Only listen on the localhost interface')
@@ -14,6 +14,7 @@ option('tracy_no_verify', type : 'boolean', value : false, description : 'Disabl
1414
option('tracy_no_vsync_capture', type : 'boolean', value : false, description : 'Disable capture of hardware Vsync events')
1515
option('tracy_no_frame_image', type : 'boolean', value : false, description : 'Disable the frame image support and its thread')
1616
option('tracy_no_system_tracing', type : 'boolean', value : false, description : 'Disable systrace sampling')
17+
option('tracy_patchable_nopsleds', type : 'boolean', value : false, description : 'Enable nopsleds for efficient patching by system-level tools (e.g. rr)')
1718
option('tracy_timer_fallback', type : 'boolean', value : false, description : 'Use lower resolution timers')
1819
option('tracy_delayed_init', type : 'boolean', value : false, description : 'Enable delayed initialization of the library (init on first call)')
1920
option('tracy_manual_lifetime', type : 'boolean', value : false, description : 'Enable the manual lifetime management of the profile')

external/sources/tracy/public/TracyClient.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "common/tracy_lz4.cpp"
2323
#include "client/TracyProfiler.cpp"
2424
#include "client/TracyCallstack.cpp"
25+
#include "client/TracySysPower.cpp"
2526
#include "client/TracySysTime.cpp"
2627
#include "client/TracySysTrace.cpp"
2728
#include "common/TracySocket.cpp"

external/sources/tracy/public/client/TracyCallstack.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,9 @@ void InitCallstackCritical()
686686
void InitCallstack()
687687
{
688688
cb_bts = backtrace_create_state( nullptr, 0, nullptr, nullptr );
689+
#ifndef TRACY_DEMANGLE
689690
___tracy_init_demangle_buffer();
691+
#endif
690692

691693
#ifdef __linux
692694
InitKernelSymbols();
@@ -761,7 +763,9 @@ debuginfod_client* GetDebuginfodClient()
761763

762764
void EndCallstack()
763765
{
766+
#ifndef TRACY_DEMANGLE
764767
___tracy_free_demangle_buffer();
768+
#endif
765769
#ifdef TRACY_DEBUGINFOD
766770
ClearDebugInfoVector( s_di_known );
767771
debuginfod_end( s_debuginfod );

external/sources/tracy/public/client/TracyLock.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class LockableCtx
2121
, m_active( false )
2222
#endif
2323
{
24-
assert( m_id != std::numeric_limits<uint32_t>::max() );
24+
assert( m_id != (std::numeric_limits<uint32_t>::max)() );
2525

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

155155
tracy_force_inline void CustomName( const char* name, size_t size )
156156
{
157-
assert( size < std::numeric_limits<uint16_t>::max() );
157+
assert( size < (std::numeric_limits<uint16_t>::max)() );
158158
auto ptr = (char*)tracy_malloc( size );
159159
memcpy( ptr, name, size );
160160
auto item = Profiler::QueueSerial();
@@ -235,7 +235,7 @@ class SharedLockableCtx
235235
, m_active( false )
236236
#endif
237237
{
238-
assert( m_id != std::numeric_limits<uint32_t>::max() );
238+
assert( m_id != (std::numeric_limits<uint32_t>::max)() );
239239

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

451451
tracy_force_inline void CustomName( const char* name, size_t size )
452452
{
453-
assert( size < std::numeric_limits<uint16_t>::max() );
453+
assert( size < (std::numeric_limits<uint16_t>::max)() );
454454
auto ptr = (char*)tracy_malloc( size );
455455
memcpy( ptr, name, size );
456456
auto item = Profiler::QueueSerial();

external/sources/tracy/public/client/TracyProfiler.cpp

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@
8383
#endif
8484

8585
#ifdef __APPLE__
86-
# define TRACY_DELAYED_INIT
86+
# ifndef TRACY_DELAYED_INIT
87+
# define TRACY_DELAYED_INIT
88+
# endif
8789
#else
8890
# ifdef __GNUC__
8991
# define init_order( val ) __attribute__ ((init_priority(val)))
@@ -1072,7 +1074,9 @@ static void CrashHandler( int signal, siginfo_t* info, void* /*ucontext*/ )
10721074
}
10731075
closedir( dp );
10741076

1077+
#ifdef TRACY_HAS_CALLSTACK
10751078
if( selfTid == s_symbolTid ) s_symbolThreadGone.store( true, std::memory_order_release );
1079+
#endif
10761080

10771081
TracyLfqPrepare( QueueType::Crash );
10781082
TracyLfqCommit;
@@ -1353,6 +1357,7 @@ Profiler::Profiler()
13531357
, m_queryImage( nullptr )
13541358
, m_queryData( nullptr )
13551359
, m_crashHandlerInstalled( false )
1360+
, m_programName( nullptr )
13561361
{
13571362
assert( !s_instance );
13581363
s_instance = this;
@@ -1711,13 +1716,24 @@ void Profiler::Worker()
17111716
if( m_sock ) break;
17121717
#ifndef TRACY_ON_DEMAND
17131718
ProcessSysTime();
1719+
# ifdef TRACY_HAS_SYSPOWER
1720+
m_sysPower.Tick();
1721+
# endif
17141722
#endif
17151723

17161724
if( m_broadcast )
17171725
{
17181726
const auto t = std::chrono::high_resolution_clock::now().time_since_epoch().count();
17191727
if( t - lastBroadcast > 3000000000 ) // 3s
17201728
{
1729+
m_programNameLock.lock();
1730+
if( m_programName )
1731+
{
1732+
broadcastMsg = GetBroadcastMessage( m_programName, strlen( m_programName ), broadcastLen, dataPort );
1733+
m_programName = nullptr;
1734+
}
1735+
m_programNameLock.unlock();
1736+
17211737
lastBroadcast = t;
17221738
const auto ts = std::chrono::duration_cast<std::chrono::seconds>( std::chrono::system_clock::now().time_since_epoch() ).count();
17231739
broadcastMsg.activeTime = int32_t( ts - m_epoch );
@@ -1828,6 +1844,9 @@ void Profiler::Worker()
18281844
for(;;)
18291845
{
18301846
ProcessSysTime();
1847+
#ifdef TRACY_HAS_SYSPOWER
1848+
m_sysPower.Tick();
1849+
#endif
18311850
const auto status = Dequeue( token );
18321851
const auto serialStatus = DequeueSerial();
18331852
if( status == DequeueStatus::ConnectionLost || serialStatus == DequeueStatus::ConnectionLost )
@@ -4149,6 +4168,7 @@ TRACY_API void ___tracy_emit_frame_image( const void* image, uint16_t w, uint16_
41494168
TRACY_API void ___tracy_emit_plot( const char* name, double val ) { tracy::Profiler::PlotData( name, val ); }
41504169
TRACY_API void ___tracy_emit_plot_float( const char* name, float val ) { tracy::Profiler::PlotData( name, val ); }
41514170
TRACY_API void ___tracy_emit_plot_int( const char* name, int64_t val ) { tracy::Profiler::PlotData( name, val ); }
4171+
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 ); }
41524172
TRACY_API void ___tracy_emit_message( const char* txt, size_t size, int callstack ) { tracy::Profiler::Message( txt, size, callstack ); }
41534173
TRACY_API void ___tracy_emit_messageL( const char* txt, int callstack ) { tracy::Profiler::Message( txt, callstack ); }
41544174
TRACY_API void ___tracy_emit_messageC( const char* txt, size_t size, uint32_t color, int callstack ) { tracy::Profiler::MessageColor( txt, size, color, callstack ); }
@@ -4167,7 +4187,7 @@ TRACY_API void ___tracy_emit_gpu_zone_begin( const struct ___tracy_gpu_zone_begi
41674187
{
41684188
TracyLfqPrepareC( tracy::QueueType::GpuZoneBegin );
41694189
tracy::MemWrite( &item->gpuZoneBegin.cpuTime, tracy::Profiler::GetTime() );
4170-
tracy::MemWrite( &item->gpuNewContext.thread, tracy::GetThreadHandle() );
4190+
tracy::MemWrite( &item->gpuZoneBegin.thread, tracy::GetThreadHandle() );
41714191
tracy::MemWrite( &item->gpuZoneBegin.srcloc, data.srcloc );
41724192
tracy::MemWrite( &item->gpuZoneBegin.queryId, data.queryId );
41734193
tracy::MemWrite( &item->gpuZoneBegin.context, data.context );
@@ -4190,7 +4210,7 @@ TRACY_API void ___tracy_emit_gpu_zone_begin_alloc( const struct ___tracy_gpu_zon
41904210
{
41914211
TracyLfqPrepareC( tracy::QueueType::GpuZoneBeginAllocSrcLoc );
41924212
tracy::MemWrite( &item->gpuZoneBegin.cpuTime, tracy::Profiler::GetTime() );
4193-
tracy::MemWrite( &item->gpuNewContext.thread, tracy::GetThreadHandle() );
4213+
tracy::MemWrite( &item->gpuZoneBegin.thread, tracy::GetThreadHandle() );
41944214
tracy::MemWrite( &item->gpuZoneBegin.srcloc, data.srcloc );
41954215
tracy::MemWrite( &item->gpuZoneBegin.queryId, data.queryId );
41964216
tracy::MemWrite( &item->gpuZoneBegin.context, data.context );
@@ -4202,7 +4222,7 @@ TRACY_API void ___tracy_emit_gpu_zone_begin_alloc_callstack( const struct ___tra
42024222
tracy::GetProfiler().SendCallstack( data.depth );
42034223
TracyLfqPrepareC( tracy::QueueType::GpuZoneBeginAllocSrcLocCallstack );
42044224
tracy::MemWrite( &item->gpuZoneBegin.cpuTime, tracy::Profiler::GetTime() );
4205-
tracy::MemWrite( &item->gpuNewContext.thread, tracy::GetThreadHandle() );
4225+
tracy::MemWrite( &item->gpuZoneBegin.thread, tracy::GetThreadHandle() );
42064226
tracy::MemWrite( &item->gpuZoneBegin.srcloc, data.srcloc );
42074227
tracy::MemWrite( &item->gpuZoneBegin.queryId, data.queryId );
42084228
tracy::MemWrite( &item->gpuZoneBegin.context, data.context );
@@ -4292,7 +4312,7 @@ TRACY_API void ___tracy_emit_gpu_zone_begin_alloc_serial( const struct ___tracy_
42924312
auto item = tracy::Profiler::QueueSerial();
42934313
tracy::MemWrite( &item->hdr.type, tracy::QueueType::GpuZoneBeginAllocSrcLocSerial );
42944314
tracy::MemWrite( &item->gpuZoneBegin.cpuTime, tracy::Profiler::GetTime() );
4295-
tracy::MemWrite( &item->gpuNewContext.thread, tracy::GetThreadHandle() );
4315+
tracy::MemWrite( &item->gpuZoneBegin.thread, tracy::GetThreadHandle() );
42964316
tracy::MemWrite( &item->gpuZoneBegin.srcloc, data.srcloc );
42974317
tracy::MemWrite( &item->gpuZoneBegin.queryId, data.queryId );
42984318
tracy::MemWrite( &item->gpuZoneBegin.context, data.context );
@@ -4304,7 +4324,7 @@ TRACY_API void ___tracy_emit_gpu_zone_begin_alloc_callstack_serial( const struct
43044324
auto item = tracy::Profiler::QueueSerialCallstack( tracy::Callstack( data.depth ) );
43054325
tracy::MemWrite( &item->hdr.type, tracy::QueueType::GpuZoneBeginAllocSrcLocCallstackSerial );
43064326
tracy::MemWrite( &item->gpuZoneBegin.cpuTime, tracy::Profiler::GetTime() );
4307-
tracy::MemWrite( &item->gpuNewContext.thread, tracy::GetThreadHandle() );
4327+
tracy::MemWrite( &item->gpuZoneBegin.thread, tracy::GetThreadHandle() );
43084328
tracy::MemWrite( &item->gpuZoneBegin.srcloc, data.srcloc );
43094329
tracy::MemWrite( &item->gpuZoneBegin.queryId, data.queryId );
43104330
tracy::MemWrite( &item->gpuZoneBegin.context, data.context );

external/sources/tracy/public/client/TracyProfiler.hpp

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "tracy_concurrentqueue.h"
1111
#include "tracy_SPSCQueue.h"
1212
#include "TracyCallstack.hpp"
13+
#include "TracySysPower.hpp"
1314
#include "TracySysTime.hpp"
1415
#include "TracyFastVector.hpp"
1516
#include "../common/TracyQueue.hpp"
@@ -208,7 +209,22 @@ class Profiler
208209
if( HardwareSupportsInvariantTSC() )
209210
{
210211
uint64_t rax, rdx;
212+
#ifdef TRACY_PATCHABLE_NOPSLEDS
213+
// Some external tooling (such as rr) wants to patch our rdtsc and replace it by a
214+
// branch to control the external input seen by a program. This kind of patching is
215+
// not generally possible depending on the surrounding code and can lead to significant
216+
// slowdowns if the compiler generated unlucky code and rr and tracy are used together.
217+
// To avoid this, use the rr-safe `nopl 0(%rax, %rax, 1); rdtsc` instruction sequence,
218+
// which rr promises will be patchable independent of the surrounding code.
219+
asm volatile (
220+
// This is nopl 0(%rax, %rax, 1), but assemblers are inconsistent about whether
221+
// they emit that as a 4 or 5 byte sequence and we need to be guaranteed to use
222+
// the 5 byte one.
223+
".byte 0x0f, 0x1f, 0x44, 0x00, 0x00\n\t"
224+
"rdtsc" : "=a" (rax), "=d" (rdx) );
225+
#else
211226
asm volatile ( "rdtsc" : "=a" (rax), "=d" (rdx) );
227+
#endif
212228
return (int64_t)(( rdx << 32 ) + rax);
213229
}
214230
# else
@@ -288,7 +304,7 @@ class Profiler
288304
{
289305
#ifndef TRACY_NO_FRAME_IMAGE
290306
auto& profiler = GetProfiler();
291-
assert( profiler.m_frameCount.load( std::memory_order_relaxed ) < std::numeric_limits<uint32_t>::max() );
307+
assert( profiler.m_frameCount.load( std::memory_order_relaxed ) < (std::numeric_limits<uint32_t>::max)() );
292308
# ifdef TRACY_ON_DEMAND
293309
if( !profiler.IsConnected() ) return;
294310
# endif
@@ -305,6 +321,12 @@ class Profiler
305321
fi->flip = flip;
306322
profiler.m_fiQueue.commit_next();
307323
profiler.m_fiLock.unlock();
324+
#else
325+
static_cast<void>(image); // unused
326+
static_cast<void>(w); // unused
327+
static_cast<void>(h); // unused
328+
static_cast<void>(offset); // unused
329+
static_cast<void>(flip); // unused
308330
#endif
309331
}
310332

@@ -362,7 +384,7 @@ class Profiler
362384

363385
static tracy_force_inline void Message( const char* txt, size_t size, int callstack )
364386
{
365-
assert( size < std::numeric_limits<uint16_t>::max() );
387+
assert( size < (std::numeric_limits<uint16_t>::max)() );
366388
#ifdef TRACY_ON_DEMAND
367389
if( !GetProfiler().IsConnected() ) return;
368390
#endif
@@ -399,7 +421,7 @@ class Profiler
399421

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

443465
static tracy_force_inline void MessageAppInfo( const char* txt, size_t size )
444466
{
445-
assert( size < std::numeric_limits<uint16_t>::max() );
467+
assert( size < (std::numeric_limits<uint16_t>::max)() );
446468
auto ptr = (char*)tracy_malloc( size );
447469
memcpy( ptr, txt, size );
448470
TracyLfqPrepare( QueueType::MessageAppInfo );
@@ -676,6 +698,13 @@ class Profiler
676698
return m_isConnected.load( std::memory_order_acquire );
677699
}
678700

701+
tracy_force_inline void SetProgramName( const char* name )
702+
{
703+
m_programNameLock.lock();
704+
m_programName = name;
705+
m_programNameLock.unlock();
706+
}
707+
679708
#ifdef TRACY_ON_DEMAND
680709
tracy_force_inline uint64_t ConnectionId() const
681710
{
@@ -730,7 +759,7 @@ class Profiler
730759
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 )
731760
{
732761
const auto sz32 = uint32_t( 2 + 4 + 4 + functionSz + 1 + sourceSz + 1 + nameSz );
733-
assert( sz32 <= std::numeric_limits<uint16_t>::max() );
762+
assert( sz32 <= (std::numeric_limits<uint16_t>::max)() );
734763
const auto sz = uint16_t( sz32 );
735764
auto ptr = (char*)tracy_malloc( sz );
736765
memcpy( ptr, &sz, 2 );
@@ -941,6 +970,10 @@ class Profiler
941970
void ProcessSysTime() {}
942971
#endif
943972

973+
#ifdef TRACY_HAS_SYSPOWER
974+
SysPower m_sysPower;
975+
#endif
976+
944977
ParameterCallback m_paramCallback;
945978
void* m_paramCallbackData;
946979
SourceContentsCallback m_sourceCallback;
@@ -959,6 +992,9 @@ class Profiler
959992
} m_prevSignal;
960993
#endif
961994
bool m_crashHandlerInstalled;
995+
996+
const char* m_programName;
997+
TracyMutex m_programNameLock;
962998
};
963999

9641000
}

external/sources/tracy/public/client/TracyScoped.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ class ScopedZone
108108

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

124124
tracy_force_inline void Name( const char* txt, size_t size )
125125
{
126-
assert( size < std::numeric_limits<uint16_t>::max() );
126+
assert( size < (std::numeric_limits<uint16_t>::max)() );
127127
if( !m_active ) return;
128128
#ifdef TRACY_ON_DEMAND
129129
if( GetProfiler().ConnectionId() != m_connectionId ) return;

0 commit comments

Comments
 (0)