Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to save logfiles seperate for each game #2504

Merged
merged 9 commits into from
Feb 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/common/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ static bool vkHostMarkers = false;
static bool vkGuestMarkers = false;
static bool rdocEnable = false;
static bool isFpsColor = true;
static bool isSeparateLogFilesEnabled = false;
static s16 cursorState = HideCursorState::Idle;
static int cursorHideTimeout = 5; // 5 seconds (default)
static bool useUnifiedInputConfig = true;
Expand Down Expand Up @@ -451,6 +452,10 @@ void setLogFilter(const std::string& type) {
logFilter = type;
}

void setSeparateLogFilesEnabled(bool enabled) {
isSeparateLogFilesEnabled = enabled;
}

void setUserName(const std::string& type) {
userName = type;
}
Expand Down Expand Up @@ -656,6 +661,10 @@ u32 GetLanguage() {
return m_language;
}

bool getSeparateLogFilesEnabled() {
return isSeparateLogFilesEnabled;
}

int getBackgroundImageOpacity() {
return backgroundImageOpacity;
}
Expand Down Expand Up @@ -761,6 +770,7 @@ void load(const std::filesystem::path& path) {
const toml::value& debug = data.at("Debug");

isDebugDump = toml::find_or<bool>(debug, "DebugDump", false);
isSeparateLogFilesEnabled = toml::find_or<bool>(debug, "isSeparateLogFilesEnabled", false);
isShaderDebug = toml::find_or<bool>(debug, "CollectShader", false);
isFpsColor = toml::find_or<bool>(debug, "FPSColor", true);
}
Expand Down Expand Up @@ -887,6 +897,7 @@ void save(const std::filesystem::path& path) {
data["Vulkan"]["rdocEnable"] = rdocEnable;
data["Debug"]["DebugDump"] = isDebugDump;
data["Debug"]["CollectShader"] = isShaderDebug;
data["Debug"]["isSeparateLogFilesEnabled"] = isSeparateLogFilesEnabled;
data["Debug"]["FPSColor"] = isFpsColor;

data["Keys"]["TrophyKey"] = trophyKey;
Expand Down
3 changes: 2 additions & 1 deletion src/common/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ void setIsMotionControlsEnabled(bool use);

void setLogType(const std::string& type);
void setLogFilter(const std::string& type);

void setSeparateLogFilesEnabled(bool enabled);
bool getSeparateLogFilesEnabled();
void setVkValidation(bool enable);
void setVkSyncValidation(bool enable);
void setRdocEnabled(bool enable);
Expand Down
5 changes: 3 additions & 2 deletions src/common/logging/backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,9 @@ class Impl {
std::filesystem::create_directory(log_dir);
Filter filter;
filter.ParseFilterString(Config::getLogFilter());
instance = std::unique_ptr<Impl, decltype(&Deleter)>(new Impl(log_dir / LOG_FILE, filter),
Deleter);
const auto& log_file_path = log_file.empty() ? LOG_FILE : log_file;
instance = std::unique_ptr<Impl, decltype(&Deleter)>(
new Impl(log_dir / log_file_path, filter), Deleter);
initialization_in_progress_suppress_logging = false;
}

Expand Down
56 changes: 30 additions & 26 deletions src/emulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,29 +50,6 @@ Emulator::Emulator() {
SetPriorityClass(GetCurrentProcess(), ABOVE_NORMAL_PRIORITY_CLASS);
#endif

// Start logger.
Common::Log::Initialize();
Common::Log::Start();
LOG_INFO(Loader, "Starting shadps4 emulator v{} ", Common::VERSION);
LOG_INFO(Loader, "Revision {}", Common::g_scm_rev);
LOG_INFO(Loader, "Branch {}", Common::g_scm_branch);
LOG_INFO(Loader, "Description {}", Common::g_scm_desc);
LOG_INFO(Loader, "Remote {}", Common::g_scm_remote_url);

LOG_INFO(Config, "General LogType: {}", Config::getLogType());
LOG_INFO(Config, "General isNeo: {}", Config::isNeoModeConsole());
LOG_INFO(Config, "GPU isNullGpu: {}", Config::nullGpu());
LOG_INFO(Config, "GPU shouldDumpShaders: {}", Config::dumpShaders());
LOG_INFO(Config, "GPU vblankDivider: {}", Config::vblankDiv());
LOG_INFO(Config, "Vulkan gpuId: {}", Config::getGpuId());
LOG_INFO(Config, "Vulkan vkValidation: {}", Config::vkValidationEnabled());
LOG_INFO(Config, "Vulkan vkValidationSync: {}", Config::vkValidationSyncEnabled());
LOG_INFO(Config, "Vulkan vkValidationGpu: {}", Config::vkValidationGpuEnabled());
LOG_INFO(Config, "Vulkan crashDiagnostics: {}", Config::getVkCrashDiagnosticEnabled());
LOG_INFO(Config, "Vulkan hostMarkers: {}", Config::getVkHostMarkersEnabled());
LOG_INFO(Config, "Vulkan guestMarkers: {}", Config::getVkGuestMarkersEnabled());
LOG_INFO(Config, "Vulkan rdocEnable: {}", Config::isRdocEnabled());

// Create stdin/stdout/stderr
Common::Singleton<FileSys::HandleTable>::Instance()->CreateStdHandles();

Expand All @@ -90,9 +67,8 @@ Emulator::Emulator() {
const auto user_dir = Common::FS::GetUserPath(Common::FS::PathType::UserDir);
QString filePath = QString::fromStdString((user_dir / "play_time.txt").string());
QFile file(filePath);
if (!file.open(QIODevice::ReadWrite | QIODevice::Text)) {
LOG_INFO(Loader, "Error opening or creating play_time.txt");
}
ASSERT_MSG(file.open(QIODevice::ReadWrite | QIODevice::Text),
"Error opening or creating play_time.txt");
#endif
}

Expand Down Expand Up @@ -138,6 +114,34 @@ void Emulator::Run(const std::filesystem::path& file, const std::vector<std::str
const auto content_id = param_sfo->GetString("CONTENT_ID");
ASSERT_MSG(content_id.has_value(), "Failed to get CONTENT_ID");
id = std::string(*content_id, 7, 9);

if (Config::getSeparateLogFilesEnabled()) {
Common::Log::Initialize(id + ".log");
}
else {
Common::Log::Initialize();
}
Common::Log::Start();
LOG_INFO(Loader, "Starting shadps4 emulator v{} ", Common::VERSION);
LOG_INFO(Loader, "Revision {}", Common::g_scm_rev);
LOG_INFO(Loader, "Branch {}", Common::g_scm_branch);
LOG_INFO(Loader, "Description {}", Common::g_scm_desc);
LOG_INFO(Loader, "Remote {}", Common::g_scm_remote_url);

LOG_INFO(Config, "General LogType: {}", Config::getLogType());
LOG_INFO(Config, "General isNeo: {}", Config::isNeoModeConsole());
LOG_INFO(Config, "GPU isNullGpu: {}", Config::nullGpu());
LOG_INFO(Config, "GPU shouldDumpShaders: {}", Config::dumpShaders());
LOG_INFO(Config, "GPU vblankDivider: {}", Config::vblankDiv());
LOG_INFO(Config, "Vulkan gpuId: {}", Config::getGpuId());
LOG_INFO(Config, "Vulkan vkValidation: {}", Config::vkValidationEnabled());
LOG_INFO(Config, "Vulkan vkValidationSync: {}", Config::vkValidationSyncEnabled());
LOG_INFO(Config, "Vulkan vkValidationGpu: {}", Config::vkValidationGpuEnabled());
LOG_INFO(Config, "Vulkan crashDiagnostics: {}", Config::getVkCrashDiagnosticEnabled());
LOG_INFO(Config, "Vulkan hostMarkers: {}", Config::getVkHostMarkersEnabled());
LOG_INFO(Config, "Vulkan guestMarkers: {}", Config::getVkGuestMarkersEnabled());
LOG_INFO(Config, "Vulkan rdocEnable: {}", Config::isRdocEnabled());

Libraries::NpTrophy::game_serial = id;
const auto trophyDir =
Common::FS::GetUserPath(Common::FS::PathType::MetaDataDir) / id / "TrophyFiles";
Expand Down
6 changes: 5 additions & 1 deletion src/qt_gui/settings_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,8 @@ void SettingsDialog::LoadValuesFromConfig() {
QString::fromStdString(toml::find_or<std::string>(data, "Keys", "TrophyKey", "")));
ui->trophyKeyLineEdit->setEchoMode(QLineEdit::Password);
ui->debugDump->setChecked(toml::find_or<bool>(data, "Debug", "DebugDump", false));
ui->separateLogFilesCheckbox->setChecked(
toml::find_or<bool>(data, "Debug", "isSeparateLogFilesEnabled", false));
ui->vkValidationCheckBox->setChecked(toml::find_or<bool>(data, "Vulkan", "validation", false));
ui->vkSyncValidationCheckBox->setChecked(
toml::find_or<bool>(data, "Vulkan", "validation_sync", false));
Expand Down Expand Up @@ -626,7 +628,8 @@ void SettingsDialog::updateNoteTextEdit(const QString& elementName) {
text = tr("Copy GPU Buffers:\\nGets around race conditions involving GPU submits.\\nMay or may not help with PM4 type 0 crashes.");
} else if (elementName == "collectShaderCheckBox") {
text = tr("Collect Shaders:\\nYou need this enabled to edit shaders with the debug menu (Ctrl + F10).");
}
} else if (elementName == "separateLogFilesCheckbox") {
text = tr("Separate Log Files:\\nWrites a separate logfile for each game.");}
// clang-format on
ui->descriptionText->setText(text.replace("\\n", "\n"));
}
Expand Down Expand Up @@ -678,6 +681,7 @@ void SettingsDialog::UpdateSettings() {
Config::setLoadGameSizeEnabled(ui->gameSizeCheckBox->isChecked());
Config::setShowSplash(ui->showSplashCheckBox->isChecked());
Config::setDebugDump(ui->debugDump->isChecked());
Config::setSeparateLogFilesEnabled(ui->separateLogFilesCheckbox->isChecked());
Config::setVkValidation(ui->vkValidationCheckBox->isChecked());
Config::setVkSyncValidation(ui->vkSyncValidationCheckBox->isChecked());
Config::setRdocEnabled(ui->rdocCheckBox->isChecked());
Expand Down
103 changes: 57 additions & 46 deletions src/qt_gui/settings_dialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
</size>
</property>
<property name="currentIndex">
<number>0</number>
<number>6</number>
</property>
<widget class="QScrollArea" name="generalTab">
<property name="widgetResizable">
Expand All @@ -73,8 +73,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>946</width>
<height>536</height>
<width>718</width>
<height>332</height>
</rect>
</property>
<layout class="QVBoxLayout" name="generalTabVLayout" stretch="0">
Expand Down Expand Up @@ -494,8 +494,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>946</width>
<height>536</height>
<width>646</width>
<height>395</height>
</rect>
</property>
<layout class="QVBoxLayout" name="guiTabVLayout" stretch="0">
Expand Down Expand Up @@ -943,8 +943,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>946</width>
<height>536</height>
<width>545</width>
<height>141</height>
</rect>
</property>
<layout class="QVBoxLayout" name="graphicsTabVLayout" stretch="0,0">
Expand Down Expand Up @@ -1187,8 +1187,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>946</width>
<height>536</height>
<width>234</width>
<height>292</height>
</rect>
</property>
<layout class="QVBoxLayout" name="userTabVLayout" stretch="0,0,1">
Expand Down Expand Up @@ -1331,8 +1331,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>946</width>
<height>536</height>
<width>455</width>
<height>252</height>
</rect>
</property>
<layout class="QVBoxLayout" name="inputTabVLayout" stretch="0,0">
Expand Down Expand Up @@ -1615,8 +1615,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>946</width>
<height>536</height>
<width>216</width>
<height>254</height>
</rect>
</property>
<layout class="QVBoxLayout" name="pathsTabLayout">
Expand Down Expand Up @@ -1877,39 +1877,50 @@
</property>
<layout class="QVBoxLayout" name="advancedLayout">
<item>
<widget class="QCheckBox" name="crashDiagnosticsCheckBox">
<property name="text">
<string>Enable Crash Diagnostics</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="collectShaderCheckBox">
<property name="text">
<string>Collect Shaders</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="copyGPUBuffersCheckBox">
<property name="text">
<string>Copy GPU Buffers</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="hostMarkersCheckBox">
<property name="text">
<string>Host Debug Markers</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="guestMarkersCheckBox">
<property name="text">
<string>Guest Debug Markers</string>
</property>
</widget>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QCheckBox" name="collectShaderCheckBox">
<property name="text">
<string>Collect Shaders</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QCheckBox" name="copyGPUBuffersCheckBox">
<property name="text">
<string>Copy GPU Buffers</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="crashDiagnosticsCheckBox">
<property name="text">
<string>Enable Crash Diagnostics</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QCheckBox" name="hostMarkersCheckBox">
<property name="text">
<string>Host Debug Markers</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QCheckBox" name="guestMarkersCheckBox">
<property name="text">
<string>Guest Debug Markers</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QCheckBox" name="separateLogFilesCheckbox">
<property name="text">
<string>Separate Log Files</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
Expand Down
Loading