From 4f0d3a958dcefa7ce56de736ce8029206631ebd4 Mon Sep 17 00:00:00 2001 From: Flyinghead Date: Wed, 11 Jan 2023 21:15:45 +0100 Subject: [PATCH] ui: debug tab with logging and profiling options --- core/profiler/fc_profiler.cpp | 4 ++- core/profiler/fc_profiler.h | 12 ++++--- core/rend/gui.cpp | 67 +++++++++++++++++++++++++++++++++++ 3 files changed, 78 insertions(+), 5 deletions(-) diff --git a/core/profiler/fc_profiler.cpp b/core/profiler/fc_profiler.cpp index a12af93b0..3fa498daa 100644 --- a/core/profiler/fc_profiler.cpp +++ b/core/profiler/fc_profiler.cpp @@ -37,9 +37,11 @@ namespace fc_profiler { std::unique_lock lock(ProfileThread::s_allThreadsLock); + if (!ProfileScope::s_thread) + return; ProfileThread& profileThread = *ProfileScope::s_thread; - std::chrono::steady_clock::time_point endTicks = std::chrono::high_resolution_clock::now(); + std::chrono::high_resolution_clock::time_point endTicks = std::chrono::high_resolution_clock::now(); std::chrono::microseconds durationMicro = std::chrono::duration_cast(endTicks - profileThread.startTicks); profileThread.cachedTime = (double)durationMicro.count() / 1000000; diff --git a/core/profiler/fc_profiler.h b/core/profiler/fc_profiler.h index 67fe2a5ce..264cdee23 100644 --- a/core/profiler/fc_profiler.h +++ b/core/profiler/fc_profiler.h @@ -10,7 +10,11 @@ #include #ifndef __PRETTY_FUNCTION__ +#ifdef _MSC_VER #define __PRETTY_FUNCTION__ __FUNCSIG__ +#else +#define __PRETTY_FUNCTION__ __func__ +#endif #endif #define FC_PROFILE_SCOPE_RESERVE_SIZE 128 @@ -41,8 +45,8 @@ namespace fc_profiler const char* file; u32 line; u32 scope; - std::chrono::steady_clock::time_point start; - std::chrono::steady_clock::time_point end; + std::chrono::high_resolution_clock::time_point start; + std::chrono::high_resolution_clock::time_point end; }; struct ProfileThread @@ -58,8 +62,8 @@ namespace fc_profiler } std::vector scopes; - std::chrono::steady_clock::time_point startTicks; - std::chrono::steady_clock::time_point endTicks; + std::chrono::high_resolution_clock::time_point startTicks; + std::chrono::high_resolution_clock::time_point endTicks; double history[FC_PROFILE_HISTORY_MAX_SIZE]; u32 level; u32 historyIdx; diff --git a/core/rend/gui.cpp b/core/rend/gui.cpp index 80ea497a9..52022d787 100644 --- a/core/rend/gui.cpp +++ b/core/rend/gui.cpp @@ -1226,6 +1226,68 @@ static void contentpath_warning_popup() } } +static inline void gui_debug_tab() +{ + if (ImGui::BeginTabItem("Debug")) + { + ImVec2 normal_padding = ImGui::GetStyle().FramePadding; + ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, normal_padding); + header("Logging"); + { + LogManager *logManager = LogManager::GetInstance(); + for (LogTypes::LOG_TYPE type = LogTypes::AICA; type < LogTypes::NUMBER_OF_LOGS; type = (LogTypes::LOG_TYPE)(type + 1)) + { + bool enabled = logManager->IsEnabled(type, logManager->GetLogLevel()); + std::string name = std::string(logManager->GetShortName(type)) + " - " + logManager->GetFullName(type); + if (ImGui::Checkbox(name.c_str(), &enabled) && logManager->GetLogLevel() > LogTypes::LWARNING) { + logManager->SetEnable(type, enabled); + cfgSaveBool("log", logManager->GetShortName(type), enabled); + } + } + ImGui::Spacing(); + + static const char *levels[] = { "Notice", "Error", "Warning", "Info", "Debug" }; + if (ImGui::BeginCombo("Log Verbosity", levels[logManager->GetLogLevel() - 1], ImGuiComboFlags_None)) + { + for (size_t i = 0; i < ARRAY_SIZE(levels); i++) + { + bool is_selected = logManager->GetLogLevel() - 1 == (int)i; + if (ImGui::Selectable(levels[i], &is_selected)) { + logManager->SetLogLevel((LogTypes::LOG_LEVELS)(i + 1)); + cfgSaveInt("log", "Verbosity", i + 1); + } + if (is_selected) + ImGui::SetItemDefaultFocus(); + } + ImGui::EndCombo(); + } + } +#if FC_PROFILER + ImGui::Spacing(); + header("Profiling"); + { + + OptionCheckbox("Enable", config::ProfilerEnabled, "Enable the profiler."); + if (!config::ProfilerEnabled) + { + ImGui::PushItemFlag(ImGuiItemFlags_Disabled, true); + ImGui::PushStyleVar(ImGuiStyleVar_Alpha, ImGui::GetStyle().Alpha * 0.5f); + } + OptionCheckbox("Display", config::ProfilerDrawToGUI, "Draw the profiler output in an overlay."); + OptionCheckbox("Output to terminal", config::ProfilerOutputTTY, "Write the profiler output to the terminal"); + // TODO frame warning time + if (!config::ProfilerEnabled) + { + ImGui::PopItemFlag(); + ImGui::PopStyleVar(); + } + } +#endif + ImGui::PopStyleVar(); + ImGui::EndTabItem(); + } +} + static void gui_display_settings() { static bool maple_devices_changed; @@ -2222,6 +2284,11 @@ static void gui_display_settings() } #endif } + +#if !defined(NDEBUG) || defined(DEBUGFAST) || FC_PROFILER + gui_debug_tab(); +#endif + if (ImGui::BeginTabItem("About")) { ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, normal_padding);