diff --git a/server/TracyUserData.cpp b/server/TracyUserData.cpp index f6e1b5ca..626a7303 100644 --- a/server/TracyUserData.cpp +++ b/server/TracyUserData.cpp @@ -18,10 +18,12 @@ constexpr auto FileDescription = "description"; constexpr auto FileTimeline = "timeline"; constexpr auto FileOptions = "options"; constexpr auto FileAnnotations = "annotations"; +constexpr auto FileSourceSubstitutions = "srcsub"; enum : uint32_t { VersionTimeline = 0 }; enum : uint32_t { VersionOptions = 5 }; enum : uint32_t { VersionAnnotations = 0 }; +enum : uint32_t { VersionSourceSubstitutions = 0 }; UserData::UserData() : m_preserveState( false ) @@ -225,6 +227,92 @@ void UserData::SaveAnnotations( const std::vector>& } } +bool UserData::LoadSourceSubstitutions( std::vector& data ) +{ + assert( Valid() ); + bool regexValid = true; + FILE* f = OpenFile( FileSourceSubstitutions, false ); + if( f ) + { + uint32_t ver; + fread( &ver, 1, sizeof( ver ), f ); + if( ver == VersionSourceSubstitutions ) + { + uint32_t sz; + fread( &sz, 1, sizeof( sz ), f ); + for( uint32_t i=0; i& data ) +{ + if( !m_preserveState ) return; + if( data.empty() ) + { + Remove( FileSourceSubstitutions ); + return; + } + assert( Valid() ); + FILE* f = OpenFile( FileSourceSubstitutions, true ); + if( f ) + { + uint32_t ver = VersionSourceSubstitutions; + fwrite( &ver, 1, sizeof( ver ), f ); + uint32_t sz = uint32_t( data.size() ); + fwrite( &sz, 1, sizeof( sz ), f ); + for( auto& v : data ) + { + sz = uint32_t( v.pattern.size() ); + fwrite( &sz, 1, sizeof( sz ), f ); + if( sz != 0 ) + { + fwrite( v.pattern.c_str(), 1, sz, f ); + } + sz = uint32_t( v.target.size() ); + fwrite( &sz, 1, sizeof( sz ), f ); + if( sz != 0 ) + { + fwrite( v.target.c_str(), 1, sz, f ); + } + } + fclose( f ); + } +} + + FILE* UserData::OpenFile( const char* filename, bool write ) { const auto path = GetSavePath( m_program.c_str(), m_time, filename, write ); diff --git a/server/TracyUserData.hpp b/server/TracyUserData.hpp index f355f708..d8e366d3 100644 --- a/server/TracyUserData.hpp +++ b/server/TracyUserData.hpp @@ -11,6 +11,7 @@ namespace tracy { struct Annotation; +struct SourceRegex; struct ViewData; class UserData @@ -32,6 +33,9 @@ public: void LoadAnnotations( std::vector>& data ); void SaveAnnotations( const std::vector>& data ); + bool LoadSourceSubstitutions( std::vector& data ); + void SaveSourceSubstitutions( const std::vector& data ); + const char* GetConfigLocation() const; private: diff --git a/server/TracyView.cpp b/server/TracyView.cpp index a12ac3dc..afb8aef2 100644 --- a/server/TracyView.cpp +++ b/server/TracyView.cpp @@ -164,6 +164,7 @@ View::View( FileRead& f, ImFont* fixedWidth, ImFont* smallFont, ImFont* bigFont, m_userData.StateShouldBePreserved(); m_userData.LoadState( m_vd ); m_userData.LoadAnnotations( m_annotations ); + m_sourceRegexValid = m_userData.LoadSourceSubstitutions( m_sourceSubstitutions ); if( m_worker.GetCallstackFrameCount() == 0 ) m_showUnknownFrames = false; if( m_worker.GetCallstackSampleCount() == 0 ) m_showAllSymbols = true; @@ -172,8 +173,10 @@ View::View( FileRead& f, ImFont* fixedWidth, ImFont* smallFont, ImFont* bigFont, View::~View() { m_worker.Shutdown(); + m_userData.SaveState( m_vd ); m_userData.SaveAnnotations( m_annotations ); + m_userData.SaveSourceSubstitutions( m_sourceSubstitutions ); if( m_compare.loadThread.joinable() ) m_compare.loadThread.join(); if( m_saveThread.joinable() ) m_saveThread.join(); diff --git a/server/TracyView.hpp b/server/TracyView.hpp index 09c7756d..51dfc233 100644 --- a/server/TracyView.hpp +++ b/server/TracyView.hpp @@ -7,7 +7,6 @@ #include #include #include -#include #include #include "TracyBadVersion.hpp" @@ -428,13 +427,6 @@ private: bool m_reconnectRequested = false; bool m_firstFrame = true; - struct SourceRegex - { - std::string pattern; - std::string target; - std::regex regex; - }; - std::vector m_sourceSubstitutions; bool m_sourceRegexValid = true; diff --git a/server/TracyViewData.hpp b/server/TracyViewData.hpp index cda7f242..a39958d4 100644 --- a/server/TracyViewData.hpp +++ b/server/TracyViewData.hpp @@ -2,6 +2,7 @@ #define __TRACYVIEWDATA_HPP__ #include +#include namespace tracy { @@ -38,6 +39,13 @@ struct Annotation uint32_t color; }; +struct SourceRegex +{ + std::string pattern; + std::string target; + std::regex regex; +}; + } #endif