From 1b3b3a94a268bb202215d2a995f365ad2d540aaa Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Mon, 17 Jun 2019 18:34:35 +0200 Subject: [PATCH] Broadcast protocol version and process name. --- client/TracyProfiler.cpp | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/client/TracyProfiler.cpp b/client/TracyProfiler.cpp index 268a1fbd..513ca956 100644 --- a/client/TracyProfiler.cpp +++ b/client/TracyProfiler.cpp @@ -422,6 +422,23 @@ static const char* GetHostInfo() return buf; } +static const char* GetBroadcastMessage( const char* procname, int& len ) +{ + static char buf[1024]; + char* ptr = buf; + + const uint32_t protoVer = ProtocolVersion; + memcpy( ptr, &protoVer, sizeof( protoVer ) ); + ptr += sizeof( protoVer ); + + const auto pnsz = strlen( procname ); + memcpy( ptr, procname, pnsz ); + ptr += pnsz; + + len = ptr - buf; + return buf; +} + #ifdef _WIN32 static DWORD s_profilerThreadId = 0; static char s_crashText[1024]; @@ -1091,6 +1108,8 @@ void Profiler::Worker() } } + const char* broadcastMsg = nullptr; + int broadcastLen = 0; #ifndef TRACY_NO_BROADCAST m_broadcast = (UdpBroadcast*)tracy_malloc( sizeof( UdpBroadcast ) ); new(m_broadcast) UdpBroadcast(); @@ -1100,6 +1119,10 @@ void Profiler::Worker() tracy_free( m_broadcast ); m_broadcast = nullptr; } + else + { + broadcastMsg = GetBroadcastMessage( procname, broadcastLen ); + } #endif // Connections loop. @@ -1129,7 +1152,7 @@ void Profiler::Worker() if( t - m_lastBroadcast > 5000000000 ) // 5s { m_lastBroadcast = t; - m_broadcast->Send( "abc", 3 ); + m_broadcast->Send( broadcastMsg, broadcastLen ); auto err = WSAGetLastError(); } }