mirror of
https://github.com/wolfpld/tracy.git
synced 2024-11-10 02:31:48 +00:00
Use cached source files.
This commit is contained in:
parent
d470202bca
commit
ee22cf3b0c
@ -4,8 +4,9 @@
|
||||
namespace tracy
|
||||
{
|
||||
|
||||
bool SourceFileValid( const char* fn, uint64_t olderThan, const View& view )
|
||||
bool SourceFileValid( const char* fn, uint64_t olderThan, const View& view, const Worker& worker )
|
||||
{
|
||||
if( worker.GetSourceFileFromCache( fn ).data != nullptr ) return true;
|
||||
struct stat buf;
|
||||
if( stat( view.SourceSubstitution( fn ), &buf ) == 0 && ( buf.st_mode & S_IFREG ) != 0 )
|
||||
{
|
||||
|
@ -8,6 +8,7 @@ namespace tracy
|
||||
{
|
||||
|
||||
class View;
|
||||
class Worker;
|
||||
|
||||
static inline bool FileExists( const char* fn )
|
||||
{
|
||||
@ -15,7 +16,7 @@ static inline bool FileExists( const char* fn )
|
||||
return stat( fn, &buf ) == 0 && ( buf.st_mode & S_IFREG ) != 0;
|
||||
}
|
||||
|
||||
bool SourceFileValid( const char* fn, uint64_t olderThan, const View& view );
|
||||
bool SourceFileValid( const char* fn, uint64_t olderThan, const View& view, const Worker& worker );
|
||||
bool SourceFileValid( const char* fn, uint64_t olderThan );
|
||||
|
||||
}
|
||||
|
@ -75,6 +75,7 @@ SourceView::SourceView( ImFont* font )
|
||||
, m_symAddr( 0 )
|
||||
, m_targetAddr( 0 )
|
||||
, m_data( nullptr )
|
||||
, m_dataBuf( nullptr )
|
||||
, m_dataSize( 0 )
|
||||
, m_targetLine( 0 )
|
||||
, m_selectedLine( 0 )
|
||||
@ -294,7 +295,7 @@ SourceView::SourceView( ImFont* font )
|
||||
|
||||
SourceView::~SourceView()
|
||||
{
|
||||
delete[] m_data;
|
||||
delete[] m_dataBuf;
|
||||
}
|
||||
|
||||
static constexpr uint32_t PackCpuInfo( uint32_t cpuid )
|
||||
@ -385,7 +386,7 @@ void SourceView::SetCpuId( uint32_t cpuId )
|
||||
SelectMicroArchitecture( "ZEN2" );
|
||||
}
|
||||
|
||||
void SourceView::OpenSource( const char* fileName, int line, const View& view )
|
||||
void SourceView::OpenSource( const char* fileName, int line, const View& view, const Worker& worker )
|
||||
{
|
||||
m_targetLine = line;
|
||||
m_selectedLine = line;
|
||||
@ -394,7 +395,7 @@ void SourceView::OpenSource( const char* fileName, int line, const View& view )
|
||||
m_symAddr = 0;
|
||||
m_sourceFiles.clear();
|
||||
|
||||
ParseSource( fileName, nullptr, view );
|
||||
ParseSource( fileName, worker, view );
|
||||
assert( !m_lines.empty() );
|
||||
}
|
||||
|
||||
@ -408,7 +409,7 @@ void SourceView::OpenSymbol( const char* fileName, int line, uint64_t baseAddr,
|
||||
m_selectedAddresses.clear();
|
||||
m_selectedAddresses.emplace( symAddr );
|
||||
|
||||
ParseSource( fileName, &worker, view );
|
||||
ParseSource( fileName, worker, view );
|
||||
Disassemble( baseAddr, worker );
|
||||
SelectLine( line, &worker, true, symAddr );
|
||||
|
||||
@ -430,28 +431,40 @@ void SourceView::OpenSymbol( const char* fileName, int line, uint64_t baseAddr,
|
||||
}
|
||||
}
|
||||
|
||||
void SourceView::ParseSource( const char* fileName, const Worker* worker, const View& view )
|
||||
void SourceView::ParseSource( const char* fileName, const Worker& worker, const View& view )
|
||||
{
|
||||
if( m_file != fileName )
|
||||
{
|
||||
m_file = fileName;
|
||||
m_fileStringIdx = worker ? worker->FindStringIdx( fileName ) : 0;
|
||||
m_fileStringIdx = worker.FindStringIdx( fileName );
|
||||
m_lines.clear();
|
||||
if( fileName )
|
||||
{
|
||||
FILE* f = fopen( view.SourceSubstitution( fileName ), "rb" );
|
||||
fseek( f, 0, SEEK_END );
|
||||
const auto sz = ftell( f );
|
||||
fseek( f, 0, SEEK_SET );
|
||||
if( sz > m_dataSize )
|
||||
uint32_t sz;
|
||||
const auto srcCache = worker.GetSourceFileFromCache( fileName );
|
||||
if( srcCache.data != nullptr )
|
||||
{
|
||||
delete[] m_data;
|
||||
m_data = new char[sz+1];
|
||||
m_dataSize = sz;
|
||||
m_data = srcCache.data;
|
||||
sz = srcCache.len;
|
||||
}
|
||||
else
|
||||
{
|
||||
FILE* f = fopen( view.SourceSubstitution( fileName ), "rb" );
|
||||
assert( f );
|
||||
fseek( f, 0, SEEK_END );
|
||||
sz = ftell( f );
|
||||
fseek( f, 0, SEEK_SET );
|
||||
if( sz > m_dataSize )
|
||||
{
|
||||
delete[] m_dataBuf;
|
||||
m_dataBuf = new char[sz+1];
|
||||
m_dataSize = sz;
|
||||
}
|
||||
fread( m_dataBuf, 1, sz, f );
|
||||
m_dataBuf[sz] = '\0';
|
||||
m_data = m_dataBuf;
|
||||
fclose( f );
|
||||
}
|
||||
fread( m_data, 1, sz, f );
|
||||
m_data[sz] = '\0';
|
||||
fclose( f );
|
||||
|
||||
m_tokenizer.Reset();
|
||||
auto txt = m_data;
|
||||
@ -1132,7 +1145,7 @@ void SourceView::RenderSymbolView( const Worker& worker, View& view )
|
||||
{
|
||||
auto line = sym->line;
|
||||
auto file = line == 0 ? nullptr : worker.GetString( sym->file );
|
||||
if( file && !SourceFileValid( file, worker.GetCaptureTime(), view ) )
|
||||
if( file && !SourceFileValid( file, worker.GetCaptureTime(), view, worker ) )
|
||||
{
|
||||
file = nullptr;
|
||||
line = 0;
|
||||
@ -1211,12 +1224,12 @@ void SourceView::RenderSymbolSourceView( uint32_t iptotal, unordered_flat_map<ui
|
||||
SmallColorBox( color );
|
||||
ImGui::SameLine();
|
||||
auto fstr = worker.GetString( StringIdx( v.first ) );
|
||||
if( SourceFileValid( fstr, worker.GetCaptureTime(), view ) )
|
||||
if( SourceFileValid( fstr, worker.GetCaptureTime(), view, worker ) )
|
||||
{
|
||||
ImGui::PushID( v.first );
|
||||
if( ImGui::Selectable( fstr, fstr == m_file ) )
|
||||
{
|
||||
ParseSource( fstr, &worker, view );
|
||||
ParseSource( fstr, worker, view );
|
||||
m_targetLine = v.second;
|
||||
SelectLine( v.second, &worker );
|
||||
}
|
||||
@ -1296,7 +1309,7 @@ void SourceView::RenderSymbolSourceView( uint32_t iptotal, unordered_flat_map<ui
|
||||
SmallColorBox( color );
|
||||
ImGui::SameLine();
|
||||
auto fstr = worker.GetString( StringIdx( v.first ) );
|
||||
if( SourceFileValid( fstr, worker.GetCaptureTime(), view ) )
|
||||
if( SourceFileValid( fstr, worker.GetCaptureTime(), view, worker ) )
|
||||
{
|
||||
ImGui::PushID( v.first );
|
||||
if( ImGui::Selectable( fstr, fstr == m_file, ImGuiSelectableFlags_SpanAllColumns ) )
|
||||
@ -1310,7 +1323,7 @@ void SourceView::RenderSymbolSourceView( uint32_t iptotal, unordered_flat_map<ui
|
||||
break;
|
||||
}
|
||||
}
|
||||
ParseSource( fstr, &worker, view );
|
||||
ParseSource( fstr, worker, view );
|
||||
m_targetLine = line;
|
||||
SelectLine( line, &worker );
|
||||
}
|
||||
@ -2413,9 +2426,9 @@ void SourceView::RenderAsmLine( AsmLine& line, uint32_t ipcnt, uint32_t iptotal,
|
||||
SelectLine( srcline, &worker, false );
|
||||
m_displayMode = DisplayMixed;
|
||||
}
|
||||
else if( SourceFileValid( fileName, worker.GetCaptureTime(), view ) )
|
||||
else if( SourceFileValid( fileName, worker.GetCaptureTime(), view, worker ) )
|
||||
{
|
||||
ParseSource( fileName, &worker, view );
|
||||
ParseSource( fileName, worker, view );
|
||||
m_targetLine = srcline;
|
||||
SelectLine( srcline, &worker, false );
|
||||
m_displayMode = DisplayMixed;
|
||||
|
@ -132,14 +132,14 @@ public:
|
||||
|
||||
void SetCpuId( uint32_t cpuid );
|
||||
|
||||
void OpenSource( const char* fileName, int line, const View& view );
|
||||
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 Render( const Worker& worker, View& view );
|
||||
|
||||
void CalcInlineStats( bool val ) { m_calcInlineStats = val; }
|
||||
|
||||
private:
|
||||
void ParseSource( const char* fileName, const Worker* worker, const View& view );
|
||||
void ParseSource( const char* fileName, const Worker& worker, const View& view );
|
||||
bool Disassemble( uint64_t symAddr, const Worker& worker );
|
||||
|
||||
void RenderSimpleSourceView();
|
||||
@ -190,7 +190,8 @@ private:
|
||||
uint64_t m_symAddr;
|
||||
uint64_t m_baseAddr;
|
||||
uint64_t m_targetAddr;
|
||||
char* m_data;
|
||||
const char* m_data;
|
||||
char* m_dataBuf;
|
||||
size_t m_dataSize;
|
||||
int m_targetLine;
|
||||
int m_selectedLine;
|
||||
|
@ -195,7 +195,7 @@ void View::ViewSource( const char* fileName, int line )
|
||||
{
|
||||
assert( fileName );
|
||||
m_sourceViewFile = fileName;
|
||||
m_sourceView->OpenSource( fileName, line, *this );
|
||||
m_sourceView->OpenSource( fileName, line, *this, m_worker );
|
||||
}
|
||||
|
||||
void View::ViewSymbol( const char* fileName, int line, uint64_t baseAddr, uint64_t symAddr )
|
||||
@ -213,7 +213,7 @@ bool View::ViewDispatch( const char* fileName, int line, uint64_t symAddr )
|
||||
}
|
||||
else
|
||||
{
|
||||
if( !SourceFileValid( fileName, m_worker.GetCaptureTime(), *this ) )
|
||||
if( !SourceFileValid( fileName, m_worker.GetCaptureTime(), *this, m_worker ) )
|
||||
{
|
||||
fileName = nullptr;
|
||||
line = 0;
|
||||
@ -6403,7 +6403,7 @@ void View::DrawZoneInfoWindow()
|
||||
}
|
||||
}
|
||||
const auto fileName = m_worker.GetString( srcloc.file );
|
||||
if( SourceFileValid( fileName, m_worker.GetCaptureTime(), *this ) )
|
||||
if( SourceFileValid( fileName, m_worker.GetCaptureTime(), *this, m_worker ) )
|
||||
{
|
||||
ImGui::SameLine();
|
||||
bool hilite = m_sourceViewFile == fileName;
|
||||
@ -6941,7 +6941,7 @@ void View::DrawZoneInfoWindow()
|
||||
ImGui::PopID();
|
||||
if( ImGui::IsItemClicked( 1 ) )
|
||||
{
|
||||
if( SourceFileValid( fileName, m_worker.GetCaptureTime(), *this ) )
|
||||
if( SourceFileValid( fileName, m_worker.GetCaptureTime(), *this, m_worker ) )
|
||||
{
|
||||
ViewSource( fileName, srcloc.line );
|
||||
}
|
||||
@ -7363,7 +7363,7 @@ void View::DrawGpuInfoWindow()
|
||||
}
|
||||
}
|
||||
const auto fileName = m_worker.GetString( srcloc.file );
|
||||
if( SourceFileValid( fileName, m_worker.GetCaptureTime(), *this ) )
|
||||
if( SourceFileValid( fileName, m_worker.GetCaptureTime(), *this, m_worker ) )
|
||||
{
|
||||
ImGui::SameLine();
|
||||
bool hilite = m_sourceViewFile == fileName;
|
||||
@ -7478,7 +7478,7 @@ void View::DrawGpuInfoWindow()
|
||||
ImGui::PopID();
|
||||
if( ImGui::IsItemClicked( 1 ) )
|
||||
{
|
||||
if( SourceFileValid( fileName, m_worker.GetCaptureTime(), *this ) )
|
||||
if( SourceFileValid( fileName, m_worker.GetCaptureTime(), *this, m_worker ) )
|
||||
{
|
||||
ViewSource( fileName, srcloc.line );
|
||||
}
|
||||
@ -8054,7 +8054,7 @@ void View::DrawOptions()
|
||||
ImGui::TextDisabled( "(%s) %s:%i", RealToString( l.second->timeline.size() ), fileName, sl.line );
|
||||
if( ImGui::IsItemClicked( 1 ) )
|
||||
{
|
||||
if( SourceFileValid( fileName, m_worker.GetCaptureTime(), *this ) )
|
||||
if( SourceFileValid( fileName, m_worker.GetCaptureTime(), *this, m_worker ) )
|
||||
{
|
||||
ViewSource( fileName, sl.line );
|
||||
}
|
||||
@ -8128,7 +8128,7 @@ void View::DrawOptions()
|
||||
ImGui::TextDisabled( "(%s) %s:%i", RealToString( l.second->timeline.size() ), fileName, sl.line );
|
||||
if( ImGui::IsItemClicked( 1 ) )
|
||||
{
|
||||
if( SourceFileValid( fileName, m_worker.GetCaptureTime(), *this ) )
|
||||
if( SourceFileValid( fileName, m_worker.GetCaptureTime(), *this, m_worker ) )
|
||||
{
|
||||
ViewSource( fileName, sl.line );
|
||||
}
|
||||
@ -8202,7 +8202,7 @@ void View::DrawOptions()
|
||||
ImGui::TextDisabled( "(%s) %s:%i", RealToString( l.second->timeline.size() ), fileName, sl.line );
|
||||
if( ImGui::IsItemClicked( 1 ) )
|
||||
{
|
||||
if( SourceFileValid( fileName, m_worker.GetCaptureTime(), *this ) )
|
||||
if( SourceFileValid( fileName, m_worker.GetCaptureTime(), *this, m_worker ) )
|
||||
{
|
||||
ViewSource( fileName, sl.line );
|
||||
}
|
||||
@ -8773,7 +8773,7 @@ void View::DrawFindZone()
|
||||
ImGui::TextColored( ImVec4( 0.5, 0.5, 0.5, 1 ), "(%s) %s:%i", RealToString( zones.size() ), fileName, srcloc.line );
|
||||
if( ImGui::IsItemClicked( 1 ) )
|
||||
{
|
||||
if( SourceFileValid( fileName, m_worker.GetCaptureTime(), *this ) )
|
||||
if( SourceFileValid( fileName, m_worker.GetCaptureTime(), *this, m_worker ) )
|
||||
{
|
||||
ViewSource( fileName, srcloc.line );
|
||||
}
|
||||
@ -11407,7 +11407,7 @@ void View::DrawStatistics()
|
||||
ImGui::TextDisabled( "%s:%i", file, srcloc.line );
|
||||
if( ImGui::IsItemClicked( 1 ) )
|
||||
{
|
||||
if( SourceFileValid( file, m_worker.GetCaptureTime(), *this ) )
|
||||
if( SourceFileValid( file, m_worker.GetCaptureTime(), *this, m_worker ) )
|
||||
{
|
||||
ViewSource( file, srcloc.line );
|
||||
}
|
||||
@ -11781,7 +11781,7 @@ void View::DrawStatistics()
|
||||
}
|
||||
if( ImGui::IsItemClicked( 1 ) )
|
||||
{
|
||||
if( SourceFileValid( file, m_worker.GetCaptureTime(), *this ) )
|
||||
if( SourceFileValid( file, m_worker.GetCaptureTime(), *this, m_worker ) )
|
||||
{
|
||||
ViewSymbol( file, line, codeAddr, v.symAddr );
|
||||
if( !m_statSeparateInlines ) m_sourceView->CalcInlineStats( false );
|
||||
@ -11942,7 +11942,7 @@ void View::DrawStatistics()
|
||||
}
|
||||
if( ImGui::IsItemClicked( 1 ) )
|
||||
{
|
||||
if( SourceFileValid( file, m_worker.GetCaptureTime(), *this ) )
|
||||
if( SourceFileValid( file, m_worker.GetCaptureTime(), *this, m_worker ) )
|
||||
{
|
||||
ViewSymbol( file, line, codeAddr, iv.symAddr );
|
||||
if( !m_statSeparateInlines ) m_sourceView->CalcInlineStats( true );
|
||||
@ -13366,7 +13366,7 @@ void View::DrawLockInfoWindow()
|
||||
ImGui::Text( "%s:%i", fileName, srcloc.line );
|
||||
if( ImGui::IsItemClicked( 1 ) )
|
||||
{
|
||||
if( SourceFileValid( fileName, m_worker.GetCaptureTime(), *this ) )
|
||||
if( SourceFileValid( fileName, m_worker.GetCaptureTime(), *this, m_worker ) )
|
||||
{
|
||||
ViewSource( fileName, srcloc.line );
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user