Change IsFrameExternal() interface to operate on StringIdx, move to Worker.

This commit is contained in:
Bartosz Taudul
2026-05-14 18:53:25 +02:00
parent 4a58c42e2d
commit 744bd21423
11 changed files with 43 additions and 59 deletions

View File

@@ -948,7 +948,7 @@ std::string TracyLlmTools::SourceSearch( std::string query, bool caseInsensitive
size_t total = 0;
for( auto& item : cache )
{
if( IsFrameExternal( item.first, nullptr ) ) continue;
if( m_worker.IsFrameExternal( StringIdx( m_worker.FindStringIdx( item.first ) ), StringIdx() ) ) continue;
if( !path.empty() && !std::regex_search( item.first, rxPath ) ) continue;
char* tmp = nullptr;

View File

@@ -213,17 +213,4 @@ std::vector<std::string> SplitLines( const char* data, size_t sz )
return ret;
}
bool IsFrameExternal( const char* filename, const char* image )
{
if( strncmp( filename, "/usr/", 5 ) == 0 || strncmp( filename, "/lib/", 5 ) == 0 || strcmp( filename, "[unknown]" ) == 0 || strcmp( filename, "<kernel>" ) == 0 ) return true;
if( strncmp( filename, "C:\\Program Files", 16 ) == 0 || strncmp( filename, "d:\\a01\\_work\\", 13 ) == 0 ) return true;
while( *filename )
{
if( filename[0] == '/' && filename[1] == '.' && filename[2] != '.' ) return true;
filename++;
}
if( !image ) return false;
return strncmp( image, "/usr/", 5 ) == 0 || strncmp( image, "/lib/", 5 ) == 0 || strncmp( image, "/lib64/", 7 ) == 0 || strcmp( image, "<kernel>" ) == 0;
}
}

View File

@@ -33,8 +33,6 @@ const char* FormatPlotValue( double val, PlotValueFormatting format );
std::vector<std::string> SplitLines( const char* data, size_t sz );
bool IsFrameExternal( const char* filename, const char* image );
}
#endif

View File

@@ -336,7 +336,7 @@ private:
unordered_flat_map<uint64_t, CallstackFrameTree> GetParentsCallstackFrameTreeTopDown( const unordered_flat_map<uint32_t, uint32_t>& stacks, bool group ) const;
void DrawParentsFrameTreeLevel( const unordered_flat_map<uint64_t, CallstackFrameTree>& tree, int& idx );
std::vector<CallstackFrameId> ReconstructZoneCallstack( const ZoneEvent& ev ) const;
std::vector<CallstackFrameId> ReconstructZoneCallstack( const ZoneEvent& ev );
void DrawInfoWindow();
void DrawZoneInfoWindow();
@@ -401,8 +401,8 @@ private:
std::vector<MemoryPage> GetMemoryPages() const;
void SmallCallstackButton( const char* name, uint32_t callstack, int& idx, uint64_t tid, bool tooltip = true );
void DrawCallstackCalls( uint32_t callstack, uint16_t limit ) const;
void DrawCallstackCalls( const CallstackFrameId* data, size_t size, uint16_t limit ) const;
void DrawCallstackCalls( uint32_t callstack, uint16_t limit );
void DrawCallstackCalls( const CallstackFrameId* data, size_t size, uint16_t limit );
nlohmann::json GetCallstackJson( const CallstackFrameId* data, size_t size ) const;
void SetViewToLastFrames();
int64_t GetZoneChildTime( const ZoneEvent& zone );

View File

