Make trace options save file user-readable.

More importantly, it allows for backwards-compatibility when something
is added or removed, instead of just ignoring what was set before when
a binary version bump occurs.
This commit is contained in:
Bartosz Taudul 2024-05-04 12:46:16 +02:00
parent 328ecc339c
commit 061b5c77ce
No known key found for this signature in database
GPG Key ID: B7FE2008B7575DF3

View File

@ -7,6 +7,8 @@
# include <unistd.h> # include <unistd.h>
#endif #endif
#include "../ini.h"
#include "TracyStorage.hpp" #include "TracyStorage.hpp"
#include "TracyUserData.hpp" #include "TracyUserData.hpp"
#include "TracyViewData.hpp" #include "TracyViewData.hpp"
@ -96,6 +98,7 @@ void UserData::LoadState( ViewData& data )
{ {
uint32_t ver; uint32_t ver;
fread( &ver, 1, sizeof( ver ), f ); fread( &ver, 1, sizeof( ver ), f );
// TODO: remove in future
if( ver == VersionOptions ) if( ver == VersionOptions )
{ {
fread( &data.drawGpuZones, 1, sizeof( data.drawGpuZones ), f ); fread( &data.drawGpuZones, 1, sizeof( data.drawGpuZones ), f );
@ -114,9 +117,37 @@ void UserData::LoadState( ViewData& data )
fread( &data.forceColors, 1, sizeof( data.forceColors ), f ); fread( &data.forceColors, 1, sizeof( data.forceColors ), f );
fread( &data.ghostZones, 1, sizeof( data.ghostZones ), f ); fread( &data.ghostZones, 1, sizeof( data.ghostZones ), f );
fread( &data.frameTarget, 1, sizeof( data.frameTarget ), f ); fread( &data.frameTarget, 1, sizeof( data.frameTarget ), f );
}
fclose( f ); fclose( f );
} }
else
{
fclose( f );
const auto path = GetSavePath( m_program.c_str(), m_time, FileOptions, false );
assert( path );
auto ini = ini_load( path );
if( ini )
{
int v;
if( ini_sget( ini, "options", "drawGpuZones", "%d", &v ) ) data.drawGpuZones = v;
if( ini_sget( ini, "options", "drawZones", "%d", &v ) ) data.drawZones = v;
if( ini_sget( ini, "options", "drawLocks", "%d", &v ) ) data.drawLocks = v;
if( ini_sget( ini, "options", "drawPlots", "%d", &v ) ) data.drawPlots = v;
if( ini_sget( ini, "options", "onlyContendedLocks", "%d", &v ) ) data.onlyContendedLocks = v;
if( ini_sget( ini, "options", "drawEmptyLabels", "%d", &v ) ) data.drawEmptyLabels = v;
if( ini_sget( ini, "options", "drawFrameTargets", "%d", &v ) ) data.drawFrameTargets = v;
if( ini_sget( ini, "options", "drawContextSwitches", "%d", &v ) ) data.drawContextSwitches = v;
if( ini_sget( ini, "options", "darkenContextSwitches", "%d", &v ) ) data.darkenContextSwitches = v;
if( ini_sget( ini, "options", "drawCpuData", "%d", &v ) ) data.drawCpuData = v;
if( ini_sget( ini, "options", "drawCpuUsageGraph", "%d", &v ) ) data.drawCpuUsageGraph = v;
if( ini_sget( ini, "options", "drawSamples", "%d", &v ) ) data.drawSamples = v;
if( ini_sget( ini, "options", "dynamicColors", "%d", &v ) ) data.dynamicColors = v;
if( ini_sget( ini, "options", "forceColors", "%d", &v ) ) data.forceColors = v;
if( ini_sget( ini, "options", "ghostZones", "%d", &v ) ) data.ghostZones = v;
if( ini_sget( ini, "options", "frameTarget", "%d", &v ) ) data.frameTarget = v;
ini_free( ini );
}
}
}
} }
void UserData::SaveState( const ViewData& data ) void UserData::SaveState( const ViewData& data )
@ -143,24 +174,23 @@ void UserData::SaveState( const ViewData& data )
f = OpenFile( FileOptions, true ); f = OpenFile( FileOptions, true );
if( f ) if( f )
{ {
uint32_t ver = VersionOptions; fprintf( f, "[options]\n" );
fwrite( &ver, 1, sizeof( ver ), f ); fprintf( f, "drawGpuZones = %d\n", data.drawGpuZones );
fwrite( &data.drawGpuZones, 1, sizeof( data.drawGpuZones ), f ); fprintf( f, "drawZones = %d\n", data.drawZones );
fwrite( &data.drawZones, 1, sizeof( data.drawZones ), f ); fprintf( f, "drawLocks = %d\n", data.drawLocks );
fwrite( &data.drawLocks, 1, sizeof( data.drawLocks ), f ); fprintf( f, "drawPlots = %d\n", data.drawPlots );
fwrite( &data.drawPlots, 1, sizeof( data.drawPlots ), f ); fprintf( f, "onlyContendedLocks = %d\n", data.onlyContendedLocks );
fwrite( &data.onlyContendedLocks, 1, sizeof( data.onlyContendedLocks ), f ); fprintf( f, "drawEmptyLabels = %d\n", data.drawEmptyLabels );
fwrite( &data.drawEmptyLabels, 1, sizeof( data.drawEmptyLabels ), f ); fprintf( f, "drawFrameTargets = %d\n", data.drawFrameTargets );
fwrite( &data.drawFrameTargets, 1, sizeof( data.drawFrameTargets ), f ); fprintf( f, "drawContextSwitches = %d\n", data.drawContextSwitches );
fwrite( &data.drawContextSwitches, 1, sizeof( data.drawContextSwitches ), f ); fprintf( f, "darkenContextSwitches = %d\n", data.darkenContextSwitches );
fwrite( &data.darkenContextSwitches, 1, sizeof( data.darkenContextSwitches ), f ); fprintf( f, "drawCpuData = %d\n", data.drawCpuData );
fwrite( &data.drawCpuData, 1, sizeof( data.drawCpuData ), f ); fprintf( f, "drawCpuUsageGraph = %d\n", data.drawCpuUsageGraph );
fwrite( &data.drawCpuUsageGraph, 1, sizeof( data.drawCpuUsageGraph ), f ); fprintf( f, "drawSamples = %d\n", data.drawSamples );
fwrite( &data.drawSamples, 1, sizeof( data.drawSamples ), f ); fprintf( f, "dynamicColors = %d\n", data.dynamicColors );
fwrite( &data.dynamicColors, 1, sizeof( data.dynamicColors ), f ); fprintf( f, "forceColors = %d\n", data.forceColors );
fwrite( &data.forceColors, 1, sizeof( data.forceColors ), f ); fprintf( f, "ghostZones = %d\n", data.ghostZones );
fwrite( &data.ghostZones, 1, sizeof( data.ghostZones ), f ); fprintf( f, "frameTarget = %d\n", data.frameTarget );
fwrite( &data.frameTarget, 1, sizeof( data.frameTarget ), f );
fclose( f ); fclose( f );
} }
} }