From 5ab84d0c3f26b7d381ec0e44282f97499ace59d4 Mon Sep 17 00:00:00 2001 From: Kevin Kuehler Date: Fri, 21 May 2021 15:25:26 -0700 Subject: [PATCH 1/4] Use file:line when comparing traces When comparing traces, where multiple classes share the same zone names, the behavior prior to this patch was to auto-select the first matching zone name in the other trace. Instead, find the most correct zone by using filename and line number. --- server/TracyView.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/server/TracyView.cpp b/server/TracyView.cpp index fc10ddea..2e0e4ff6 100644 --- a/server/TracyView.cpp +++ b/server/TracyView.cpp @@ -11407,8 +11407,10 @@ void View::DrawCompare() auto& srcloc1 = m_compare.second->GetSourceLocation( m_compare.match[1][m_compare.selMatch[1]] ); auto string0 = m_worker.GetString( srcloc0.name.active ? srcloc0.name : srcloc0.function ); auto string1 = m_compare.second->GetString( srcloc1.name.active ? srcloc1.name : srcloc1.function ); + auto file0 = m_worker.GetString( srcloc0.file ); + auto file1 = m_compare.second->GetString( srcloc1.file ); - if( strcmp( string0, string1 ) != 0 ) + if( strcmp( string0, string1 ) != 0 || strcmp( file0, file1 ) != 0 || srcloc0.line != srcloc1.line ) { idx = 0; if( prev0 != m_compare.selMatch[0] ) @@ -11417,7 +11419,8 @@ void View::DrawCompare() { auto& srcloc = m_compare.second->GetSourceLocation( v ); auto string = m_compare.second->GetString( srcloc.name.active ? srcloc.name : srcloc.function ); - if( strcmp( string0, string ) == 0 ) + auto file = m_compare.second->GetString( srcloc.file ); + if( strcmp( string0, string ) == 0 && strcmp( file0, file) == 0 && srcloc0.line == srcloc.line ) { m_compare.selMatch[1] = idx; break; @@ -11432,7 +11435,8 @@ void View::DrawCompare() { auto& srcloc = m_worker.GetSourceLocation( v ); auto string = m_worker.GetString( srcloc.name.active ? srcloc.name : srcloc.function ); - if( strcmp( string1, string ) == 0 ) + auto file = m_compare.second->GetString( srcloc.file ); + if( strcmp( string1, string ) == 0 && strcmp( file1, file) == 0 && srcloc1.line == srcloc.line ) { m_compare.selMatch[0] = idx; break; From 306055ebfaa5243daa2140e3686911f4ab0c853d Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Sat, 22 May 2021 00:46:11 +0200 Subject: [PATCH 2/4] Cosmetics. --- server/TracyView.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/TracyView.cpp b/server/TracyView.cpp index 2e0e4ff6..9498561f 100644 --- a/server/TracyView.cpp +++ b/server/TracyView.cpp @@ -11420,7 +11420,7 @@ void View::DrawCompare() auto& srcloc = m_compare.second->GetSourceLocation( v ); auto string = m_compare.second->GetString( srcloc.name.active ? srcloc.name : srcloc.function ); auto file = m_compare.second->GetString( srcloc.file ); - if( strcmp( string0, string ) == 0 && strcmp( file0, file) == 0 && srcloc0.line == srcloc.line ) + if( strcmp( string0, string ) == 0 && strcmp( file0, file ) == 0 && srcloc0.line == srcloc.line ) { m_compare.selMatch[1] = idx; break; @@ -11436,7 +11436,7 @@ void View::DrawCompare() auto& srcloc = m_worker.GetSourceLocation( v ); auto string = m_worker.GetString( srcloc.name.active ? srcloc.name : srcloc.function ); auto file = m_compare.second->GetString( srcloc.file ); - if( strcmp( string1, string ) == 0 && strcmp( file1, file) == 0 && srcloc1.line == srcloc.line ) + if( strcmp( string1, string ) == 0 && strcmp( file1, file ) == 0 && srcloc1.line == srcloc.line ) { m_compare.selMatch[0] = idx; break; From e01ba2d7d4c63a3c33880a58ce35887391c5d86d Mon Sep 17 00:00:00 2001 From: stgatilov Date: Sat, 22 May 2021 14:20:36 +0700 Subject: [PATCH 3/4] Tiny fix in manual Without parentheses, bitwise-and takes precedence over bitwise-or. --- manual/tracy.tex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manual/tracy.tex b/manual/tracy.tex index afff202a..202f77c6 100644 --- a/manual/tracy.tex +++ b/manual/tracy.tex @@ -1121,7 +1121,7 @@ enum SubSystems ... // Preferably a define in the build system -#define SUBSYSTEMS Sys_Physics | Sys_NasalDemons +#define SUBSYSTEMS (Sys_Physics | Sys_NasalDemons) ... From 871d41be1fa60816b06c250bf3f9ba1fbc1194d5 Mon Sep 17 00:00:00 2001 From: Kevin Kuehler Date: Sat, 22 May 2021 01:11:53 -0700 Subject: [PATCH 4/4] Implement FindMatchingZone(..) Sets m_compare to the matched index. It supports multiple flags. It can be run by comparing function name, source file, line number, and any combination thereof. When searching for a match, we do 3 runs, quitting out if any of them succeed. 1. Look for zone with same function same, source file, line number. 2. Look for zone with same function same, source file. 3. Look for zone with same function same. --- server/TracyView.cpp | 123 +++++++++++++++++++++++++++++-------------- server/TracyView.hpp | 8 +++ 2 files changed, 92 insertions(+), 39 deletions(-) diff --git a/server/TracyView.cpp b/server/TracyView.cpp index 9498561f..6b4ee9a0 100644 --- a/server/TracyView.cpp +++ b/server/TracyView.cpp @@ -11189,6 +11189,87 @@ void View::DrawZoneList( int id, const Vector>& zones ) ImGui::TreePop(); } +bool View::FindMatchingZone( int prev0, int prev1, int flags ) +{ + int idx = 0; + bool found = false; + auto& srcloc0 = m_worker.GetSourceLocation( m_compare.match[0][m_compare.selMatch[0]] ); + auto& srcloc1 = m_compare.second->GetSourceLocation( m_compare.match[1][m_compare.selMatch[1]] ); + auto string0 = m_worker.GetString( srcloc0.name.active ? srcloc0.name : srcloc0.function ); + auto string1 = m_compare.second->GetString( srcloc1.name.active ? srcloc1.name : srcloc1.function ); + auto file0 = m_worker.GetString( srcloc0.file ); + auto file1 = m_compare.second->GetString( srcloc1.file ); + bool wrongFile = false; + bool wrongLine = false; + if( flags & FindMatchingZoneFlagSourceFile ) + { + wrongFile = strcmp( file0, file1 ) != 0; + } + if( flags & FindMatchingZoneFlagLineNum ) + { + wrongLine = srcloc0.line != srcloc1.line; + } + + if( strcmp( string0, string1 ) != 0 || wrongFile || wrongLine ) + { + if( prev0 != m_compare.selMatch[0] ) + { + for( auto& v : m_compare.match[1] ) + { + auto& srcloc = m_compare.second->GetSourceLocation( v ); + auto string = m_compare.second->GetString( srcloc.name.active ? srcloc.name : srcloc.function ); + auto file = m_compare.second->GetString( srcloc.file ); + bool sameFile = true; + bool sameLine = true; + if( flags & FindMatchingZoneFlagSourceFile ) + { + sameFile = strcmp( file0, file ) == 0; + } + if( flags & FindMatchingZoneFlagLineNum ) + { + sameLine = srcloc0.line == srcloc.line; + } + if( strcmp( string0, string ) == 0 && sameFile && sameLine ) + { + m_compare.selMatch[1] = idx; + found = true; + break; + } + idx++; + } + } + else + { + assert( prev1 != m_compare.selMatch[1] ); + for( auto& v : m_compare.match[0] ) + { + auto& srcloc = m_worker.GetSourceLocation( v ); + auto string = m_worker.GetString( srcloc.name.active ? srcloc.name : srcloc.function ); + auto file = m_worker.GetString( srcloc.file ); + bool sameFile = true; + bool sameLine = true; + if( flags & FindMatchingZoneFlagSourceFile ) + { + sameFile = strcmp( file1, file ) == 0; + } + if( flags & FindMatchingZoneFlagLineNum ) + { + sameLine = srcloc1.line == srcloc.line; + } + if( strcmp( string1, string ) == 0 && sameFile && sameLine ) + { + m_compare.selMatch[0] = idx; + found = true; + break; + } + idx++; + } + + } + } + return found; +} + void View::DrawCompare() { ImGui::SetNextWindowSize( ImVec2( 590, 800 ), ImGuiCond_FirstUseEver ); @@ -11403,47 +11484,11 @@ void View::DrawCompare() if( m_compare.link ) { - auto& srcloc0 = m_worker.GetSourceLocation( m_compare.match[0][m_compare.selMatch[0]] ); - auto& srcloc1 = m_compare.second->GetSourceLocation( m_compare.match[1][m_compare.selMatch[1]] ); - auto string0 = m_worker.GetString( srcloc0.name.active ? srcloc0.name : srcloc0.function ); - auto string1 = m_compare.second->GetString( srcloc1.name.active ? srcloc1.name : srcloc1.function ); - auto file0 = m_worker.GetString( srcloc0.file ); - auto file1 = m_compare.second->GetString( srcloc1.file ); - - if( strcmp( string0, string1 ) != 0 || strcmp( file0, file1 ) != 0 || srcloc0.line != srcloc1.line ) + if( !FindMatchingZone( prev0, prev1, FindMatchingZoneFlagSourceFile | FindMatchingZoneFlagLineNum ) ) { - idx = 0; - if( prev0 != m_compare.selMatch[0] ) + if( !FindMatchingZone( prev0, prev1, FindMatchingZoneFlagSourceFile ) ) { - for( auto& v : m_compare.match[1] ) - { - auto& srcloc = m_compare.second->GetSourceLocation( v ); - auto string = m_compare.second->GetString( srcloc.name.active ? srcloc.name : srcloc.function ); - auto file = m_compare.second->GetString( srcloc.file ); - if( strcmp( string0, string ) == 0 && strcmp( file0, file ) == 0 && srcloc0.line == srcloc.line ) - { - m_compare.selMatch[1] = idx; - break; - } - idx++; - } - } - else - { - assert( prev1 != m_compare.selMatch[1] ); - for( auto& v : m_compare.match[0] ) - { - auto& srcloc = m_worker.GetSourceLocation( v ); - auto string = m_worker.GetString( srcloc.name.active ? srcloc.name : srcloc.function ); - auto file = m_compare.second->GetString( srcloc.file ); - if( strcmp( string1, string ) == 0 && strcmp( file1, file ) == 0 && srcloc1.line == srcloc.line ) - { - m_compare.selMatch[0] = idx; - break; - } - idx++; - } - + FindMatchingZone( prev0, prev1, FindMatchingZoneFlagDefault ); } } } diff --git a/server/TracyView.hpp b/server/TracyView.hpp index 7e7ddfa3..53d10990 100644 --- a/server/TracyView.hpp +++ b/server/TracyView.hpp @@ -251,6 +251,7 @@ private: uint64_t GetZoneThread( const ZoneEvent& zone ) const; uint64_t GetZoneThread( const GpuEvent& zone ) const; const GpuCtxData* GetZoneCtx( const GpuEvent& zone ) const; + bool FindMatchingZone( int prev0, int prev1, int flags ); const ZoneEvent* FindZoneAtTime( uint64_t thread, int64_t time ) const; uint64_t GetFrameNumber( const FrameData& fd, int i, uint64_t offset ) const; const char* GetFrameText( const FrameData& fd, int i, uint64_t ftime, uint64_t offset ) const; @@ -447,6 +448,13 @@ private: NeedsJoin }; + enum + { + FindMatchingZoneFlagDefault = 0, + FindMatchingZoneFlagSourceFile = (1 << 0), + FindMatchingZoneFlagLineNum = (1 << 1), + }; + std::atomic m_saveThreadState { SaveThreadState::Inert }; std::thread m_saveThread; std::atomic m_srcFileBytes { 0 };