tracy/server/TracyUserData.cpp
Bartosz Taudul dc5444ff0f Notify UserData that view state should be preserved.
This is only active when a trace is loaded from a file (and state should
be persistent for future sessions using this trace), or when state is
saved to a file (so that future sessions will use current state).

No state is preserved by default, i.e. when the trace was not saved to a
file.
2019-08-28 19:37:01 +02:00

70 lines
1.4 KiB
C++

#include <assert.h>
#include <memory>
#include "TracyStorage.hpp"
#include "TracyUserData.hpp"
namespace tracy
{
constexpr auto FileDescription = "description";
UserData::UserData()
: m_preserveState( false )
{
}
UserData::UserData( const char* program, uint64_t time )
: m_program( program )
, m_time( time )
{
FILE* f = OpenFile( FileDescription, false );
if( f )
{
fseek( f, 0, SEEK_END );
const auto sz = ftell( f );
fseek( f, 0, SEEK_SET );
auto buf = std::make_unique<char[]>( sz );
fread( buf.get(), 1, sz, f );
fclose( f );
m_description.assign( buf.get(), buf.get() + sz );
}
}
void UserData::Init( const char* program, uint64_t time )
{
assert( !Valid() );
m_program = program;
m_time = time;
}
bool UserData::SetDescription( const char* description )
{
assert( Valid() );
m_description = description;
const auto sz = m_description.size();
FILE* f = OpenFile( FileDescription, true );
if( !f ) return false;
fwrite( description, 1, sz, f );
fclose( f );
return true;
}
void UserData::StateShouldBePreserved()
{
m_preserveState = true;
}
FILE* UserData::OpenFile( const char* filename, bool write )
{
const auto path = GetSavePath( m_program.c_str(), m_time, filename, write );
if( !path ) return nullptr;
FILE* f = fopen( path, write ? "wb" : "rb" );
return f;
}
}