Skip to content

Commit

Permalink
added option to update settings
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasmr committed Jan 23, 2024
1 parent e786d7b commit 579627f
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 17 deletions.
61 changes: 45 additions & 16 deletions microprofile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1713,21 +1713,7 @@ void MicroProfileInit()
S.nTimerNegativeCpuIndex = MicroProfileGetTimerIndex(S.nTokenNegativeCpu);
S.nTimerNegativeGpuIndex = MicroProfileGetTimerIndex(S.nTokenNegativeGpu);
}
{
auto DupeString = [](const char* BasePath, const char* File) -> const char*
{
size_t Len = strlen(BasePath) + strlen(File) + 1;
char* Data = (char*)MicroProfileAllocInternal(Len+1, 1);
snprintf(Data, Len,"%s%s", BasePath, File);
return Data;
};
const char* pBaseSettingsPath = MICROPROFILE_GET_SETTINGS_FILE_PATH;
S.pSettings = DupeString(pBaseSettingsPath, MICROPROFILE_SETTINGS_FILE);
S.pSettingsReadOnly = DupeString(pBaseSettingsPath, MICROPROFILE_SETTINGS_FILE_BUILTIN);
S.pSettingsTemp = DupeString(pBaseSettingsPath, MICROPROFILE_SETTINGS_FILE MICROPROFILE_SETTINGS_FILE_TEMP);
}


MicroProfileUpdateSettingsPath();

#if MICROPROFILE_FRAME_EXTRA_DATA
S.FrameExtraCounterData = (MicroProfileFrameExtraCounterData*)1;
Expand All @@ -1740,6 +1726,47 @@ void MicroProfileInit()
mutex.unlock();
}
}
void MicroProfileUpdateSettingsPath()
{
if(S.pSettings)
{
MicroProfileFreeInternal((void*)S.pSettings);
S.pSettings = nullptr;
}
if(S.pSettingsReadOnly)
{
MicroProfileFreeInternal((void*)S.pSettingsReadOnly);
S.pSettingsReadOnly = nullptr;
}
if(S.pSettingsTemp)
{
MicroProfileFreeInternal((void*)S.pSettingsTemp);
S.pSettingsTemp = nullptr;
}
auto DupeString = [](const char* BasePath, const char* File) -> const char*
{
size_t BaseLen = strlen(BasePath);
bool TrailingSlash = BaseLen > 1 && (BasePath[BaseLen - 1] == '\\' || BasePath[BaseLen - 1] == '/');
size_t Len = BaseLen + strlen(File) + 2;
char* Data = (char*)MicroProfileAllocInternal(Len + 1, 1);
#ifdef _WIN32
char Slash = '\\';
#else
char Slash = '/';
#endif
if (TrailingSlash)
snprintf(Data, Len, "%s%s", BasePath, File);
else
snprintf(Data, Len, "%s%c%s", BasePath, Slash, File);

return Data;
};
const char* pBaseSettingsPath = MICROPROFILE_GET_SETTINGS_FILE_PATH;
S.pSettings = DupeString(pBaseSettingsPath, MICROPROFILE_SETTINGS_FILE);
S.pSettingsReadOnly = DupeString(pBaseSettingsPath, MICROPROFILE_SETTINGS_FILE_BUILTIN);
S.pSettingsTemp = DupeString(pBaseSettingsPath, MICROPROFILE_SETTINGS_FILE MICROPROFILE_SETTINGS_FILE_TEMP);
}


void MicroProfileJoinContextSwitchTrace();

Expand Down Expand Up @@ -7473,7 +7500,9 @@ void MicroProfileLoadPresets(const char* pSettingsName, uint32_t nLoadPresetType
uint32_t nLen = (uint32_t)strlen(pJson) + 1;
if(nLen > S.nJsonSettingsBufferSize)
{
S.pJsonSettings = (char*)MP_REALLOC(S.pJsonSettings, nLen);
if (S.pJsonSettings)
S.pJsonSettings = nullptr;
S.pJsonSettings = (char*)MP_ALLOC(nLen, 1);
S.nJsonSettingsBufferSize = nLen;
}
S.pJsonSettingsName = pSettingsName;
Expand Down
5 changes: 4 additions & 1 deletion microprofile.h
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,7 @@ typedef uint32_t MicroProfileTimelineToken;
#define MicroProfileCsvConfigAddTimer(...)
#define MicroProfileCsvConfigAddGroup(...)
#define MicroProfileCsvConfigAddCounter(...)
#define MicroProfileUpdateSettingsPath(...)



Expand Down Expand Up @@ -1045,6 +1046,8 @@ extern "C"
MICROPROFILE_API void MicroProfileCsvConfigAddGroup(const char* Group, const char* DisplayName IF_CPP(= nullptr) );
MICROPROFILE_API void MicroProfileCsvConfigAddCounter(const char* CounterName, const char* DisplayName IF_CPP(= nullptr) );

MICROPROFILE_API void MicroProfileUpdateSettingsPath();

#ifdef __cplusplus
}
#endif
Expand Down Expand Up @@ -1154,7 +1157,7 @@ extern "C"
#endif

#if MICROPROFILE_GPU_TIMERS_D3D11
#define MICROPROFILE_D3D_MAX_QUERIES (8 << 10)
#define MICROPROFILE_D3D_MAX_QUERIES (32 << 10)
MICROPROFILE_API void MicroProfileGpuInitD3D11(void* pDevice, void* pDeviceContext);
MICROPROFILE_API void MicroProfileGpuShutdown();
#endif
Expand Down

0 comments on commit 579627f

Please sign in to comment.