mirror of
https://github.com/wolfpld/tracy.git
synced 2024-11-10 02:31:48 +00:00
Save/load source substitutions.
This commit is contained in:
parent
ff4b4fd9d9
commit
91ad77d86a
@ -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<std::unique_ptr<Annotation>>&
|
||||
}
|
||||
}
|
||||
|
||||
bool UserData::LoadSourceSubstitutions( std::vector<SourceRegex>& 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<sz; i++ )
|
||||
{
|
||||
std::string pattern, target;
|
||||
uint32_t tsz;
|
||||
fread( &tsz, 1, sizeof( tsz ), f );
|
||||
if( tsz != 0 )
|
||||
{
|
||||
char buf[1024];
|
||||
assert( tsz < 1024 );
|
||||
fread( buf, 1, tsz, f );
|
||||
pattern.assign( buf, tsz );
|
||||
}
|
||||
fread( &tsz, 1, sizeof( tsz ), f );
|
||||
if( tsz != 0 )
|
||||
{
|
||||
char buf[1024];
|
||||
assert( tsz < 1024 );
|
||||
fread( buf, 1, tsz, f );
|
||||
target.assign( buf, tsz );
|
||||
}
|
||||
std::regex regex;
|
||||
try
|
||||
{
|
||||
regex.assign( pattern );
|
||||
}
|
||||
catch( std::regex_error& err )
|
||||
{
|
||||
regexValid = false;
|
||||
}
|
||||
data.emplace_back( SourceRegex { std::move( pattern ), std::move( target ), std::move( regex ) } );
|
||||
}
|
||||
}
|
||||
fclose( f );
|
||||
}
|
||||
return regexValid;
|
||||
}
|
||||
|
||||
void UserData::SaveSourceSubstitutions( const std::vector<SourceRegex>& 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 );
|
||||
|
@ -11,6 +11,7 @@ namespace tracy
|
||||
{
|
||||
|
||||
struct Annotation;
|
||||
struct SourceRegex;
|
||||
struct ViewData;
|
||||
|
||||
class UserData
|
||||
@ -32,6 +33,9 @@ public:
|
||||
void LoadAnnotations( std::vector<std::unique_ptr<Annotation>>& data );
|
||||
void SaveAnnotations( const std::vector<std::unique_ptr<Annotation>>& data );
|
||||
|
||||
bool LoadSourceSubstitutions( std::vector<SourceRegex>& data );
|
||||
void SaveSourceSubstitutions( const std::vector<SourceRegex>& data );
|
||||
|
||||
const char* GetConfigLocation() const;
|
||||
|
||||
private:
|
||||
|
@ -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();
|
||||
|
@ -7,7 +7,6 @@
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <regex>
|
||||
#include <vector>
|
||||
|
||||
#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<SourceRegex> m_sourceSubstitutions;
|
||||
bool m_sourceRegexValid = true;
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
#define __TRACYVIEWDATA_HPP__
|
||||
|
||||
#include <stdint.h>
|
||||
#include <regex>
|
||||
|
||||
namespace tracy
|
||||
{
|
||||
@ -38,6 +39,13 @@ struct Annotation
|
||||
uint32_t color;
|
||||
};
|
||||
|
||||
struct SourceRegex
|
||||
{
|
||||
std::string pattern;
|
||||
std::string target;
|
||||
std::regex regex;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user