From 2a6a082c934d2c011dc4a732883fc5bddc7a179e Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Sat, 7 Oct 2023 01:00:59 +0200 Subject: [PATCH] Maintain a history of viewed symbols. --- server/TracySourceView.cpp | 15 ++++++++++++++- server/TracySourceView.hpp | 13 ++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/server/TracySourceView.cpp b/server/TracySourceView.cpp index 2af1a170..c7dccd0f 100644 --- a/server/TracySourceView.cpp +++ b/server/TracySourceView.cpp @@ -606,7 +606,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, Worker& worker, const View& view ) +void SourceView::OpenSymbol( const char* fileName, int line, uint64_t baseAddr, uint64_t symAddr, Worker& worker, const View& view, bool updateHistory ) { m_targetLine = line; m_targetAddr = symAddr; @@ -623,6 +623,19 @@ void SourceView::OpenSymbol( const char* fileName, int line, uint64_t baseAddr, SelectViewMode(); if( !worker.GetInlineSymbolList( baseAddr, m_codeLen ) ) m_calcInlineStats = false; + + if( updateHistory ) + { + m_history.erase( m_history.begin() + m_historyCursor, m_history.end() ); + + History entry = { fileName, line, baseAddr, symAddr }; + if( m_history.empty() || memcmp( &m_history.back(), &entry, sizeof( History ) ) != 0 ) + { + m_history.emplace_back( entry ); + if( m_history.size() > 100 ) m_history.erase( m_history.begin() ); + m_historyCursor = m_history.size(); + } + } } void SourceView::SelectViewMode() diff --git a/server/TracySourceView.hpp b/server/TracySourceView.hpp index faf828e5..66d2d3fe 100644 --- a/server/TracySourceView.hpp +++ b/server/TracySourceView.hpp @@ -153,6 +153,14 @@ private: unordered_flat_map hwCountSrc, hwCountAsm; }; + struct History + { + const char* fileName; + int64_t line; + uint64_t baseAddr; + uint64_t symAddr; + }; + public: SourceView(); @@ -160,7 +168,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, Worker& worker, const View& view ); + void OpenSymbol( const char* fileName, int line, uint64_t baseAddr, uint64_t symAddr, Worker& worker, const View& view, bool updateHistory = true ); void Render( Worker& worker, View& view ); void CalcInlineStats( bool val ) { m_calcInlineStats = val; } @@ -287,6 +295,9 @@ private: size_t sel; std::vector target; } m_asmTarget; + + std::vector m_history; + size_t m_historyCursor = 0; }; }