From 864d7e4e4771af5f728daa1006d068da00382669 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Sun, 14 Nov 2021 13:05:05 +0100 Subject: [PATCH] Sort symbols list only when actually needed. --- server/TracySourceView.cpp | 2 +- server/TracySourceView.hpp | 2 +- server/TracyWorker.cpp | 64 ++++++++++++++++++++++---------------- server/TracyWorker.hpp | 8 +++-- 4 files changed, 45 insertions(+), 31 deletions(-) diff --git a/server/TracySourceView.cpp b/server/TracySourceView.cpp index b40384be..8748d3b5 100644 --- a/server/TracySourceView.cpp +++ b/server/TracySourceView.cpp @@ -506,7 +506,7 @@ void SourceView::OpenSource( const char* fileName, int line, const View& view, c assert( !m_source.empty() ); } -void SourceView::OpenSymbol( const char* fileName, int line, uint64_t baseAddr, uint64_t symAddr, const Worker& worker, const View& view ) +void SourceView::OpenSymbol( const char* fileName, int line, uint64_t baseAddr, uint64_t symAddr, Worker& worker, const View& view ) { m_targetLine = line; m_targetAddr = symAddr; diff --git a/server/TracySourceView.hpp b/server/TracySourceView.hpp index faa843ab..6cc3c986 100644 --- a/server/TracySourceView.hpp +++ b/server/TracySourceView.hpp @@ -146,7 +146,7 @@ public: void SetCpuId( uint32_t cpuid ); void OpenSource( const char* fileName, int line, const View& view, const Worker& worker ); - void OpenSymbol( const char* fileName, int line, uint64_t baseAddr, uint64_t symAddr, const Worker& worker, const View& view ); + void OpenSymbol( const char* fileName, int line, uint64_t baseAddr, uint64_t symAddr, Worker& worker, const View& view ); void Render( Worker& worker, View& view ); void CalcInlineStats( bool val ) { m_calcInlineStats = val; } diff --git a/server/TracyWorker.cpp b/server/TracyWorker.cpp index 86f9b998..d13ae43a 100644 --- a/server/TracyWorker.cpp +++ b/server/TracyWorker.cpp @@ -2545,15 +2545,17 @@ const char* Worker::GetSymbolCode( uint64_t sym, uint32_t& len ) const return it->second.data; } -uint64_t Worker::GetSymbolForAddress( uint64_t address ) const +uint64_t Worker::GetSymbolForAddress( uint64_t address ) { + DoPostponedSymbols(); auto it = std::lower_bound( m_data.symbolLoc.begin(), m_data.symbolLoc.end(), address, [] ( const auto& l, const auto& r ) { return l.addr + l.len < r; } ); if( it == m_data.symbolLoc.end() || address < it->addr ) return 0; return it->addr; } -uint64_t Worker::GetSymbolForAddress( uint64_t address, uint32_t& offset ) const +uint64_t Worker::GetSymbolForAddress( uint64_t address, uint32_t& offset ) { + DoPostponedSymbols(); auto it = std::lower_bound( m_data.symbolLoc.begin(), m_data.symbolLoc.end(), address, [] ( const auto& l, const auto& r ) { return l.addr + l.len < r; } ); if( it == m_data.symbolLoc.end() || address < it->addr ) return 0; offset = address - it->addr; @@ -2595,8 +2597,9 @@ const Vector* Worker::GetAddressesForLocation( uint32_t fileStringIdx, } } -const uint64_t* Worker::GetInlineSymbolList( uint64_t sym, uint32_t len ) const +const uint64_t* Worker::GetInlineSymbolList( uint64_t sym, uint32_t len ) { + DoPostponedInlineSymbols(); auto it = std::lower_bound( m_data.symbolLocInline.begin(), m_data.symbolLocInline.end(), sym ); if( it == m_data.symbolLocInline.end() ) return nullptr; if( *it >= sym + len ) return nullptr; @@ -4295,9 +4298,41 @@ void Worker::HandleFrameName( uint64_t name, const char* str, size_t sz ) } ); } +void Worker::DoPostponedSymbols() +{ + if( m_data.newSymbolsIndex >= 0 ) + { +#ifdef NO_PARALLEL_SORT + pdqsort_branchless( m_data.symbolLoc.begin() + m_data.newSymbolsIndex, m_data.symbolLoc.end(), [] ( const auto& l, const auto& r ) { return l.addr < r.addr; } ); +#else + std::sort( std::execution::par_unseq, m_data.symbolLoc.begin() + m_data.newSymbolsIndex, m_data.symbolLoc.end(), [] ( const auto& l, const auto& r ) { return l.addr < r.addr; } ); +#endif + const auto ms = std::lower_bound( m_data.symbolLoc.begin(), m_data.symbolLoc.begin() + m_data.newSymbolsIndex, m_data.symbolLoc[m_data.newSymbolsIndex], [] ( const auto& l, const auto& r ) { return l.addr < r.addr; } ); + std::inplace_merge( ms, m_data.symbolLoc.begin() + m_data.newSymbolsIndex, m_data.symbolLoc.end(), [] ( const auto& l, const auto& r ) { return l.addr < r.addr; } ); + m_data.newSymbolsIndex = -1; + } +} + +void Worker::DoPostponedInlineSymbols() +{ + if( m_data.newInlineSymbolsIndex >= 0 ) + { +#ifdef NO_PARALLEL_SORT + pdqsort_branchless( m_data.symbolLocInline.begin() + m_data.newInlineSymbolsIndex, m_data.symbolLocInline.end() ); +#else + std::sort( std::execution::par_unseq, m_data.symbolLocInline.begin() + m_data.newInlineSymbolsIndex, m_data.symbolLocInline.end() ); +#endif + const auto ms = std::lower_bound( m_data.symbolLocInline.begin(), m_data.symbolLocInline.begin() + m_data.newInlineSymbolsIndex, m_data.symbolLocInline[m_data.newInlineSymbolsIndex] ); + std::inplace_merge( ms, m_data.symbolLocInline.begin() + m_data.newInlineSymbolsIndex, m_data.symbolLocInline.end() ); + m_data.newInlineSymbolsIndex = -1; + } +} + void Worker::DoPostponedWorkAll() { DoPostponedWork(); + DoPostponedSymbols(); + DoPostponedInlineSymbols(); for( auto& plot : m_data.plots.Data() ) { @@ -4362,29 +4397,6 @@ void Worker::DoPostponedWork() m_data.newContextSwitchesReceived = false; } #endif - - if( m_data.newSymbolsIndex >= 0 ) - { -#ifdef NO_PARALLEL_SORT - pdqsort_branchless( m_data.symbolLoc.begin() + m_data.newSymbolsIndex, m_data.symbolLoc.end(), [] ( const auto& l, const auto& r ) { return l.addr < r.addr; } ); -#else - std::sort( std::execution::par_unseq, m_data.symbolLoc.begin() + m_data.newSymbolsIndex, m_data.symbolLoc.end(), [] ( const auto& l, const auto& r ) { return l.addr < r.addr; } ); -#endif - const auto ms = std::lower_bound( m_data.symbolLoc.begin(), m_data.symbolLoc.begin() + m_data.newSymbolsIndex, m_data.symbolLoc[m_data.newSymbolsIndex], [] ( const auto& l, const auto& r ) { return l.addr < r.addr; } ); - std::inplace_merge( ms, m_data.symbolLoc.begin() + m_data.newSymbolsIndex, m_data.symbolLoc.end(), [] ( const auto& l, const auto& r ) { return l.addr < r.addr; } ); - m_data.newSymbolsIndex = -1; - } - if( m_data.newInlineSymbolsIndex >= 0 ) - { -#ifdef NO_PARALLEL_SORT - pdqsort_branchless( m_data.symbolLocInline.begin() + m_data.newInlineSymbolsIndex, m_data.symbolLocInline.end() ); -#else - std::sort( std::execution::par_unseq, m_data.symbolLocInline.begin() + m_data.newInlineSymbolsIndex, m_data.symbolLocInline.end() ); -#endif - const auto ms = std::lower_bound( m_data.symbolLocInline.begin(), m_data.symbolLocInline.begin() + m_data.newInlineSymbolsIndex, m_data.symbolLocInline[m_data.newInlineSymbolsIndex] ); - std::inplace_merge( ms, m_data.symbolLocInline.begin() + m_data.newInlineSymbolsIndex, m_data.symbolLocInline.end() ); - m_data.newInlineSymbolsIndex = -1; - } } #ifndef TRACY_NO_STATISTICS diff --git a/server/TracyWorker.hpp b/server/TracyWorker.hpp index 8f1779f1..8a891779 100644 --- a/server/TracyWorker.hpp +++ b/server/TracyWorker.hpp @@ -511,13 +511,13 @@ public: const SymbolData* GetSymbolData( uint64_t sym ) const; bool HasSymbolCode( uint64_t sym ) const; const char* GetSymbolCode( uint64_t sym, uint32_t& len ) const; - uint64_t GetSymbolForAddress( uint64_t address ) const; - uint64_t GetSymbolForAddress( uint64_t address, uint32_t& offset ) const; + uint64_t GetSymbolForAddress( uint64_t address ); + uint64_t GetSymbolForAddress( uint64_t address, uint32_t& offset ); uint64_t GetInlineSymbolForAddress( uint64_t address ) const; bool HasInlineSymbolAddresses() const { return !m_data.codeSymbolMap.empty(); } StringIdx GetLocationForAddress( uint64_t address, uint32_t& line ) const; const Vector* GetAddressesForLocation( uint32_t fileStringIdx, uint32_t line ) const; - const uint64_t* GetInlineSymbolList( uint64_t sym, uint32_t len ) const; + const uint64_t* GetInlineSymbolList( uint64_t sym, uint32_t len ); #ifndef TRACY_NO_STATISTICS const VarArray& GetParentCallstack( uint32_t idx ) const { return *m_data.parentCallstackPayload[idx]; } @@ -623,6 +623,8 @@ public: std::pair GetTextureCompressionBytes() const { return std::make_pair( m_texcomp.GetInputBytesCount(), m_texcomp.GetOutputBytesCount() ); } + void DoPostponedSymbols(); + void DoPostponedInlineSymbols(); void DoPostponedWork(); void DoPostponedWorkAll();