Sort symbols list only when actually needed.

This commit is contained in:
Bartosz Taudul 2021-11-14 13:05:05 +01:00
parent b978a7c652
commit 864d7e4e47
No known key found for this signature in database
GPG Key ID: B7FE2008B7575DF3
4 changed files with 45 additions and 31 deletions

View File

@ -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;

View File

@ -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; }

View File

@ -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<uint64_t>* 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

View File

@ -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<uint64_t>* 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<CallstackFrameId>& GetParentCallstack( uint32_t idx ) const { return *m_data.parentCallstackPayload[idx]; }
@ -623,6 +623,8 @@ public:
std::pair<uint64_t, uint64_t> GetTextureCompressionBytes() const { return std::make_pair( m_texcomp.GetInputBytesCount(), m_texcomp.GetOutputBytesCount() ); }
void DoPostponedSymbols();
void DoPostponedInlineSymbols();
void DoPostponedWork();
void DoPostponedWorkAll();