diff --git a/manual/tracy.tex b/manual/tracy.tex index 6939f078..6ce4c0e0 100644 --- a/manual/tracy.tex +++ b/manual/tracy.tex @@ -804,6 +804,8 @@ Suppose for some reason you want to use another port\footnote{For example, other If a custom port is not specified and the default listening port is already occupied, the profiler will automatically try to listen on a number of other ports. +Since the port in use may differ from the default one, the client application may query the actual data connection port using the \texttt{TracyPort} macro. It returns the port number once the listening socket has been bound, or zero otherwise. + \begin{bclogo}[ noborder=true, couleur=black!5, diff --git a/public/client/TracyProfiler.cpp b/public/client/TracyProfiler.cpp index 58b6b4e4..b52991e5 100644 --- a/public/client/TracyProfiler.cpp +++ b/public/client/TracyProfiler.cpp @@ -1552,6 +1552,7 @@ Profiler::Profiler() , m_broadcast( nullptr ) , m_noExit( false ) , m_userPort( 0 ) + , m_dataPort( 0 ) , m_zoneId( 1 ) , m_sectionId( 1 ) , m_samplingPeriod( 0 ) @@ -1955,6 +1956,7 @@ void Profiler::Worker() std::this_thread::sleep_for( std::chrono::milliseconds( 10 ) ); } } + m_dataPort.store( dataPort, std::memory_order_release ); #ifndef TRACY_NO_BROADCAST m_broadcast = (UdpBroadcast*)tracy_malloc( sizeof( UdpBroadcast ) ); diff --git a/public/client/TracyProfiler.hpp b/public/client/TracyProfiler.hpp index 9689921a..215741bf 100644 --- a/public/client/TracyProfiler.hpp +++ b/public/client/TracyProfiler.hpp @@ -914,6 +914,12 @@ public: return m_isConnected.load( std::memory_order_acquire ); } + // Returns 0 until the listen socket is bound + tracy_force_inline uint32_t GetPort() const + { + return m_dataPort.load( std::memory_order_acquire ); + } + tracy_force_inline void SetProgramName( const char* name ) { m_programNameLock.lock(); @@ -1175,6 +1181,7 @@ private: UdpBroadcast* m_broadcast; bool m_noExit; uint32_t m_userPort; + std::atomic m_dataPort; std::atomic m_zoneId; std::atomic m_sectionId; int64_t m_samplingPeriod; diff --git a/public/tracy/Tracy.hpp b/public/tracy/Tracy.hpp index b8f12b6b..08d13cac 100644 --- a/public/tracy/Tracy.hpp +++ b/public/tracy/Tracy.hpp @@ -115,6 +115,7 @@ #define TracyParameterRegister(x,y) #define TracyParameterSetup(x,y,z,w) #define TracyIsConnected false +#define TracyPort 0 #define TracyIsStarted false #define TracySetProgramName(x) @@ -258,6 +259,7 @@ #define TracyParameterRegister( cb, data ) tracy::Profiler::ParameterRegister( cb, data ) #define TracyParameterSetup( idx, name, type, val ) tracy::Profiler::ParameterSetup( idx, name, type, val ) #define TracyIsConnected tracy::GetProfiler().IsConnected() +#define TracyPort tracy::GetProfiler().GetPort() #define TracySetProgramName( name ) tracy::GetProfiler().SetProgramName( name ) #define TracySectionEnter( fmt, ... ) tracy::Profiler::SectionEnter( 0, fmt, ##__VA_ARGS__ )