@@ -417,10 +417,7 @@ void View::DrawCallstackTable( const CallstackFrameId* data, size_t size, uint64
if( match ) continue;
}
auto filename = m_worker.GetString( frame.file );
auto image = frameData->imageName.Active() ? m_worker.GetString( frameData->imageName ) : nullptr;
const bool isExternal = IsFrameExternal( filename, image );
const bool isExternal = m_worker.IsFrameExternal( frame.file, frameData->imageName );
if( isExternal )
{
if( !m_showExternalFrames )
@@ -511,6 +508,7 @@ void View::DrawCallstackTable( const CallstackFrameId* data, size_t size, uint64
indentVal = sin( time * 60.f ) * 10.f * time;
ImGui::Indent( indentVal );
}
auto filename = m_worker.GetString( frame.file );
switch( m_showCallstackFrameAddress )
{
case 0:
@@ -623,8 +621,9 @@ void View::DrawCallstackTable( const CallstackFrameId* data, size_t size, uint64
}
ImGui::PopTextWrapPos();
ImGui::TableNextColumn();
if( image )
if( frameData->imageName.Active() )
{
auto image = m_worker.GetString( frameData->imageName );
const char* end = image + strlen( image );
if( m_shortImageNames )
@@ -695,13 +694,13 @@ void View::SmallCallstackButton( const char* name, uint32_t callstack, int& idx,
}
}
void View::DrawCallstackCalls( uint32_t callstack, uint16_t limit ) const
void View::DrawCallstackCalls( uint32_t callstack, uint16_t limit )
{
const auto& csdata = m_worker.GetCallstack( callstack );
DrawCallstackCalls( csdata.data(), csdata.size(), limit );
}
void View::DrawCallstackCalls( const CallstackFrameId* data, size_t size, uint16_t limit ) const
void View::DrawCallstackCalls( const CallstackFrameId* data, size_t size, uint16_t limit )
{
bool first = true;
int i;
@@ -711,9 +710,7 @@ void View::DrawCallstackCalls( const CallstackFrameId* data, size_t size, uint16
const auto frameData = m_worker.GetCallstackFrame( v );
if( !frameData ) break;
const auto& frame = frameData->data[frameData->size - 1];
auto filename = m_worker.GetString( frame.file );
auto image = frameData->imageName.Active() ? m_worker.GetString( frameData->imageName ) : nullptr;
if( IsFrameExternal( filename, image ) ) continue;
if( m_worker.IsFrameExternal( frame.file, frameData->imageName ) ) continue;
if( first )
{
first = false;
@@ -748,9 +745,7 @@ void View::DrawCallstackCalls( const CallstackFrameId* data, size_t size, uint16
const auto frameData = m_worker.GetCallstackFrame( v );
if( !frameData ) break;
const auto& frame = frameData->data[frameData->size - 1];
auto filename = m_worker.GetString( frame.file );
auto image = frameData->imageName.Active() ? m_worker.GetString( frameData->imageName ) : nullptr;
if( IsFrameExternal( filename, image ) ) continue;
if( m_worker.IsFrameExternal( frame.file, frameData->imageName ) ) continue;
framesLeft = true;
break;
}
@@ -808,10 +803,6 @@ void View::CallstackTooltipContents( uint32_t idx )
if( match ) continue;
}
auto filename = m_worker.GetString( frame.file );
auto image = frameData->imageName.Active() ? m_worker.GetString( frameData->imageName ) : nullptr;
const auto external = IsFrameExternal( filename, image );
if( f == fsz-1 )
{
ImGui::TextDisabled( "%i.", fidx++ );
@@ -829,7 +820,7 @@ void View::CallstackTooltipContents( uint32_t idx )
{
TextColoredUnformatted( 0xFF8888FF, txt );
}
else if( external )
else if( m_worker.IsFrameExternal( frame.file, frameData->imageName ) )
{
if( m_vd.shortenName == ShortenName::Never )
{

View File

@@ -302,14 +302,9 @@ void View::BuildFlameGraph( const Worker& worker, std::vector<FlameGraphItem>& d
{
const auto frame = frameData->data[j-1];
const auto symaddr = frame.symAddr;
if( symaddr != 0 )
if( symaddr != 0 && !m_worker.IsFrameExternal( frame.file, frameData->imageName ) )
{
auto filename = m_worker.GetString( frame.file );
auto image = frameData->imageName.Active() ? m_worker.GetString( frameData->imageName ) : nullptr;
if( !IsFrameExternal( filename, image ) )
{
cache.emplace_back( FrameCache { symaddr, frame.name } );
}
cache.emplace_back( FrameCache { symaddr, frame.name } );
}
}
}
@@ -328,9 +323,7 @@ void View::BuildFlameGraph( const Worker& worker, std::vector<FlameGraphItem>& d
const auto symaddr = frame.symAddr;
if( symaddr != 0 )
{
auto filename = m_worker.GetString( frame.file );
auto image = frameData->imageName.Active() ? m_worker.GetString( frameData->imageName ) : nullptr;
cache.emplace_back( FrameCache { symaddr, frame.name, IsFrameExternal( filename, image ) } );
cache.emplace_back( FrameCache { symaddr, frame.name, m_worker.IsFrameExternal( frame.file, frameData->imageName ) } );
}
}
}

View File

@@ -1010,10 +1010,8 @@ void View::DrawSampleParents()
for( uint8_t f=0; f<fsz; f++ )
{
const auto& frame = frameData->data[f];
auto filename = m_worker.GetString( frame.file );
auto image = frameData->imageName.Active() ? m_worker.GetString( frameData->imageName ) : nullptr;
if( IsFrameExternal( filename, image ) )
if( m_worker.IsFrameExternal( frame.file, frameData->imageName ) )
{
if( !m_showExternalFrames )
{

View File

@@ -813,7 +813,7 @@ void View::DrawStatistics()
const auto image = m_worker.GetString( v.second.imageName );
bool pass =
( m_statShowKernel || ( v.first >> 63 ) == 0 ) &&
( m_statShowExternal || !IsFrameExternal( m_worker.GetString( v.second.file ), image ) ) &&
( m_statShowExternal || !m_worker.IsFrameExternal( v.second.file, v.second.imageName ) ) &&
m_statisticsFilter.PassFilter( name ) &&
m_statisticsImageFilter.PassFilter( image );
if( !pass && v.second.size.Val() == 0 )
@@ -827,7 +827,7 @@ void View::DrawStatistics()
const auto parentName = m_worker.GetString( pit->second.name );
pass =
( m_statShowKernel || ( parentAddr >> 63 ) == 0 ) &&
( m_statShowExternal || !IsFrameExternal( m_worker.GetString( pit->second.file ), image ) ) &&
( m_statShowExternal || !m_worker.IsFrameExternal( pit->second.file, v.second.imageName ) ) &&
m_statisticsFilter.PassFilter( parentName ) &&
m_statisticsImageFilter.PassFilter( image );
}
@@ -927,7 +927,7 @@ void View::DrawStatistics()
const auto image = m_worker.GetString( sit->second.imageName );
bool pass =
( m_statShowKernel || ( v.first >> 63 ) == 0 ) &&
( m_statShowExternal || !IsFrameExternal( m_worker.GetString( sit->second.file ), image ) ) &&
( m_statShowExternal || !m_worker.IsFrameExternal( sit->second.file, sit->second.imageName ) ) &&
m_statisticsFilter.PassFilter( name ) &&
m_statisticsImageFilter.PassFilter( image );
if( !pass && sit->second.size.Val() == 0 )
@@ -941,7 +941,7 @@ void View::DrawStatistics()
const auto parentName = m_worker.GetString( pit->second.name );
pass =
( m_statShowKernel || ( parentAddr >> 63 ) == 0 ) &&
( m_statShowExternal || !IsFrameExternal( m_worker.GetString( pit->second.file ), image ) ) &&
( m_statShowExternal || !m_worker.IsFrameExternal( pit->second.file, sit->second.imageName ) ) &&
m_statisticsFilter.PassFilter( parentName ) &&
m_statisticsImageFilter.PassFilter( image );
}

View File

@@ -999,7 +999,7 @@ nlohmann::json View::GetCallstackJson( const CallstackFrameId* data, size_t size
return json;
}
static size_t GetNumLocalFrames( const Worker& m_worker, const CallstackFrameId* data, size_t size )
static size_t GetNumLocalFrames( Worker& m_worker, const CallstackFrameId* data, size_t size )
{
size_t local = 0;
auto end = data + size;
@@ -1008,14 +1008,12 @@ static size_t GetNumLocalFrames( const Worker& m_worker, const CallstackFrameId*
const auto frameData = m_worker.GetCallstackFrame( *data++ );
if( !frameData ) continue;
const auto& frame = frameData->data[frameData->size - 1];
auto filename = m_worker.GetString( frame.file );
auto image = frameData->imageName.Active() ? m_worker.GetString( frameData->imageName ) : nullptr;
if( !IsFrameExternal( filename, image ) ) local++;
if( !m_worker.IsFrameExternal( frame.file, frameData->imageName ) ) local++;
}
return local;
}
std::vector<CallstackFrameId> View::ReconstructZoneCallstack( const ZoneEvent& ev ) const
std::vector<CallstackFrameId> View::ReconstructZoneCallstack( const ZoneEvent& ev )
{
constexpr int SampleLimit = 10000;
std::vector<CallstackFrameId> ret;

View File

@@ -8934,4 +8934,22 @@ void Worker::CacheSourceFiles()
}
}
static bool IsFrameExternalImpl( const char* filename, const char* image )
{
if( strncmp( filename, "/usr/", 5 ) == 0 || strncmp( filename, "/lib/", 5 ) == 0 || strcmp( filename, "[unknown]" ) == 0 || strcmp( filename, "<kernel>" ) == 0 ) return true;
if( strncmp( filename, "C:\\Program Files", 16 ) == 0 || strncmp( filename, "d:\\a01\\_work\\", 13 ) == 0 ) return true;
while( *filename )
{
if( filename[0] == '/' && filename[1] == '.' && filename[2] != '.' ) return true;
filename++;
}
if( !image ) return false;
return strncmp( image, "/usr/", 5 ) == 0 || strncmp( image, "/lib/", 5 ) == 0 || strncmp( image, "/lib64/", 7 ) == 0 || strcmp( image, "<kernel>" ) == 0;
}
bool Worker::IsFrameExternal( StringIdx filename, StringIdx image )
{
return IsFrameExternalImpl( GetString( filename ), image.Active() ? GetString( image ) : nullptr );
}
}

View File

@@ -703,6 +703,7 @@ public:
void DoPostponedWorkAll();
void CacheSourceFiles();
bool IsFrameExternal( StringIdx filename, StringIdx image );
StringLocation StoreString( const char* str, size_t sz );