From 01d7fefe525b1b7fe51cbe6b49a855983f201661 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Fri, 17 Apr 2020 19:09:13 +0200 Subject: [PATCH] Perform source file name substitution. --- profiler/build/win32/Tracy.vcxproj | 1 + profiler/build/win32/Tracy.vcxproj.filters | 3 ++ server/TracyFilesystem.cpp | 17 +++++++++++ server/TracyFilesystem.hpp | 13 +++------ server/TracySourceView.cpp | 34 +++++++++++----------- server/TracySourceView.hpp | 11 +++---- server/TracyView.cpp | 30 +++++++++---------- server/TracyView.hpp | 2 ++ 8 files changed, 64 insertions(+), 47 deletions(-) create mode 100644 server/TracyFilesystem.cpp diff --git a/profiler/build/win32/Tracy.vcxproj b/profiler/build/win32/Tracy.vcxproj index c36b5a3f..d84fa9ea 100644 --- a/profiler/build/win32/Tracy.vcxproj +++ b/profiler/build/win32/Tracy.vcxproj @@ -113,6 +113,7 @@ + diff --git a/profiler/build/win32/Tracy.vcxproj.filters b/profiler/build/win32/Tracy.vcxproj.filters index 2cfdeb54..876b49cf 100644 --- a/profiler/build/win32/Tracy.vcxproj.filters +++ b/profiler/build/win32/Tracy.vcxproj.filters @@ -195,6 +195,9 @@ server + + server + diff --git a/server/TracyFilesystem.cpp b/server/TracyFilesystem.cpp new file mode 100644 index 00000000..e33de71c --- /dev/null +++ b/server/TracyFilesystem.cpp @@ -0,0 +1,17 @@ +#include "TracyFilesystem.hpp" +#include "TracyView.hpp" + +namespace tracy +{ + +bool SourceFileValid( const char* fn, uint64_t olderThan, const View& view ) +{ + struct stat buf; + if( stat( view.SourceSubstitution( fn ), &buf ) == 0 && ( buf.st_mode & S_IFREG ) != 0 ) + { + return (uint64_t)buf.st_mtime < olderThan; + } + return false; +} + +} diff --git a/server/TracyFilesystem.hpp b/server/TracyFilesystem.hpp index 1ee8cc1f..40c9a62f 100644 --- a/server/TracyFilesystem.hpp +++ b/server/TracyFilesystem.hpp @@ -1,26 +1,21 @@ #ifndef __TRACYFILESYSTEM_HPP__ #define __TRACYFILESYSTEM_HPP__ +#include #include namespace tracy { +class View; + static inline bool FileExists( const char* fn ) { struct stat buf; return stat( fn, &buf ) == 0 && ( buf.st_mode & S_IFREG ) != 0; } -static inline bool SourceFileValid( const char* fn, uint64_t olderThan ) -{ - struct stat buf; - if( stat( fn, &buf ) == 0 && ( buf.st_mode & S_IFREG ) != 0 ) - { - return (uint64_t)buf.st_mtime < olderThan; - } - return false; -} +bool SourceFileValid( const char* fn, uint64_t olderThan, const View& view ); } diff --git a/server/TracySourceView.cpp b/server/TracySourceView.cpp index 12122edb..3bea8d1a 100644 --- a/server/TracySourceView.cpp +++ b/server/TracySourceView.cpp @@ -323,7 +323,7 @@ bool SourceView::Disassemble( uint64_t symAddr, const Worker& worker ) return true; } -void SourceView::Render( const Worker& worker ) +void SourceView::Render( const Worker& worker, const View& view ) { m_highlightAddr.Decay( 0 ); m_hoveredLine.Decay( 0 ); @@ -342,7 +342,7 @@ void SourceView::Render( const Worker& worker ) } else { - RenderSymbolView( worker ); + RenderSymbolView( worker, view ); } } @@ -378,7 +378,7 @@ void SourceView::RenderSimpleSourceView() ImGui::EndChild(); } -void SourceView::RenderSymbolView( const Worker& worker ) +void SourceView::RenderSymbolView( const Worker& worker, const View& view ) { assert( m_symAddr != 0 ); @@ -558,16 +558,16 @@ void SourceView::RenderSymbolView( const Worker& worker ) switch( m_displayMode ) { case DisplaySource: - RenderSymbolSourceView( iptotalSrc, ipcountSrc, ipcountAsm, ipmaxSrc, worker ); + RenderSymbolSourceView( iptotalSrc, ipcountSrc, ipcountAsm, ipmaxSrc, worker, view ); break; case DisplayAsm: - jumpOut = RenderSymbolAsmView( iptotalAsm, ipcountAsm, ipmaxAsm, worker ); + jumpOut = RenderSymbolAsmView( iptotalAsm, ipcountAsm, ipmaxAsm, worker, view ); break; case DisplayMixed: ImGui::Columns( 2 ); - RenderSymbolSourceView( iptotalSrc, ipcountSrc, ipcountAsm, ipmaxSrc, worker ); + RenderSymbolSourceView( iptotalSrc, ipcountSrc, ipcountAsm, ipmaxSrc, worker, view ); ImGui::NextColumn(); - jumpOut = RenderSymbolAsmView( iptotalAsm, ipcountAsm, ipmaxAsm, worker ); + jumpOut = RenderSymbolAsmView( iptotalAsm, ipcountAsm, ipmaxAsm, worker, view ); ImGui::EndColumns(); break; default: @@ -582,7 +582,7 @@ void SourceView::RenderSymbolView( const Worker& worker ) { auto line = sym->line; auto file = line == 0 ? nullptr : worker.GetString( sym->file ); - if( file && !SourceFileValid( file, worker.GetCaptureTime() ) ) + if( file && !SourceFileValid( file, worker.GetCaptureTime(), view ) ) { file = nullptr; line = 0; @@ -620,7 +620,7 @@ static uint32_t GetHotnessColor( uint32_t ipSum, uint32_t maxIpCount ) } -void SourceView::RenderSymbolSourceView( uint32_t iptotal, unordered_flat_map ipcount, unordered_flat_map ipcountAsm, uint32_t ipmax, const Worker& worker ) +void SourceView::RenderSymbolSourceView( uint32_t iptotal, unordered_flat_map ipcount, unordered_flat_map ipcountAsm, uint32_t ipmax, const Worker& worker, const View& view ) { if( m_sourceFiles.empty() ) { @@ -661,7 +661,7 @@ void SourceView::RenderSymbolSourceView( uint32_t iptotal, unordered_flat_map ipcount, uint32_t ipmax, const Worker& worker ) +uint64_t SourceView::RenderSymbolAsmView( uint32_t iptotal, unordered_flat_map ipcount, uint32_t ipmax, const Worker& worker, const View& view ) { SmallCheckbox( ICON_FA_SEARCH_LOCATION " Relative locations", &m_asmRelative ); if( !m_sourceFiles.empty() ) @@ -919,7 +919,7 @@ uint64_t SourceView::RenderSymbolAsmView( uint32_t iptotal, unordered_flat_mapsecond; - RenderAsmLine( line, ipcnt, iptotal, ipmax, worker, jumpOut, maxAddrLen ); + RenderAsmLine( line, ipcnt, iptotal, ipmax, worker, jumpOut, maxAddrLen, view ); insList.emplace_back( line.addr ); } } @@ -1279,7 +1279,7 @@ void SourceView::RenderLine( const Line& line, int lineNum, uint32_t ipcnt, uint draw->AddLine( wpos + ImVec2( 0, ty+2 ), wpos + ImVec2( w, ty+2 ), 0x08FFFFFF ); } -void SourceView::RenderAsmLine( const AsmLine& line, uint32_t ipcnt, uint32_t iptotal, uint32_t ipmax, const Worker& worker, uint64_t& jumpOut, int maxAddrLen ) +void SourceView::RenderAsmLine( const AsmLine& line, uint32_t ipcnt, uint32_t iptotal, uint32_t ipmax, const Worker& worker, uint64_t& jumpOut, int maxAddrLen, const View& view ) { const auto ty = ImGui::GetFontSize(); auto draw = ImGui::GetWindowDrawList(); @@ -1379,7 +1379,7 @@ void SourceView::RenderAsmLine( const AsmLine& line, uint32_t ipcnt, uint32_t ip SelectLine( srcline, &worker, false ); m_displayMode = DisplayMixed; } - else if( SourceFileValid( fileName, worker.GetCaptureTime() ) ) + else if( SourceFileValid( fileName, worker.GetCaptureTime(), view ) ) { ParseSource( fileName, &worker ); m_targetLine = srcline; diff --git a/server/TracySourceView.hpp b/server/TracySourceView.hpp index bd6a45e4..4258e7cb 100644 --- a/server/TracySourceView.hpp +++ b/server/TracySourceView.hpp @@ -12,6 +12,7 @@ struct ImFont; namespace tracy { +class View; class Worker; class SourceView @@ -51,7 +52,7 @@ public: void OpenSource( const char* fileName, int line ); void OpenSymbol( const char* fileName, int line, uint64_t baseAddr, uint64_t symAddr, const Worker& worker ); - void Render( const Worker& worker ); + void Render( const Worker& worker, const View& view ); void CalcInlineStats( bool val ) { m_calcInlineStats = val; } @@ -60,13 +61,13 @@ private: bool Disassemble( uint64_t symAddr, const Worker& worker ); void RenderSimpleSourceView(); - void RenderSymbolView( const Worker& worker ); + void RenderSymbolView( const Worker& worker, const View& view ); - void RenderSymbolSourceView( uint32_t iptotal, unordered_flat_map ipcount, unordered_flat_map ipcountAsm, uint32_t ipmax, const Worker& worker ); - uint64_t RenderSymbolAsmView( uint32_t iptotal, unordered_flat_map ipcount, uint32_t ipmax, const Worker& worker ); + void RenderSymbolSourceView( uint32_t iptotal, unordered_flat_map ipcount, unordered_flat_map ipcountAsm, uint32_t ipmax, const Worker& worker, const View& view ); + uint64_t RenderSymbolAsmView( uint32_t iptotal, unordered_flat_map ipcount, uint32_t ipmax, const Worker& worker, const View& view ); void RenderLine( const Line& line, int lineNum, uint32_t ipcnt, uint32_t iptotal, uint32_t ipmax, const Worker* worker ); - void RenderAsmLine( const AsmLine& line, uint32_t ipcnt, uint32_t iptotal, uint32_t ipmax, const Worker& worker, uint64_t& jumpOut, int maxAddrLen ); + void RenderAsmLine( const AsmLine& line, uint32_t ipcnt, uint32_t iptotal, uint32_t ipmax, const Worker& worker, uint64_t& jumpOut, int maxAddrLen, const View& view ); void SelectLine( uint32_t line, const Worker* worker, bool changeAsmLine = true, uint64_t targetAddr = 0 ); void SelectAsmLines( uint32_t file, uint32_t line, const Worker& worker, bool changeAsmLine = true, uint64_t targetAddr = 0 ); diff --git a/server/TracyView.cpp b/server/TracyView.cpp index 8ef1fbfc..08808087 100644 --- a/server/TracyView.cpp +++ b/server/TracyView.cpp @@ -27,12 +27,10 @@ #endif #include "tracy_pdqsort.h" -#include "TracyBadVersion.hpp" #include "TracyColor.hpp" #include "TracyFileRead.hpp" #include "TracyFileWrite.hpp" #include "TracyFilesystem.hpp" -#include "TracyImGui.hpp" #include "TracyPopcnt.hpp" #include "TracyPrint.hpp" #include "TracySort.hpp" @@ -215,7 +213,7 @@ bool View::ViewDispatch( const char* fileName, int line, uint64_t symAddr ) } else { - if( !SourceFileValid( fileName, m_worker.GetCaptureTime() ) ) + if( !SourceFileValid( fileName, m_worker.GetCaptureTime(), *this ) ) { fileName = nullptr; line = 0; @@ -6264,7 +6262,7 @@ void View::DrawZoneInfoWindow() } } const auto fileName = m_worker.GetString( srcloc.file ); - if( SourceFileValid( fileName, m_worker.GetCaptureTime() ) ) + if( SourceFileValid( fileName, m_worker.GetCaptureTime(), *this ) ) { ImGui::SameLine(); bool hilite = m_sourceViewFile == fileName; @@ -6795,7 +6793,7 @@ void View::DrawZoneInfoWindow() ImGui::PopID(); if( ImGui::IsItemClicked( 1 ) ) { - if( SourceFileValid( fileName, m_worker.GetCaptureTime() ) ) + if( SourceFileValid( fileName, m_worker.GetCaptureTime(), *this ) ) { ViewSource( fileName, srcloc.line ); } @@ -7217,7 +7215,7 @@ void View::DrawGpuInfoWindow() } } const auto fileName = m_worker.GetString( srcloc.file ); - if( SourceFileValid( fileName, m_worker.GetCaptureTime() ) ) + if( SourceFileValid( fileName, m_worker.GetCaptureTime(), *this ) ) { ImGui::SameLine(); bool hilite = m_sourceViewFile == fileName; @@ -7332,7 +7330,7 @@ void View::DrawGpuInfoWindow() ImGui::PopID(); if( ImGui::IsItemClicked( 1 ) ) { - if( SourceFileValid( fileName, m_worker.GetCaptureTime() ) ) + if( SourceFileValid( fileName, m_worker.GetCaptureTime(), *this ) ) { ViewSource( fileName, srcloc.line ); } @@ -7908,7 +7906,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() ) ) + if( SourceFileValid( fileName, m_worker.GetCaptureTime(), *this ) ) { ViewSource( fileName, sl.line ); } @@ -7982,7 +7980,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() ) ) + if( SourceFileValid( fileName, m_worker.GetCaptureTime(), *this ) ) { ViewSource( fileName, sl.line ); } @@ -8056,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() ) ) + if( SourceFileValid( fileName, m_worker.GetCaptureTime(), *this ) ) { ViewSource( fileName, sl.line ); } @@ -8627,7 +8625,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() ) ) + if( SourceFileValid( fileName, m_worker.GetCaptureTime(), *this ) ) { ViewSource( fileName, srcloc.line ); } @@ -11260,7 +11258,7 @@ void View::DrawStatistics() ImGui::TextDisabled( "%s:%i", file, srcloc.line ); if( ImGui::IsItemClicked( 1 ) ) { - if( SourceFileValid( file, m_worker.GetCaptureTime() ) ) + if( SourceFileValid( file, m_worker.GetCaptureTime(), *this ) ) { ViewSource( file, srcloc.line ); } @@ -11625,7 +11623,7 @@ void View::DrawStatistics() } if( ImGui::IsItemClicked( 1 ) ) { - if( SourceFileValid( file, m_worker.GetCaptureTime() ) ) + if( SourceFileValid( file, m_worker.GetCaptureTime(), *this ) ) { ViewSymbol( file, line, codeAddr, v.symAddr ); if( !m_statSeparateInlines ) m_sourceView->CalcInlineStats( false ); @@ -11783,7 +11781,7 @@ void View::DrawStatistics() } if( ImGui::IsItemClicked( 1 ) ) { - if( SourceFileValid( file, m_worker.GetCaptureTime() ) ) + if( SourceFileValid( file, m_worker.GetCaptureTime(), *this ) ) { ViewSymbol( file, line, codeAddr, iv.symAddr ); if( !m_statSeparateInlines ) m_sourceView->CalcInlineStats( true ); @@ -13078,7 +13076,7 @@ void View::DrawTextEditor() ImGui::SetNextWindowSize( ImVec2( 700, 800 ), ImGuiCond_FirstUseEver ); bool show = true; ImGui::Begin( "Source view", &show, ImGuiWindowFlags_NoScrollbar ); - m_sourceView->Render( m_worker ); + m_sourceView->Render( m_worker, *this ); ImGui::End(); if( !show ) m_sourceViewFile = nullptr; } @@ -13205,7 +13203,7 @@ void View::DrawLockInfoWindow() ImGui::Text( "%s:%i", fileName, srcloc.line ); if( ImGui::IsItemClicked( 1 ) ) { - if( SourceFileValid( fileName, m_worker.GetCaptureTime() ) ) + if( SourceFileValid( fileName, m_worker.GetCaptureTime(), *this ) ) { ViewSource( fileName, srcloc.line ); } diff --git a/server/TracyView.hpp b/server/TracyView.hpp index cfd7852a..09c7756d 100644 --- a/server/TracyView.hpp +++ b/server/TracyView.hpp @@ -10,8 +10,10 @@ #include #include +#include "TracyBadVersion.hpp" #include "TracyBuzzAnim.hpp" #include "TracyDecayValue.hpp" +#include "TracyImGui.hpp" #include "TracyShortPtr.hpp" #include "TracyTexture.hpp" #include "TracyUserData.hpp"