Allow changing tracy port in client.

This commit is contained in:
Bartosz Taudul 2019-09-21 15:11:15 +02:00
parent 140654961c
commit e13cbf52fd
3 changed files with 21 additions and 9 deletions

View File

@ -1156,6 +1156,12 @@ void Profiler::Worker()
SetThreadName( "Tracy Profiler" ); SetThreadName( "Tracy Profiler" );
#ifdef TRACY_PORT
const auto port = TRACY_PORT;
#else
const auto port = 8086;
#endif
while( m_timeBegin.load( std::memory_order_relaxed ) == 0 ) std::this_thread::sleep_for( std::chrono::milliseconds( 10 ) ); while( m_timeBegin.load( std::memory_order_relaxed ) == 0 ) std::this_thread::sleep_for( std::chrono::milliseconds( 10 ) );
rpmalloc_thread_initialize(); rpmalloc_thread_initialize();
@ -1198,7 +1204,7 @@ void Profiler::Worker()
moodycamel::ConsumerToken token( GetQueue() ); moodycamel::ConsumerToken token( GetQueue() );
ListenSocket listen; ListenSocket listen;
if( !listen.Listen( "8086", 8 ) ) if( !listen.Listen( port, 8 ) )
{ {
for(;;) for(;;)
{ {
@ -1215,7 +1221,7 @@ void Profiler::Worker()
#ifndef TRACY_NO_BROADCAST #ifndef TRACY_NO_BROADCAST
m_broadcast = (UdpBroadcast*)tracy_malloc( sizeof( UdpBroadcast ) ); m_broadcast = (UdpBroadcast*)tracy_malloc( sizeof( UdpBroadcast ) );
new(m_broadcast) UdpBroadcast(); new(m_broadcast) UdpBroadcast();
if( !m_broadcast->Open( "255.255.255.255", "8086" ) ) if( !m_broadcast->Open( "255.255.255.255", port ) )
{ {
m_broadcast->~UdpBroadcast(); m_broadcast->~UdpBroadcast();
tracy_free( m_broadcast ); tracy_free( m_broadcast );
@ -1256,7 +1262,7 @@ void Profiler::Worker()
lastBroadcast = t; lastBroadcast = t;
const auto ts = std::chrono::duration_cast<std::chrono::seconds>( std::chrono::system_clock::now().time_since_epoch() ).count(); const auto ts = std::chrono::duration_cast<std::chrono::seconds>( std::chrono::system_clock::now().time_since_epoch() ).count();
broadcastMsg.activeTime = uint32_t( ts - m_epoch ); broadcastMsg.activeTime = uint32_t( ts - m_epoch );
m_broadcast->Send( 8086, &broadcastMsg, broadcastLen ); m_broadcast->Send( port, &broadcastMsg, broadcastLen );
} }
} }
} }

View File

@ -279,7 +279,7 @@ ListenSocket::~ListenSocket()
if( m_sock != -1 ) Close(); if( m_sock != -1 ) Close();
} }
bool ListenSocket::Listen( const char* port, int backlog ) bool ListenSocket::Listen( int port, int backlog )
{ {
assert( m_sock == -1 ); assert( m_sock == -1 );
@ -291,7 +291,10 @@ bool ListenSocket::Listen( const char* port, int backlog )
hints.ai_socktype = SOCK_STREAM; hints.ai_socktype = SOCK_STREAM;
hints.ai_flags = AI_PASSIVE; hints.ai_flags = AI_PASSIVE;
if( getaddrinfo( nullptr, port, &hints, &res ) != 0 ) return false; char portbuf[32];
sprintf( portbuf, "%i", port );
if( getaddrinfo( nullptr, portbuf, &hints, &res ) != 0 ) return false;
m_sock = socket( res->ai_family, res->ai_socktype, res->ai_protocol ); m_sock = socket( res->ai_family, res->ai_socktype, res->ai_protocol );
#if defined _WIN32 || defined __CYGWIN__ #if defined _WIN32 || defined __CYGWIN__
@ -359,7 +362,7 @@ UdpBroadcast::~UdpBroadcast()
if( m_sock != -1 ) Close(); if( m_sock != -1 ) Close();
} }
bool UdpBroadcast::Open( const char* addr, const char* port ) bool UdpBroadcast::Open( const char* addr, int port )
{ {
assert( m_sock == -1 ); assert( m_sock == -1 );
@ -370,7 +373,10 @@ bool UdpBroadcast::Open( const char* addr, const char* port )
hints.ai_family = AF_INET; hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_DGRAM; hints.ai_socktype = SOCK_DGRAM;
if( getaddrinfo( addr, port, &hints, &res ) != 0 ) return false; char portbuf[32];
sprintf( portbuf, "%i", port );
if( getaddrinfo( addr, portbuf, &hints, &res ) != 0 ) return false;
int sock = 0; int sock = 0;
for( ptr = res; ptr; ptr = ptr->ai_next ) for( ptr = res; ptr; ptr = ptr->ai_next )
{ {

View File

@ -52,7 +52,7 @@ public:
ListenSocket(); ListenSocket();
~ListenSocket(); ~ListenSocket();
bool Listen( const char* port, int backlog ); bool Listen( int port, int backlog );
Socket* Accept(); Socket* Accept();
void Close(); void Close();
@ -71,7 +71,7 @@ public:
UdpBroadcast(); UdpBroadcast();
~UdpBroadcast(); ~UdpBroadcast();
bool Open( const char* addr, const char* port ); bool Open( const char* addr, int port );
void Close(); void Close();
int Send( int port, const void* data, int len ); int Send( int port, const void* data, int len );