From 63450b662e8fd6fcb52ea6cd29783b0cc2f97692 Mon Sep 17 00:00:00 2001 From: PabloMK7 Date: Sun, 21 Jul 2024 12:36:00 +0200 Subject: [PATCH] Add instant log flush option (#209) --- .../features/settings/model/BooleanSetting.kt | 3 ++- .../features/settings/ui/SettingsFragmentPresenter.kt | 9 +++++++++ src/android/app/src/main/jni/config.cpp | 1 + src/android/app/src/main/jni/default_ini.h | 4 ++++ src/android/app/src/main/res/values/strings.xml | 2 ++ src/citra/config.cpp | 2 ++ src/citra_qt/configuration/config.cpp | 2 ++ src/citra_qt/configuration/configure_debug.cpp | 2 ++ src/citra_qt/configuration/configure_debug.ui | 10 ++++++++++ src/common/logging/backend.cpp | 11 +++++++++-- src/common/settings.cpp | 1 + src/common/settings.h | 1 + 12 files changed, 45 insertions(+), 3 deletions(-) diff --git a/src/android/app/src/main/java/org/citra/citra_emu/features/settings/model/BooleanSetting.kt b/src/android/app/src/main/java/org/citra/citra_emu/features/settings/model/BooleanSetting.kt index 0a1cf915a..8ef9664f3 100644 --- a/src/android/app/src/main/java/org/citra/citra_emu/features/settings/model/BooleanSetting.kt +++ b/src/android/app/src/main/java/org/citra/citra_emu/features/settings/model/BooleanSetting.kt @@ -13,7 +13,8 @@ enum class BooleanSetting( ASYNC_SHADERS("async_shader_compilation", Settings.SECTION_RENDERER, false), PLUGIN_LOADER("plugin_loader", Settings.SECTION_SYSTEM, false), ALLOW_PLUGIN_LOADER("allow_plugin_loader", Settings.SECTION_SYSTEM, true), - SWAP_SCREEN("swap_screen", Settings.SECTION_LAYOUT, false); + SWAP_SCREEN("swap_screen", Settings.SECTION_LAYOUT, false), + INSTANT_DEBUG_LOG("instant_debug_log", Settings.SECTION_DEBUG, false); override var boolean: Boolean = defaultValue diff --git a/src/android/app/src/main/java/org/citra/citra_emu/features/settings/ui/SettingsFragmentPresenter.kt b/src/android/app/src/main/java/org/citra/citra_emu/features/settings/ui/SettingsFragmentPresenter.kt index 8f104f0b5..51a96644a 100644 --- a/src/android/app/src/main/java/org/citra/citra_emu/features/settings/ui/SettingsFragmentPresenter.kt +++ b/src/android/app/src/main/java/org/citra/citra_emu/features/settings/ui/SettingsFragmentPresenter.kt @@ -986,6 +986,15 @@ class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView) IntSetting.DEBUG_RENDERER.defaultValue ) ) + add( + SwitchSetting( + BooleanSetting.INSTANT_DEBUG_LOG, + R.string.instant_debug_log, + R.string.instant_debug_log_desc, + BooleanSetting.INSTANT_DEBUG_LOG.key, + BooleanSetting.INSTANT_DEBUG_LOG.defaultValue + ) + ) } } diff --git a/src/android/app/src/main/jni/config.cpp b/src/android/app/src/main/jni/config.cpp index e565c8ec8..105712aba 100644 --- a/src/android/app/src/main/jni/config.cpp +++ b/src/android/app/src/main/jni/config.cpp @@ -262,6 +262,7 @@ void Config::ReadValues() { ReadSetting("Debugging", Settings::values.renderer_debug); ReadSetting("Debugging", Settings::values.use_gdbstub); ReadSetting("Debugging", Settings::values.gdbstub_port); + ReadSetting("Debugging", Settings::values.instant_debug_log); for (const auto& service_module : Service::service_module_map) { bool use_lle = sdl2_config->GetBoolean("Debugging", "LLE\\" + service_module.name, false); diff --git a/src/android/app/src/main/jni/default_ini.h b/src/android/app/src/main/jni/default_ini.h index acf42a73f..8f82352f9 100644 --- a/src/android/app/src/main/jni/default_ini.h +++ b/src/android/app/src/main/jni/default_ini.h @@ -357,6 +357,10 @@ renderer_debug = use_gdbstub=false gdbstub_port=24689 +# Flush log output on every message +# Immediately commits the debug log to file. Use this if citra crashes and the log output is being cut. +instant_debug_log = + # To LLE a service module add "LLE\=true" [WebService] diff --git a/src/android/app/src/main/res/values/strings.xml b/src/android/app/src/main/res/values/strings.xml index aad33db15..6ad304cfd 100644 --- a/src/android/app/src/main/res/values/strings.xml +++ b/src/android/app/src/main/res/values/strings.xml @@ -703,5 +703,7 @@ Miscellaneous Use Artic Controller when connected to Artic Base Server Use the controls provided by Artic Base Server when connected to it instead of the configured input device. + Flush log output on every message + Immediately commits the debug log to file. Use this if citra crashes and the log output is being cut. diff --git a/src/citra/config.cpp b/src/citra/config.cpp index bd60d4764..367b4cd8e 100644 --- a/src/citra/config.cpp +++ b/src/citra/config.cpp @@ -126,6 +126,7 @@ void Config::ReadValues() { Settings::values.current_input_profile.udp_input_port = static_cast(sdl2_config->GetInteger("Controls", "udp_input_port", InputCommon::CemuhookUDP::DEFAULT_PORT)); + ReadSetting("Controls", Settings::values.use_artic_base_controller); // Core ReadSetting("Core", Settings::values.use_cpu_jit); @@ -322,6 +323,7 @@ void Config::ReadValues() { ReadSetting("Debugging", Settings::values.renderer_debug); ReadSetting("Debugging", Settings::values.use_gdbstub); ReadSetting("Debugging", Settings::values.gdbstub_port); + ReadSetting("Debugging", Settings::values.instant_debug_log); for (const auto& service_module : Service::service_module_map) { bool use_lle = sdl2_config->GetBoolean("Debugging", "LLE\\" + service_module.name, false); diff --git a/src/citra_qt/configuration/config.cpp b/src/citra_qt/configuration/config.cpp index 886b66aa2..619d82833 100644 --- a/src/citra_qt/configuration/config.cpp +++ b/src/citra_qt/configuration/config.cpp @@ -494,6 +494,7 @@ void Config::ReadDebuggingValues() { ReadBasicSetting(Settings::values.gdbstub_port); ReadBasicSetting(Settings::values.renderer_debug); ReadBasicSetting(Settings::values.dump_command_buffers); + ReadBasicSetting(Settings::values.instant_debug_log); qt_config->beginGroup(QStringLiteral("LLE")); for (const auto& service_module : Service::service_module_map) { @@ -1031,6 +1032,7 @@ void Config::SaveDebuggingValues() { WriteBasicSetting(Settings::values.use_gdbstub); WriteBasicSetting(Settings::values.gdbstub_port); WriteBasicSetting(Settings::values.renderer_debug); + WriteBasicSetting(Settings::values.instant_debug_log); qt_config->beginGroup(QStringLiteral("LLE")); for (const auto& service_module : Settings::values.lle_modules) { diff --git a/src/citra_qt/configuration/configure_debug.cpp b/src/citra_qt/configuration/configure_debug.cpp index b843c3bc3..8f4af8bc2 100644 --- a/src/citra_qt/configuration/configure_debug.cpp +++ b/src/citra_qt/configuration/configure_debug.cpp @@ -121,6 +121,7 @@ void ConfigureDebug::SetConfiguration() { SettingsToSlider(Settings::values.cpu_clock_percentage.GetValue())); ui->clock_display_label->setText( QStringLiteral("%1%").arg(Settings::values.cpu_clock_percentage.GetValue())); + ui->instant_debug_log->setChecked(Settings::values.instant_debug_log.GetValue()); } void ConfigureDebug::ApplyConfiguration() { @@ -138,6 +139,7 @@ void ConfigureDebug::ApplyConfiguration() { Settings::values.delay_start_for_lle_modules = ui->delay_start_for_lle_modules->isChecked(); Settings::values.renderer_debug = ui->toggle_renderer_debug->isChecked(); Settings::values.dump_command_buffers = ui->toggle_dump_command_buffers->isChecked(); + Settings::values.instant_debug_log = ui->instant_debug_log->isChecked(); ConfigurationShared::ApplyPerGameSetting( &Settings::values.cpu_clock_percentage, ui->clock_speed_combo, diff --git a/src/citra_qt/configuration/configure_debug.ui b/src/citra_qt/configuration/configure_debug.ui index 860df0ffe..3fb3595ed 100644 --- a/src/citra_qt/configuration/configure_debug.ui +++ b/src/citra_qt/configuration/configure_debug.ui @@ -117,6 +117,16 @@ + + + + Flush log output on every message + + + <html><body>Immediately commits the debug log to file. Use this if citra crashes and the log output is being cut.<br>Enabling this feature will decrease performance, only use it for debugging purposes.</body></html> + + + diff --git a/src/common/logging/backend.cpp b/src/common/logging/backend.cpp index 9f8f82c99..1a911fd75 100644 --- a/src/common/logging/backend.cpp +++ b/src/common/logging/backend.cpp @@ -68,7 +68,7 @@ public: } void Flush() override { - // stderr shouldn't be buffered + std::fflush(stderr); } void EnableForStacktrace() override { @@ -263,7 +263,14 @@ public: !boost::regex_search(FormatLogMessage(new_entry), regex_filter)) { return; } - message_queue.EmplaceWait(new_entry); + if (Settings::values.instant_debug_log.GetValue()) { + ForEachBackend([&new_entry](Backend& backend) { + backend.Write(new_entry); + backend.Flush(); + }); + } else { + message_queue.EmplaceWait(new_entry); + } } private: diff --git a/src/common/settings.cpp b/src/common/settings.cpp index 69cc6f4ef..833901a73 100644 --- a/src/common/settings.cpp +++ b/src/common/settings.cpp @@ -147,6 +147,7 @@ void LogSettings() { log_setting("Debugging_DelayStartForLLEModules", values.delay_start_for_lle_modules.GetValue()); log_setting("Debugging_UseGdbstub", values.use_gdbstub.GetValue()); log_setting("Debugging_GdbstubPort", values.gdbstub_port.GetValue()); + log_setting("Debugging_InstantDebugLog", values.instant_debug_log.GetValue()); } bool IsConfiguringGlobal() { diff --git a/src/common/settings.h b/src/common/settings.h index b61957a6a..ba556c8c6 100644 --- a/src/common/settings.h +++ b/src/common/settings.h @@ -542,6 +542,7 @@ struct Values { Setting delay_start_for_lle_modules{true, "delay_start_for_lle_modules"}; Setting use_gdbstub{false, "use_gdbstub"}; Setting gdbstub_port{24689, "gdbstub_port"}; + Setting instant_debug_log{false, "instant_debug_log"}; // Miscellaneous Setting log_filter{"*:Info", "log_filter"};