diff --git a/capture/src/capture.cpp b/capture/src/capture.cpp index bfbf29a2..0e8106f7 100644 --- a/capture/src/capture.cpp +++ b/capture/src/capture.cpp @@ -30,7 +30,7 @@ void SigInt( int ) void Usage() { - printf( "Usage: capture -a address -o output.tracy\n" ); + printf( "Usage: capture -a address -o output.tracy [-p port]\n" ); exit( 1 ); } @@ -46,9 +46,10 @@ int main( int argc, char** argv ) const char* address = nullptr; const char* output = nullptr; + int port = 8086; int c; - while( ( c = getopt( argc, argv, "a:o:" ) ) != -1 ) + while( ( c = getopt( argc, argv, "a:o:p:" ) ) != -1 ) { switch( c ) { @@ -58,6 +59,9 @@ int main( int argc, char** argv ) case 'o': output = optarg; break; + case 'p': + port = atoi( optarg ); + break; default: Usage(); break; @@ -66,9 +70,9 @@ int main( int argc, char** argv ) if( !address || !output ) Usage(); - printf( "Connecting to %s...", address ); + printf( "Connecting to %s:%i...", address, port ); fflush( stdout ); - tracy::Worker worker( address ); + tracy::Worker worker( address, port ); while( !worker.IsConnected() ) { const auto handshake = worker.GetHandshakeStatus(); diff --git a/common/TracySocket.cpp b/common/TracySocket.cpp index 07f60869..fdf6c65a 100644 --- a/common/TracySocket.cpp +++ b/common/TracySocket.cpp @@ -86,7 +86,7 @@ Socket::~Socket() } } -bool Socket::Connect( const char* addr, const char* port ) +bool Socket::Connect( const char* addr, int port ) { assert( m_sock == -1 ); @@ -97,7 +97,10 @@ bool Socket::Connect( const char* addr, const char* port ) hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; - 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; for( ptr = res; ptr; ptr = ptr->ai_next ) { diff --git a/common/TracySocket.hpp b/common/TracySocket.hpp index 787e3d1f..789be00b 100644 --- a/common/TracySocket.hpp +++ b/common/TracySocket.hpp @@ -21,7 +21,7 @@ public: Socket( int sock ); ~Socket(); - bool Connect( const char* addr, const char* port ); + bool Connect( const char* addr, int port ); void Close(); int Send( const void* buf, int len ); diff --git a/profiler/src/ResolvService.cpp b/profiler/src/ResolvService.cpp index a60ccc2b..fd1d15fe 100644 --- a/profiler/src/ResolvService.cpp +++ b/profiler/src/ResolvService.cpp @@ -8,8 +8,9 @@ #include "ResolvService.hpp" -ResolvService::ResolvService() +ResolvService::ResolvService( int port ) : m_exit( false ) + , m_port( port ) , m_thread( [this] { Worker(); } ) { } @@ -32,7 +33,7 @@ void ResolvService::Worker() { struct sockaddr_in addr = {}; addr.sin_family = AF_INET; - addr.sin_port = 8086; + addr.sin_port = m_port; char buf[128]; diff --git a/profiler/src/ResolvService.hpp b/profiler/src/ResolvService.hpp index f75c13f4..a56e2462 100644 --- a/profiler/src/ResolvService.hpp +++ b/profiler/src/ResolvService.hpp @@ -19,7 +19,7 @@ class ResolvService }; public: - ResolvService(); + ResolvService( int port ); ~ResolvService(); void Query( uint32_t ip, const std::function& callback ); @@ -31,6 +31,7 @@ private: std::mutex m_lock; std::condition_variable m_cv; std::vector m_queue; + int m_port; std::thread m_thread; }; diff --git a/profiler/src/main.cpp b/profiler/src/main.cpp index 7a844ec5..20e25433 100644 --- a/profiler/src/main.cpp +++ b/profiler/src/main.cpp @@ -104,6 +104,9 @@ int main( int argc, char** argv ) std::unique_ptr view; tracy::BadVersionState badVer; + int port = 8086; + const char* connectTo = nullptr; + if( argc == 2 ) { auto f = std::unique_ptr( tracy::FileRead::Open( argv[1] ) ); @@ -112,9 +115,30 @@ int main( int argc, char** argv ) view = std::make_unique( *f ); } } - else if( argc == 3 && strcmp( argv[1], "-a" ) == 0 ) + else { - view = std::make_unique( argv[2] ); + while( argc >= 3 ) + { + if( strcmp( argv[1], "-a" ) == 0 ) + { + connectTo = argv[2]; + } + else if( strcmp( argv[1], "-p" ) == 0 ) + { + port = atoi( argv[2] ); + } + else + { + fprintf( stderr, "Bad parameter: %s", argv[1] ); + exit( 1 ); + } + argc -= 2; + argv += 2; + } + } + if( connectTo ) + { + view = std::make_unique( connectTo, port ); } char title[128]; @@ -261,7 +285,7 @@ int main( int argc, char** argv ) std::mutex resolvLock; tracy::flat_hash_map resolvMap; - ResolvService resolv; + ResolvService resolv( port ); glfwShowWindow( window ); @@ -296,7 +320,7 @@ int main( int argc, char** argv ) if( !broadcastListen ) { broadcastListen = std::make_unique(); - if( !broadcastListen->Listen( 8086 ) ) + if( !broadcastListen->Listen( port ) ) { broadcastListen.reset(); } @@ -456,7 +480,7 @@ int main( int argc, char** argv ) } connHistVec = RebuildConnectionHistory( connHistMap ); - view = std::make_unique( addr, fixedWidth, smallFont, bigFont, SetWindowTitleCallback ); + view = std::make_unique( addr, port, fixedWidth, smallFont, bigFont, SetWindowTitleCallback ); } ImGui::SameLine( 0, ImGui::GetFontSize() * 2 ); if( ImGui::Button( ICON_FA_FOLDER_OPEN " Open saved trace" ) && !loadThread.joinable() ) @@ -527,7 +551,7 @@ int main( int argc, char** argv ) if( badProto ) flags |= ImGuiSelectableFlags_Disabled; if( ImGui::Selectable( name->second.c_str(), &sel, flags ) && !loadThread.joinable() ) { - view = std::make_unique( v.second.address.c_str(), fixedWidth, smallFont, bigFont, SetWindowTitleCallback ); + view = std::make_unique( v.second.address.c_str(), port, fixedWidth, smallFont, bigFont, SetWindowTitleCallback ); } ImGui::NextColumn(); const auto acttime = ( v.second.activeTime + ( time - v.second.time ) / 1000 ) * 1000000000ll; diff --git a/server/TracyView.cpp b/server/TracyView.cpp index e97ca35a..a9caa657 100644 --- a/server/TracyView.cpp +++ b/server/TracyView.cpp @@ -110,8 +110,8 @@ enum { MinFrameSize = 5 }; static View* s_instance = nullptr; -View::View( const char* addr, ImFont* fixedWidth, ImFont* smallFont, ImFont* bigFont, SetTitleCallback stcb ) - : m_worker( addr ) +View::View( const char* addr, int port, ImFont* fixedWidth, ImFont* smallFont, ImFont* bigFont, SetTitleCallback stcb ) + : m_worker( addr, port ) , m_staticView( false ) , m_pause( false ) , m_frames( nullptr ) diff --git a/server/TracyView.hpp b/server/TracyView.hpp index 8b88cae9..38e6e262 100644 --- a/server/TracyView.hpp +++ b/server/TracyView.hpp @@ -63,8 +63,8 @@ public: using SetTitleCallback = void(*)( const char* ); - View( ImFont* fixedWidth = nullptr, ImFont* smallFont = nullptr, ImFont* bigFont = nullptr, SetTitleCallback stcb = nullptr ) : View( "127.0.0.1", fixedWidth, smallFont, bigFont, stcb ) {} - View( const char* addr, ImFont* fixedWidth = nullptr, ImFont* smallFont = nullptr, ImFont* bigFont = nullptr, SetTitleCallback stcb = nullptr ); + View( ImFont* fixedWidth = nullptr, ImFont* smallFont = nullptr, ImFont* bigFont = nullptr, SetTitleCallback stcb = nullptr ) : View( "127.0.0.1", 8086, fixedWidth, smallFont, bigFont, stcb ) {} + View( const char* addr, int port, ImFont* fixedWidth = nullptr, ImFont* smallFont = nullptr, ImFont* bigFont = nullptr, SetTitleCallback stcb = nullptr ); View( FileRead& f, ImFont* fixedWidth = nullptr, ImFont* smallFont = nullptr, ImFont* bigFont = nullptr, SetTitleCallback stcb = nullptr ); ~View(); diff --git a/server/TracyWorker.cpp b/server/TracyWorker.cpp index 2ddc1609..7e61cebe 100644 --- a/server/TracyWorker.cpp +++ b/server/TracyWorker.cpp @@ -234,8 +234,9 @@ static tracy_force_inline void UpdateLockRange( LockMap& lockmap, const LockEven LoadProgress Worker::s_loadProgress; -Worker::Worker( const char* addr ) +Worker::Worker( const char* addr, int port ) : m_addr( addr ) + , m_port( port ) , m_hasData( false ) , m_stream( LZ4_createStreamDecode() ) , m_buffer( new char[TargetFrameSize*3 + 1] ) @@ -2125,7 +2126,7 @@ void Worker::Exec() for(;;) { if( m_shutdown.load( std::memory_order_relaxed ) ) return; - if( m_sock.Connect( m_addr.c_str(), "8086" ) ) break; + if( m_sock.Connect( m_addr.c_str(), m_port ) ) break; } auto lz4buf = std::make_unique( LZ4Size ); diff --git a/server/TracyWorker.hpp b/server/TracyWorker.hpp index 81ca893c..4245e04e 100644 --- a/server/TracyWorker.hpp +++ b/server/TracyWorker.hpp @@ -270,7 +270,7 @@ public: NUM_FAILURES }; - Worker( const char* addr ); + Worker( const char* addr, int port ); Worker( FileRead& f, EventType::Type eventMask = EventType::All ); ~Worker(); @@ -536,6 +536,7 @@ private: Socket m_sock; std::string m_addr; + int m_port; std::thread m_thread; std::atomic m_connected { false };