From f17bd3f444928b3fa0d2b9332a50dba0920c7bfe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Gr=C3=A9goire?= Date: Fri, 24 Oct 2025 17:56:02 +0200 Subject: [PATCH] TracyDebug now uses TracyInternalMessage by default unless `TRACY_VERBOSE` or `TRACY_NO_INTERNAL_MESSAGE` is defined --- CMakeLists.txt | 2 ++ manual/tracy.tex | 5 +-- meson.build | 4 +++ meson.options | 1 + public/client/TracyCallstack.cpp | 10 +++--- public/client/TracyDebug.hpp | 18 +++++++++- public/client/TracyKCore.cpp | 2 +- public/client/TracyOverride.cpp | 4 +-- public/client/TracyProfiler.cpp | 6 ++-- public/client/TracyRingBuffer.hpp | 2 +- public/client/TracySysPower.cpp | 2 +- public/client/TracySysTrace.cpp | 58 +++++++++++++++--------------- public/client/windows/TracyETW.cpp | 2 ++ 13 files changed, 71 insertions(+), 45 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1ebe5748..144379b9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -146,6 +146,8 @@ set_option(TRACY_IGNORE_MEMORY_FAULTS "Ignore instrumentation errors from memory # advanced set_option(TRACY_VERBOSE "[advanced] Verbose output from the profiler" OFF) mark_as_advanced(TRACY_VERBOSE) +set_option(TRACY_NO_INTERNAL_MESSAGE "[advanced] Prevent the profiler from logging messages" OFF) +mark_as_advanced(TRACY_NO_INTERNAL_MESSAGE) set_option(TRACY_DEMANGLE "[advanced] Don't use default demangling function - You'll need to provide your own" OFF) mark_as_advanced(TRACY_DEMANGLE) if(rocprofiler-sdk_FOUND) diff --git a/manual/tracy.tex b/manual/tracy.tex index f478ee33..0e7dc934 100644 --- a/manual/tracy.tex +++ b/manual/tracy.tex @@ -646,7 +646,8 @@ Although the basic features will work without them, you'll have to grant elevate \subsubsection{Troubleshooting} -Setting the \texttt{TRACY\_VERBOSE} variable will make the client display advanced information about the detected features. By matching those debug prints to the source code, you might be able to uncover why some of the features are missing on your platform. +By default, Tracy's diagnostics will be sent as Message logs (section~\ref{messagelog}) to the server. +Setting the \texttt{TRACY\_NO\_INTERNAL\_MESSAGE} define will disable this feature, but setting the \texttt{TRACY\_VERBOSE} will make the client print advanced information about the detected features to the standard error output. By matching those debug prints to the source code, you might be able to uncover why some of the features are missing on your platform. \subsubsection{Changing network port} @@ -1492,7 +1493,7 @@ Fast navigation in large data sets and correlating zones with what was happening If you want to include color coding of the messages (for example to make critical messages easily visible), you can use \texttt{TracyMessageC(text, size, color)} or \texttt{TracyMessageLC(text, color)} macros. Messages can also have different severity levels: \texttt{Trace}, \texttt{Debug}, \texttt{Info}, \texttt{Warning}, \texttt{Error} or \texttt{Fatal}. -The previous macros will log messages with the severity "Info". To log a message with a different severity, you may use the \texttt{TracyLogString} macro that regroups all the functionalities from the previous macros. We recommend writing your own macros, wrapping the different severities for easier use. You may provide a color of 0 if you do not want to set a color for this message. +The \texttt{TracyMessage} macros will log messages with the severity \texttt{Info}. To log a message with a different severity, you may use the \texttt{TracyLogString} macro that regroups all the functionalities from the previous macros. We recommend writing your own macros, wrapping the different severities for easier use. You may provide a color of 0 if you do not want to set a color for this message. Examples: \begin{lstlisting} diff --git a/meson.build b/meson.build index 16031448..7b81aedb 100644 --- a/meson.build +++ b/meson.build @@ -114,6 +114,10 @@ if get_option('verbose') tracy_common_args += ['-DTRACY_VERBOSE'] endif +if get_option('no_internal_message') + tracy_common_args += ['-DTRACY_NO_INTERNAL_MESSAGE'] +endif + if get_option('debuginfod') tracy_common_args += ['-DTRACY_DEBUGINFOD'] tracy_public_deps += dependency('libdebuginfod') diff --git a/meson.options b/meson.options index 6527c917..d57d6b27 100644 --- a/meson.options +++ b/meson.options @@ -24,5 +24,6 @@ option('manual_lifetime', type : 'boolean', value : false, description : 'Enable option('fibers', type : 'boolean', value : false, description : 'Enable fibers support') option('no_crash_handler', type : 'boolean', value : false, description : 'Disable crash handling') option('verbose', type : 'boolean', value : false, description : 'Enable verbose logging') +option('no_internal_message', type : 'boolean', value : false, description : 'Prevent the profiler from logging messages') option('debuginfod', type : 'boolean', value : false, description : 'Enable debuginfod support') option('ignore_memory_faults', type : 'boolean', value : false, description : 'Ignore instrumentation errors from memory free events that do not have a matching allocation') diff --git a/public/client/TracyCallstack.cpp b/public/client/TracyCallstack.cpp index 7ab6b1c4..3cc41386 100644 --- a/public/client/TracyCallstack.cpp +++ b/public/client/TracyCallstack.cpp @@ -532,7 +532,7 @@ void InitCallstack() #endif //#ifndef TRACY_SYMBOL_OFFLINE_RESOLVE if( s_shouldResolveSymbolsOffline ) { - TracyDebug("TRACY: enabling offline symbol resolving!\n"); + TracyDebug( "TRACY: enabling offline symbol resolving!" ); } CreateImageCaches(); @@ -551,7 +551,7 @@ void InitCallstack() const bool initTimeModuleLoad = !( noInitLoadEnv && noInitLoadEnv[0] == '1' ); if ( !initTimeModuleLoad ) { - TracyDebug("TRACY: skipping init time dbghelper module load\n"); + TracyDebug( "TRACY: skipping init time dbghelper module load" ); } else { @@ -963,7 +963,7 @@ static void InitKernelSymbols() } assert( dst == s_kernelSym + validCnt ); - TracyDebug( "Loaded %zu kernel symbols (%zu code sections)\n", tmpSym.size(), validCnt ); + TracyDebug( "Loaded %zu kernel symbols (%zu code sections)", tmpSym.size(), validCnt ); } #endif @@ -1040,7 +1040,7 @@ void InitCallstack() if( s_shouldResolveSymbolsOffline ) { cb_bts = nullptr; // disable use of libbacktrace calls - TracyDebug("TRACY: enabling offline symbol resolving!\n"); + TracyDebug( "TRACY: enabling offline symbol resolving!" ); } else { @@ -1100,7 +1100,7 @@ int GetDebugInfoDescriptor( const char* buildid_data, size_t buildid_size, const it->filename = (char*)tracy_malloc( fnsz ); memcpy( it->filename, filename, fnsz ); it->fd = fd >= 0 ? fd : -1; - TracyDebug( "DebugInfo descriptor query: %i, fn: %s\n", fd, filename ); + TracyDebug( "DebugInfo descriptor query: %i, fn: %s", fd, filename ); return it->fd; } diff --git a/public/client/TracyDebug.hpp b/public/client/TracyDebug.hpp index 8723356f..ecf852f4 100644 --- a/public/client/TracyDebug.hpp +++ b/public/client/TracyDebug.hpp @@ -1,9 +1,25 @@ #ifndef __TRACYPRINT_HPP__ #define __TRACYPRINT_HPP__ +#ifdef TRACY_ON_DEMAND +# define TRACY_VERBOSE_EARLY_OUT_COND if( !GetProfiler().IsConnected() ) break +#else +# define TRACY_VERBOSE_EARLY_OUT_COND assert( tracy::ProfilerAvailable() ) +#endif + +#define TracyInternalMessage( severity, ... ) \ + do { \ + TRACY_VERBOSE_EARLY_OUT_COND; \ + char buffer[4096]; \ + snprintf( buffer, sizeof(buffer), __VA_ARGS__ ); \ + tracy::Profiler::LogString( tracy::MessageSourceType::Tracy, severity, 0, TRACY_CALLSTACK, strlen( buffer ), buffer ); \ + } while( 0 ) + #ifdef TRACY_VERBOSE # include -# define TracyDebug(...) fprintf( stderr, __VA_ARGS__ ); +# define TracyDebug(...) do { fprintf( stderr, __VA_ARGS__ ); fputc( '\n', stderr ); } while( 0 ) +#elif !defined(TRACY_NO_INTERNAL_MESSAGE) +# define TracyDebug(...) TracyInternalMessage( tracy::MessageSeverity::Debug, __VA_ARGS__ ) #else # define TracyDebug(...) #endif diff --git a/public/client/TracyKCore.cpp b/public/client/TracyKCore.cpp index 09d51d11..f77f6b03 100644 --- a/public/client/TracyKCore.cpp +++ b/public/client/TracyKCore.cpp @@ -87,7 +87,7 @@ KCore::KCore() } std::sort( m_offsets.begin(), m_offsets.end(), []( const Offset& lhs, const Offset& rhs ) { return lhs.start < rhs.start; } ); - TracyDebug( "KCore: %zu segments found\n", m_offsets.size() ); + TracyDebug( "KCore: %zu segments found", m_offsets.size() ); return; err: diff --git a/public/client/TracyOverride.cpp b/public/client/TracyOverride.cpp index 591508a7..07064bc4 100644 --- a/public/client/TracyOverride.cpp +++ b/public/client/TracyOverride.cpp @@ -12,11 +12,11 @@ extern "C" int dlclose( void* hnd ) struct link_map* lm; if( dlinfo( hnd, RTLD_DI_LINKMAP, &lm ) == 0 ) { - TracyDebug( "Overriding dlclose for %s\n", lm->l_name ); + TracyDebug( "Overriding dlclose for %s", lm->l_name ); } else { - TracyDebug( "Overriding dlclose for unknown object (%s)\n", dlerror() ); + TracyDebug( "Overriding dlclose for unknown object (%s)", dlerror() ); } #endif return 0; diff --git a/public/client/TracyProfiler.cpp b/public/client/TracyProfiler.cpp index 0535644d..5e148023 100644 --- a/public/client/TracyProfiler.cpp +++ b/public/client/TracyProfiler.cpp @@ -1180,7 +1180,7 @@ static void StartSystemTracing( int64_t& samplingPeriod ) const bool disableSystrace = ( noSysTrace && noSysTrace[0] == '1' ); if( disableSystrace ) { - TracyDebug( "TRACY: Sys Trace was disabled by 'TRACY_NO_SYS_TRACE=1'\n" ); + TracyDebug( "TRACY: Sys Trace was disabled by 'TRACY_NO_SYS_TRACE=1'" ); } else if( SysTraceStart( samplingPeriod ) ) { @@ -4239,7 +4239,7 @@ void Profiler::HandleSourceCodeQuery( char* data, char* image, uint32_t id ) if( buildid ) { auto d = debuginfod_find_source( GetDebuginfodClient(), buildid, size, data, nullptr ); - TracyDebug( "DebugInfo source query: %s, fn: %s, image: %s\n", d >= 0 ? " ok " : "fail", data, image ); + TracyDebug( "DebugInfo source query: %s, fn: %s, image: %s", d >= 0 ? " ok " : "fail", data, image ); if( d >= 0 ) { struct stat st; @@ -4269,7 +4269,7 @@ void Profiler::HandleSourceCodeQuery( char* data, char* image, uint32_t id ) } else { - TracyDebug( "DebugInfo invalid query fn: %s, image: %s\n", data, image ); + TracyDebug( "DebugInfo invalid query fn: %s, image: %s", data, image ); } #endif diff --git a/public/client/TracyRingBuffer.hpp b/public/client/TracyRingBuffer.hpp index e9100e2d..1d1a9097 100644 --- a/public/client/TracyRingBuffer.hpp +++ b/public/client/TracyRingBuffer.hpp @@ -29,7 +29,7 @@ public: auto mapAddr = mmap( nullptr, m_mapSize, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0 ); if( mapAddr == MAP_FAILED ) { - TracyDebug( "mmap failed: errno %i (%s)\n", errno, strerror( errno ) ); + TracyDebug( "mmap failed: errno %i (%s)", errno, strerror( errno ) ); m_fd = 0; m_metadata = nullptr; close( fd ); diff --git a/public/client/TracySysPower.cpp b/public/client/TracySysPower.cpp index 6ad1d647..ed04b8b9 100644 --- a/public/client/TracySysPower.cpp +++ b/public/client/TracySysPower.cpp @@ -138,7 +138,7 @@ void SysPower::ScanDirectory( const char* path, int parent ) domain->overflow = maxRange; domain->handle = handle; domain->name = name; - TracyDebug( "Power domain id %i, %s found at %s\n", parent, name, path ); + TracyDebug( "Power domain id %i, %s found at %s", parent, name, path ); } else { diff --git a/public/client/TracySysTrace.cpp b/public/client/TracySysTrace.cpp index 4fd65d35..55aa3152 100644 --- a/public/client/TracySysTrace.cpp +++ b/public/client/TracySysTrace.cpp @@ -493,7 +493,7 @@ static void ProbePreciseIp( perf_event_attr& pe, unsigned long long config0, uns } pe.precise_ip--; } - TracyDebug( " Probed precise_ip: %i\n", pe.precise_ip ); + TracyDebug( " Probed precise_ip: %i", pe.precise_ip ); } static void ProbePreciseIp( perf_event_attr& pe, pid_t pid ) @@ -509,7 +509,7 @@ static void ProbePreciseIp( perf_event_attr& pe, pid_t pid ) } pe.precise_ip--; } - TracyDebug( " Probed precise_ip: %i\n", pe.precise_ip ); + TracyDebug( " Probed precise_ip: %i", pe.precise_ip ); } static bool IsGenuineIntel() @@ -587,12 +587,12 @@ bool SysTraceStart( int64_t& samplingPeriod ) #ifdef TRACY_VERBOSE int paranoidLevel = 2; paranoidLevel = atoi( paranoidLevelStr ); - TracyDebug( "perf_event_paranoid: %i\n", paranoidLevel ); + TracyDebug( "perf_event_paranoid: %i", paranoidLevel ); #endif auto traceFsPath = GetTraceFsPath(); if( !traceFsPath ) return false; - TracyDebug( "tracefs path: %s\n", traceFsPath ); + TracyDebug( "tracefs path: %s", traceFsPath ); int switchId = -1, wakingId = -1, vsyncId = -1; const auto switchIdStr = ReadFile( traceFsPath, "/events/sched/sched_switch/id" ); @@ -604,9 +604,9 @@ bool SysTraceStart( int64_t& samplingPeriod ) tracy_free( traceFsPath ); - TracyDebug( "sched_switch id: %i\n", switchId ); - TracyDebug( "sched_waking id: %i\n", wakingId ); - TracyDebug( "drm_vblank_event id: %i\n", vsyncId ); + TracyDebug( "sched_switch id: %i", switchId ); + TracyDebug( "sched_waking id: %i", wakingId ); + TracyDebug( "drm_vblank_event id: %i", vsyncId ); #ifdef TRACY_NO_SAMPLING const bool noSoftwareSampling = true; @@ -686,7 +686,7 @@ bool SysTraceStart( int64_t& samplingPeriod ) if( !noSoftwareSampling ) { - TracyDebug( "Setup software sampling\n" ); + TracyDebug( "Setup software sampling" ); ProbePreciseIp( pe, currentPid ); for( int i=0; i