From bd2f903c08a9ea1cca387e6b119611c31deab134 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Mon, 1 May 2023 19:07:49 +0200 Subject: [PATCH] Add persistent target FPS option. --- profiler/src/main.cpp | 15 +++++++++++++-- server/TracyConfig.hpp | 1 + server/TracyView.cpp | 4 ++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/profiler/src/main.cpp b/profiler/src/main.cpp index bd666ec7..e11865bf 100644 --- a/profiler/src/main.cpp +++ b/profiler/src/main.cpp @@ -169,6 +169,7 @@ static void LoadConfig() int v; if( ini_sget( ini, "core", "threadedRendering", "%d", &v ) ) s_config.threadedRendering = v; + if( ini_sget( ini, "timeline", "targetFps", "%d", &v ) && v >= 1 && v < 10000 ) s_config.targetFps = v; ini_free( ini ); } @@ -182,6 +183,9 @@ static bool SaveConfig() fprintf( f, "[core]\n" ); fprintf( f, "threadedRendering = %i\n", (int)s_config.threadedRendering ); + fprintf( f, "\n[timeline]\n" ); + fprintf( f, "targetFps = %i\n", s_config.targetFps ); + fclose( f ); return true; } @@ -553,17 +557,24 @@ static void DrawContents() ImGui::Separator(); if( ImGui::TreeNode( ICON_FA_TOOLBOX " Global settings" ) ) { + ImGui::PushStyleVar( ImGuiStyleVar_FramePadding, ImVec2( 0, 0 ) ); ImGui::TextUnformatted( "Threaded rendering" ); ImGui::Indent(); - ImGui::PushStyleVar( ImGuiStyleVar_FramePadding, ImVec2( 0, 0 ) ); if( ImGui::RadioButton( "Enabled", s_config.threadedRendering ) ) { s_config.threadedRendering = true; SaveConfig(); } ImGui::SameLine(); tracy::DrawHelpMarker( "Uses all available CPU cores for rendering. May affect performance of the profiled application when running on the same machine." ); if( ImGui::RadioButton( "Disabled", !s_config.threadedRendering ) ) { s_config.threadedRendering = false; SaveConfig(); } ImGui::SameLine(); tracy::DrawHelpMarker( "Restricts rendering to a single CPU core. Can reduce profiler frame rate." ); - ImGui::PopStyleVar(); ImGui::Unindent(); + + ImGui::Spacing(); + ImGui::TextUnformatted( "Target FPS" ); + ImGui::SameLine(); + int tmp = s_config.targetFps; + ImGui::SetNextItemWidth( 90 * dpiScale ); + if( ImGui::InputInt( "##targetfps", &tmp ) ) { s_config.targetFps = std::clamp( tmp, 1, 9999 ); SaveConfig(); } + ImGui::PopStyleVar(); ImGui::TreePop(); } ImGui::Separator(); diff --git a/server/TracyConfig.hpp b/server/TracyConfig.hpp index 5a90d44a..2f40c504 100644 --- a/server/TracyConfig.hpp +++ b/server/TracyConfig.hpp @@ -7,6 +7,7 @@ namespace tracy struct Config { bool threadedRendering = true; + int targetFps = 60; }; } diff --git a/server/TracyView.cpp b/server/TracyView.cpp index 9a22ebdb..b19b0694 100644 --- a/server/TracyView.cpp +++ b/server/TracyView.cpp @@ -66,6 +66,8 @@ View::View( void(*cbMainThread)(const std::function&, bool), const char* { InitMemory(); InitTextEditor(); + + m_vd.frameTarget = config.targetFps; } View::View( void(*cbMainThread)(const std::function&, bool), FileRead& f, ImFont* fixedWidth, ImFont* smallFont, ImFont* bigFont, SetTitleCallback stcb, SetScaleCallback sscb, AttentionCallback acb, const Config& config ) @@ -99,6 +101,8 @@ View::View( void(*cbMainThread)(const std::function&, bool), FileRead& f if( m_worker.GetCallstackFrameCount() == 0 ) m_showUnknownFrames = false; if( m_worker.GetCallstackSampleCount() == 0 ) m_showAllSymbols = true; + + m_vd.frameTarget = config.targetFps; } View::~View()