Remove locationCodeAddressList map from Worker.

Mapping of source code locations to code addresses is now performed
dynamically during disassembly in SourceView.
This commit is contained in:
Bartosz Taudul 2022-10-11 23:59:07 +02:00
parent 57e039f96c
commit 0b84b50d9f
No known key found for this signature in database
GPG Key ID: B7FE2008B7575DF3
5 changed files with 39 additions and 68 deletions

View File

@ -7,7 +7,7 @@ namespace Version
{
enum { Major = 0 };
enum { Minor = 8 };
enum { Patch = 4 };
enum { Patch = 5 };
}
}

View File

@ -96,6 +96,11 @@ struct ChildStat
};
static tracy_force_inline uint64_t PackFileLine( uint32_t fileIdx, uint32_t line )
{
return ( uint64_t( fileIdx ) << 32 ) | line;
}
static size_t CountHwSamples( const SortedVector<Int48, Int48Sort>& vec, const Range& range )
{
if( vec.empty() ) return 0;
@ -655,6 +660,7 @@ bool SourceView::Disassemble( uint64_t symAddr, const Worker& worker )
m_locMap.clear();
m_jumpTable.clear();
m_jumpOut.clear();
m_locationAddress.clear();
m_maxJumpLevel = 0;
m_asmSelected = -1;
m_asmCountBase = -1;
@ -936,9 +942,17 @@ bool SourceView::Disassemble( uint64_t symAddr, const Worker& worker )
if( srcline > mLineMax ) mLineMax = srcline;
const auto idx = srcidx.Idx();
auto sit = m_sourceFiles.find( idx );
if( sit == m_sourceFiles.end() )
if( sit == m_sourceFiles.end() ) m_sourceFiles.emplace( idx, srcline );
const auto packed = PackFileLine( idx, srcline );
auto lit = m_locationAddress.find( packed );
if( lit == m_locationAddress.end() )
{
m_sourceFiles.emplace( idx, srcline );
m_locationAddress.emplace( packed, std::vector<uint64_t>( { op.address } ) );
}
else
{
assert( lit->second.back() < op.address );
lit->second.push_back( op.address );
}
}
char tmp[16];
@ -2109,7 +2123,7 @@ void SourceView::RenderSymbolSourceView( const AddrStatData& as, Worker& worker,
{
if( as.ipCountSrc.find( lineNum ) == as.ipCountSrc.end() )
{
auto addresses = worker.GetAddressesForLocation( m_source.idx(), lineNum );
auto addresses = GetAddressesForLocation( m_source.idx(), lineNum );
if( addresses )
{
for( auto& addr : *addresses )
@ -3076,7 +3090,7 @@ void SourceView::RenderLine( const Tokenizer::Line& line, int lineNum, const Add
if( !m_asm.empty() )
{
assert( worker && view );
auto addresses = worker->GetAddressesForLocation( m_source.idx(), lineNum );
auto addresses = GetAddressesForLocation( m_source.idx(), lineNum );
if( addresses )
{
for( auto& addr : *addresses )
@ -4678,7 +4692,7 @@ void SourceView::SelectLine( uint32_t line, const Worker* worker, bool updateAsm
void SourceView::SelectAsmLines( uint32_t file, uint32_t line, const Worker& worker, bool updateAsmLine, uint64_t targetAddr, bool changeAsmLine )
{
m_selectedAddresses.clear();
auto addresses = worker.GetAddressesForLocation( file, line );
auto addresses = GetAddressesForLocation( file, line );
if( addresses )
{
const auto& addr = *addresses;
@ -4736,7 +4750,7 @@ void SourceView::SelectAsmLines( uint32_t file, uint32_t line, const Worker& wor
void SourceView::SelectAsmLinesHover( uint32_t file, uint32_t line, const Worker& worker )
{
assert( m_selectedAddressesHover.empty() );
auto addresses = worker.GetAddressesForLocation( file, line );
auto addresses = GetAddressesForLocation( file, line );
if( addresses )
{
for( auto& v : *addresses )
@ -5391,6 +5405,19 @@ bool SourceView::IsInContext( const Worker& worker, uint64_t addr ) const
return !m_calcInlineStats || !worker.HasInlineSymbolAddresses() || worker.GetInlineSymbolForAddress( addr ) == m_symAddr;
}
const std::vector<uint64_t>* SourceView::GetAddressesForLocation( uint32_t fileStringIdx, uint32_t line ) const
{
auto it = m_locationAddress.find( PackFileLine( fileStringIdx, line ) );
if( it == m_locationAddress.end() )
{
return nullptr;
}
else
{
return &it->second;
}
}
#ifndef TRACY_NO_FILESELECTOR
void SourceView::Save( const Worker& worker, size_t start, size_t stop )
{

View File

@ -202,6 +202,7 @@ private:
void CheckWrite( size_t line, RegsX86 reg, size_t limit );
bool IsInContext( const Worker& worker, uint64_t addr ) const;
const std::vector<uint64_t>* GetAddressesForLocation( uint32_t fileStringIdx, uint32_t line ) const;
#ifndef TRACY_NO_FILESELECTOR
void Save( const Worker& worker, size_t start = 0, size_t stop = std::numeric_limits<size_t>::max() );
@ -249,6 +250,8 @@ private:
size_t m_maxJumpLevel;
bool m_showJumps;
unordered_flat_map<uint64_t, std::vector<uint64_t>> m_locationAddress;
unordered_flat_map<uint32_t, uint32_t> m_sourceFiles;
unordered_flat_set<uint64_t> m_selectedAddresses;
unordered_flat_set<uint64_t> m_selectedAddressesHover;

View File

@ -38,11 +38,6 @@
namespace tracy
{
static tracy_force_inline uint64_t PackFileLine( uint32_t fileIdx, uint32_t line )
{
return ( uint64_t( fileIdx ) << 32 ) | line;
}
static tracy_force_inline uint32_t UnpackFileLine( uint64_t packed, uint32_t& line )
{
line = packed & 0xFFFFFFFF;
@ -1772,31 +1767,9 @@ Worker::Worker( FileRead& f, EventType::Type eventMask, bool bgTasks )
}
}
if( fileVer <= FileVersion( 0, 8, 4 ) )
{
f.Read( sz );
if( eventMask & EventType::SymbolCode )
{
m_data.locationCodeAddressList.reserve( sz );
for( uint64_t i=0; i<sz; i++ )
{
uint64_t packed;
uint16_t lsz;
f.Read2( packed, lsz );
Vector<uint64_t> data;
data.reserve_exact( lsz, m_slab );
uint64_t ref = 0;
for( uint16_t j=0; j<lsz; j++ )
{
uint64_t diff;
f.Read( diff );
ref += diff;
data[j] = ref;
m_data.codeAddressToLocation.emplace( ref, packed );
}
m_data.locationCodeAddressList.emplace( packed, std::move( data ) );
}
}
else
{
for( uint64_t i=0; i<sz; i++ )
{
uint64_t packed;
@ -2600,19 +2573,6 @@ StringIdx Worker::GetLocationForAddress( uint64_t address, uint32_t& line ) cons
}
}
const Vector<uint64_t>* Worker::GetAddressesForLocation( uint32_t fileStringIdx, uint32_t line ) const
{
auto it = m_data.locationCodeAddressList.find( PackFileLine( fileStringIdx, line ) );
if( it == m_data.locationCodeAddressList.end() )
{
return nullptr;
}
else
{
return &it->second;
}
}
const uint64_t* Worker::GetInlineSymbolList( uint64_t sym, uint32_t len )
{
DoPostponedInlineSymbols();
@ -8401,23 +8361,6 @@ void Worker::Write( FileWrite& f, bool fiDict )
f.Write( v.second.data, v.second.len );
}
sz = m_data.locationCodeAddressList.size();
f.Write( &sz, sizeof( sz ) );
for( auto& v : m_data.locationCodeAddressList )
{
f.Write( &v.first, sizeof( v.first ) );
uint16_t lsz = uint16_t( v.second.size() );
f.Write( &lsz, sizeof( lsz ) );
uint64_t ref = 0;
const uint64_t* ptr = v.second.data();
for( uint16_t i=0; i<lsz; i++ )
{
uint64_t diff = *ptr++ - ref;
ref += diff;
f.Write( &diff, sizeof( diff ) );
}
}
sz = m_data.codeSymbolMap.size();
f.Write( &sz, sizeof( sz ) );
for( auto& v : m_data.codeSymbolMap )

View File

@ -386,7 +386,6 @@ private:
uint64_t symbolCodeSize = 0;
unordered_flat_map<uint64_t, uint64_t> codeAddressToLocation;
unordered_flat_map<uint64_t, Vector<uint64_t>> locationCodeAddressList;
unordered_flat_map<const char*, MemoryBlock, charutil::Hasher, charutil::Comparator> sourceFileCache;
@ -546,7 +545,6 @@ public:
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 );
#ifndef TRACY_NO_STATISTICS