From 2f807a4c0da400606008195d15c6d7d9d733e3d2 Mon Sep 17 00:00:00 2001 From: jackun Date: Fri, 16 Jul 2021 03:28:46 +0300 Subject: [PATCH] Add `spdlog` wrap and logging --- .gitignore | 1 + meson.build | 10 ++++++ meson_options.txt | 1 + src/battery.cpp | 3 +- src/config.cpp | 6 ++-- src/cpu.cpp | 59 ++++++++++++++--------------------- src/dbus.cpp | 28 ++++++----------- src/dbus_helpers.h | 13 ++++---- src/file_utils.cpp | 7 ++--- src/gl/imgui_hud.cpp | 8 ----- src/gl/imgui_impl_opengl3.cpp | 17 +++++----- src/gl/inject_egl.cpp | 23 +++++--------- src/gl/inject_glx.cpp | 52 ++++++++++-------------------- src/gpu.cpp | 9 +++--- src/loaders/loader_dbus.cpp | 3 +- src/loaders/loader_glx.cpp | 3 +- src/loaders/loader_libdrm.cpp | 5 +-- src/loaders/loader_nvctrl.cpp | 3 +- src/loaders/loader_nvml.cpp | 3 +- src/loaders/loader_x11.cpp | 3 +- src/logging.cpp | 9 ++---- src/meson.build | 1 + src/notify.cpp | 7 ++--- src/nvctrl.cpp | 14 ++++----- src/nvml.cpp | 15 ++++----- src/overlay.cpp | 51 +++++++++++++----------------- src/overlay_params.cpp | 29 ++++++++++------- src/shared_x11.cpp | 9 +++--- src/vulkan.cpp | 12 +++---- subprojects/spdlog.wrap | 12 +++++++ 30 files changed, 189 insertions(+), 227 deletions(-) create mode 100644 subprojects/spdlog.wrap diff --git a/.gitignore b/.gitignore index dde6add8..14654d5c 100644 --- a/.gitignore +++ b/.gitignore @@ -40,6 +40,7 @@ lib32-mangohud*.tar.* subprojects/packagecache/ subprojects/Vulkan-Headers-*/ subprojects/imgui-*/ +subprojects/spdlog-*/ #GNU Global Metadata **/GPATH diff --git a/meson.build b/meson.build index a8f843e7..c45b3ea3 100644 --- a/meson.build +++ b/meson.build @@ -242,6 +242,16 @@ dearimgui_sp = subproject('imgui', default_options: [ ]) dearimgui_dep = dearimgui_sp.get_variable('imgui_dep') +spdlog_dep = cpp.find_library('spdlog', required: get_option('use_system_spdlog')) +if not spdlog_dep.found() + spdlog_sp = subproject('spdlog', default_options: [ + 'default_library=static', + ]) + spdlog_dep = spdlog_sp.get_variable('spdlog_dep') +else + spdlog_dep = dependency('spdlog', required: true) +endif + if ['windows', 'mingw'].contains(host_machine.system()) subdir('modules/minhook') inc_common += ( include_directories('modules/minhook/include')) diff --git a/meson_options.txt b/meson_options.txt index c3526553..6036bd27 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -1,5 +1,6 @@ option('glibcxx_asserts', type : 'boolean', value : false) option('use_system_vulkan', type : 'feature', value : 'disabled', description: 'Use system vulkan headers instead of the provided ones') +option('use_system_spdlog', type : 'feature', value : 'disabled', description: 'Use system spdlog library') option('vulkan_datadir', type : 'string', value : '', description: 'Path to the system vulkan headers data directory if different from MangoHud\'s datadir') option('append_libdir_mangohud', type : 'boolean', value : true, description: 'Append "mangohud" to libdir path or not.') option('ld_libdir_prefix', type : 'boolean', value : false, description: 'Set ld libdir to "$prefix/lib/mangohud/\$LIB"') diff --git a/src/battery.cpp b/src/battery.cpp index e61e6681..9e3e0435 100644 --- a/src/battery.cpp +++ b/src/battery.cpp @@ -1,6 +1,7 @@ #include #include "battery.h" #include +#include namespace fs = ghc::filesystem; @@ -26,7 +27,7 @@ void BatteryStats::update() { if (!batt_check) { numBattery(); if (batt_count == 0) { - std::cerr<<"MANGOHUD: No battery found\n"; + spdlog::error("No battery found"); } } diff --git a/src/config.cpp b/src/config.cpp index 616594b3..25611422 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include "config.h" #include "file_utils.h" #include "string_utils.h" @@ -110,17 +111,16 @@ void parseConfigFile(overlay_params& params) { std::ifstream stream(*p); if (!stream.good()) { // printing just so user has an idea of possible configs - std::cerr << "skipping config: " << *p << " [ not found ]" << std::endl; + spdlog::info("skipping config: '{}' [ not found ]", *p); continue; } stream.imbue(std::locale::classic()); - std::cerr << "parsing config: " << *p; + spdlog::info("parsing config: '{}'", *p); while (std::getline(stream, line)) { parseConfigLine(line, params.options); } - std::cerr << " [ ok ]" << std::endl; params.config_file_path = *p; return; } diff --git a/src/cpu.cpp b/src/cpu.cpp index 2816c5a5..86fa7a9d 100644 --- a/src/cpu.cpp +++ b/src/cpu.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include "string_utils.h" #ifndef PROCDIR @@ -116,13 +117,13 @@ bool CPUStats::Init() m_cpuData.clear(); if (!file.is_open()) { - std::cerr << "Failed to opening " << PROCSTATFILE << std::endl; + spdlog::error("Failed to opening " PROCSTATFILE); return false; } do { if (!std::getline(file, line)) { - std::cerr << "Failed to read all of " << PROCSTATFILE << std::endl; + spdlog::debug("Failed to read all of " PROCSTATFILE); return false; } else if (starts_with(line, "cpu")) { if (first) { @@ -175,7 +176,7 @@ bool CPUStats::UpdateCPUData() bool ret = false; if (!file.is_open()) { - std::cerr << "Failed to opening " << PROCSTATFILE << std::endl; + spdlog::error("Failed to opening " PROCSTATFILE); return false; } @@ -189,21 +190,20 @@ bool CPUStats::UpdateCPUData() } else if (sscanf(line.c_str(), "cpu%4d %16llu %16llu %16llu %16llu %16llu %16llu %16llu %16llu %16llu %16llu", &cpuid, &usertime, &nicetime, &systemtime, &idletime, &ioWait, &irq, &softIrq, &steal, &guest, &guestnice) == 11) { - //std::cerr << "Parsing 'cpu" << cpuid << "' line:" << line << std::endl; + //spdlog::debug("Parsing 'cpu{}' line:{}", cpuid, line); if (!ret) { - //std::cerr << "Failed to parse 'cpu' line" << std::endl; - std::cerr << "Failed to parse 'cpu' line:" << line << std::endl; + spdlog::debug("Failed to parse 'cpu' line:{}", line); return false; } if (cpuid < 0 /* can it? */) { - std::cerr << "Cpu id '" << cpuid << "' is out of bounds" << std::endl; + spdlog::debug("Cpu id '{}' is out of bounds", cpuid); return false; } if ((size_t)cpuid >= m_cpuData.size()) { - std::cerr << "Cpu id '" << cpuid << "' is out of bounds, reiniting" << std::endl; + spdlog::debug("Cpu id '{}' is out of bounds, reiniting", cpuid); return Reinit(); } @@ -399,9 +399,7 @@ static bool find_fallback_temp_input(const std::string path, std::string& input) if (!ends_with(file, "_input")) continue; input = path + "/" + file; -#ifndef NDEBUG - std::cerr << "fallback cpu temp input: " << input << "\n"; -#endif + spdlog::debug("fallback cpu temp input: {}", input); return true; } return false; @@ -418,9 +416,8 @@ bool CPUStats::GetCpuFile() { for (auto& dir : dirs) { path = hwmon + dir; name = read_line(path + "/name"); -#ifndef NDEBUG - std::cerr << "hwmon: sensor name: " << name << std::endl; -#endif + spdlog::debug("hwmon: sensor name: {}", name); + if (name == "coretemp") { find_temp_input(path, input, "Package id 0"); break; @@ -437,12 +434,11 @@ bool CPUStats::GetCpuFile() { } if (path.empty() || (!file_exists(input) && !find_fallback_temp_input(path, input))) { - std::cerr << "MANGOHUD: Could not find cpu temp sensor location" << std::endl; + spdlog::error("Could not find cpu temp sensor location"); return false; } else { -#ifndef NDEBUG - std::cerr << "hwmon: using input: " << input << std::endl; -#endif + + spdlog::debug("hwmon: using input: {}", input); m_cpuTempFile = fopen(input.c_str(), "r"); } return true; @@ -480,12 +476,10 @@ CPUPowerData_k10temp* init_cpu_power_data_k10temp(const std::string path) { if(!find_input(path, "in", socVoltageInput, "Vsoc")) return nullptr; if(!find_input(path, "curr", socCurrentInput, "Isoc")) return nullptr; -#ifndef NDEBUG - std::cerr << "hwmon: using input: " << coreVoltageInput << std::endl; - std::cerr << "hwmon: using input: " << coreCurrentInput << std::endl; - std::cerr << "hwmon: using input: " << socVoltageInput << std::endl; - std::cerr << "hwmon: using input: " << socCurrentInput << std::endl; -#endif + spdlog::debug("hwmon: using input: {}", coreVoltageInput); + spdlog::debug("hwmon: using input: {}", coreCurrentInput); + spdlog::debug("hwmon: using input: {}", socVoltageInput); + spdlog::debug("hwmon: using input: {}", socCurrentInput); powerData->coreVoltageFile = fopen(coreVoltageInput.c_str(), "r"); powerData->coreCurrentFile = fopen(coreCurrentInput.c_str(), "r"); @@ -503,10 +497,8 @@ CPUPowerData_zenpower* init_cpu_power_data_zenpower(const std::string path) { if(!find_input(path, "power", corePowerInput, "SVI2_P_Core")) return nullptr; if(!find_input(path, "power", socPowerInput, "SVI2_P_SoC")) return nullptr; -#ifndef NDEBUG - std::cerr << "hwmon: using input: " << corePowerInput << std::endl; - std::cerr << "hwmon: using input: " << socPowerInput << std::endl; -#endif + spdlog::debug("hwmon: using input: {}", corePowerInput); + spdlog::debug("hwmon: using input: {}", socPowerInput); powerData->corePowerFile = fopen(corePowerInput.c_str(), "r"); powerData->socPowerFile = fopen(socPowerInput.c_str(), "r"); @@ -538,9 +530,8 @@ bool CPUStats::InitCpuPowerData() { for (auto& dir : dirs) { path = hwmon + dir; name = read_line(path + "/name"); -#ifndef NDEBUG - std::cerr << "hwmon: sensor name: " << name << std::endl; -#endif + spdlog::debug("hwmon: sensor name: {}", name); + if (name == "k10temp") { cpuPowerData = (CPUPowerData*)init_cpu_power_data_k10temp(path); break; @@ -556,9 +547,7 @@ bool CPUStats::InitCpuPowerData() { for (auto& dir : powercap_dirs) { path = powercap + dir; name = read_line(path + "/name"); -#ifndef NDEBUG - std::cerr << "powercap: name: " << name << std::endl; -#endif + spdlog::debug("powercap: name: {}", name); if (name == "package-0") { cpuPowerData = (CPUPowerData*)init_cpu_power_data_rapl(path); break; @@ -567,7 +556,7 @@ bool CPUStats::InitCpuPowerData() { } if(cpuPowerData == nullptr) { - std::cerr << "MANGOHUD: Failed to initialize CPU power data" << std::endl; + spdlog::error("Failed to initialize CPU power data"); return false; } diff --git a/src/dbus.cpp b/src/dbus.cpp index 44ffafc7..f1fc38be 100644 --- a/src/dbus.cpp +++ b/src/dbus.cpp @@ -163,7 +163,7 @@ bool dbus_manager::init(const std::string& requested_player) { } if (!m_dbus_ldr.IsLoaded() && !m_dbus_ldr.Load("libdbus-1.so.3")) { - std::cerr << "MANGOHUD: Could not load libdbus-1.so.3\n"; + spdlog::error("Could not load libdbus-1.so.3"); return false; } @@ -173,14 +173,13 @@ bool dbus_manager::init(const std::string& requested_player) { if (nullptr == (m_dbus_conn = m_dbus_ldr.bus_get(DBUS_BUS_SESSION, &m_error))) { - std::cerr << "MANGOHUD: " << m_error.message << std::endl; + spdlog::error("{}", m_error.message); m_dbus_ldr.error_free(&m_error); return false; } - std::cout << "MANGOHUD: Connected to D-Bus as \"" - << m_dbus_ldr.bus_get_unique_name(m_dbus_conn) << "\"." - << std::endl; + spdlog::debug("Connected to D-Bus as \"{}\"", + m_dbus_ldr.bus_get_unique_name(m_dbus_conn)); dbus_list_name_to_owner(); connect_to_signals(); @@ -198,10 +197,7 @@ bool dbus_manager::select_active_player() { // If the requested player is available, use it if (m_name_owners.count(m_requested_player) > 0) { m_active_player = m_requested_player; -#ifndef NDEBUG - std::cerr << "Selecting requested player: " << m_requested_player - << "\n"; -#endif + spdlog::debug("Selecting requested player: {}", m_requested_player); get_media_player_metadata(meta, m_active_player); } } else { @@ -221,9 +217,7 @@ bool dbus_manager::select_active_player() { if(it != m_name_owners.end()){ m_active_player = it->first; -#ifndef NDEBUG - std::cerr << "Selecting fallback player: " << m_active_player << "\n"; -#endif + spdlog::debug("Selecting fallback player: {}", m_active_player); } } } @@ -232,9 +226,7 @@ bool dbus_manager::select_active_player() { onNewPlayer(meta); return true; } else { -#ifndef NDEBUG - std::cerr << "No active players\n"; -#endif + spdlog::debug("No active players"); if (!old_active_player.empty()) { onNoPlayer(); } @@ -333,8 +325,7 @@ void dbus_manager::connect_to_signals() { auto signal = format_signal(kv); m_dbus_ldr.bus_add_match(m_dbus_conn, signal.c_str(), &m_error); if (m_dbus_ldr.error_is_set(&m_error)) { - ::perror(m_error.name); - ::perror(m_error.message); + spdlog::error("{}: {}", m_error.name, m_error.message); m_dbus_ldr.error_free(&m_error); // return; } @@ -352,8 +343,7 @@ void dbus_manager::disconnect_from_signals() { auto signal = format_signal(kv); m_dbus_ldr.bus_remove_match(m_dbus_conn, signal.c_str(), &m_error); if (m_dbus_ldr.error_is_set(&m_error)) { - ::perror(m_error.name); - ::perror(m_error.message); + spdlog::error("{}: {}", m_error.name, m_error.message); m_dbus_ldr.error_free(&m_error); } } diff --git a/src/dbus_helpers.h b/src/dbus_helpers.h index b91a9f29..b0191592 100644 --- a/src/dbus_helpers.h +++ b/src/dbus_helpers.h @@ -3,6 +3,7 @@ #define MANGOHUD_DBUS_HELPERS #include +#include #include "loaders/loader_dbus.h" @@ -136,8 +137,8 @@ template auto DBusMessageIter_wrap::get_primitive() -> T { auto requested_type = detail::dbus_type_identifier; if (requested_type != type()) { - std::cerr << "Type mismatch: '" << ((char)requested_type) << "' vs '" - << (char)type() << "'\n"; + spdlog::error("Type mismatch: '{}' vs '{}'", + ((char)requested_type), (char)type()); #ifndef NDEBUG exit(-1); #else @@ -190,13 +191,13 @@ auto DBusMessageIter_wrap::get_stringified() -> std::string { if (is_unsigned()) return std::to_string(get_unsigned()); if (is_signed()) return std::to_string(get_signed()); if (is_double()) return std::to_string(get_primitive()); - std::cerr << "stringify failed\n"; + spdlog::error("stringify failed"); return std::string(); } auto DBusMessageIter_wrap::get_array_iter() -> DBusMessageIter_wrap { if (!is_array()) { - std::cerr << "Not an array; " << (char)type() << "\n"; + spdlog::error("Not an array; {}", (char)type()); return DBusMessageIter_wrap(DBusMessageIter{}, m_DBus); } @@ -207,7 +208,7 @@ auto DBusMessageIter_wrap::get_array_iter() -> DBusMessageIter_wrap { auto DBusMessageIter_wrap::get_dict_entry_iter() -> DBusMessageIter_wrap { if (type() != DBUS_TYPE_DICT_ENTRY) { - std::cerr << "Not a dict entry" << (char)type() << "\n"; + spdlog::error("Not a dict entry {}", (char)type()); return DBusMessageIter_wrap(DBusMessageIter{}, m_DBus); } @@ -334,7 +335,7 @@ DBusMessage_wrap DBusMessage_wrap::send_with_reply_and_block( auto reply = m_DBus->connection_send_with_reply_and_block(conn, m_msg, timeout, &err); if (reply == nullptr) { - std::cerr << "MangoHud[" << __func__ << "]: " << err.message << "\n"; + spdlog::error("[{}]: {}", __func__, err.message); free_if_owning(); m_DBus->error_free(&err); } diff --git a/src/file_utils.cpp b/src/file_utils.cpp index d87ec740..f3ef8a3f 100644 --- a/src/file_utils.cpp +++ b/src/file_utils.cpp @@ -8,6 +8,7 @@ #include #include #include +#include std::string read_line(const std::string& filename) { @@ -22,8 +23,7 @@ bool find_folder(const char* root, const char* prefix, std::string& dest) struct dirent* dp; DIR* dirp = opendir(root); if (!dirp) { - std::cerr << "Error opening directory '" << root << "': "; - perror(""); + spdlog::error("Error opening directory '{}': {}", root, strerror(errno)); return false; } @@ -52,8 +52,7 @@ std::vector ls(const char* root, const char* prefix, LS_FLAGS flags DIR* dirp = opendir(root); if (!dirp) { - std::cerr << "Error opening directory '" << root << "': "; - perror(""); + spdlog::error("Error opening directory '{}': {}", root, strerror(errno)); return list; } diff --git a/src/gl/imgui_hud.cpp b/src/gl/imgui_hud.cpp index bf95945e..5e7fcdbb 100644 --- a/src/gl/imgui_hud.cpp +++ b/src/gl/imgui_hud.cpp @@ -168,10 +168,6 @@ void imgui_create(void *ctx) void imgui_shutdown() { -#ifndef NDEBUG - std::cerr << __func__ << std::endl; -#endif - if (state.imgui_ctx) { ImGui::SetCurrentContext(state.imgui_ctx); ImGui_ImplOpenGL3_Shutdown(); @@ -185,10 +181,6 @@ void imgui_set_context(void *ctx) { if (!ctx) return; - -#ifndef NDEBUG - std::cerr << __func__ << ": " << ctx << std::endl; -#endif imgui_create(ctx); } diff --git a/src/gl/imgui_impl_opengl3.cpp b/src/gl/imgui_impl_opengl3.cpp index 1a1c7347..ee94964e 100644 --- a/src/gl/imgui_impl_opengl3.cpp +++ b/src/gl/imgui_impl_opengl3.cpp @@ -70,6 +70,7 @@ #include // intptr_t #include +#include #include #include "overlay.h" @@ -138,13 +139,13 @@ static bool CheckShader(GLuint handle, const char* desc) glGetShaderiv(handle, GL_COMPILE_STATUS, &status); glGetShaderiv(handle, GL_INFO_LOG_LENGTH, &log_length); if ((GLboolean)status == GL_FALSE) - fprintf(stderr, "ERROR: ImGui_ImplOpenGL3_CreateDeviceObjects: failed to compile %s!\n", desc); + spdlog::error("ImGui_ImplOpenGL3_CreateDeviceObjects: failed to compile {}!", desc); if (log_length > 1) { ImVector buf; buf.resize((int)(log_length + 1)); glGetShaderInfoLog(handle, log_length, NULL, (GLchar*)buf.begin()); - fprintf(stderr, "%s\n", buf.begin()); + spdlog::error("{}", buf.begin()); } return (GLboolean)status == GL_TRUE; } @@ -156,13 +157,13 @@ static bool CheckProgram(GLuint handle, const char* desc) glGetProgramiv(handle, GL_LINK_STATUS, &status); glGetProgramiv(handle, GL_INFO_LOG_LENGTH, &log_length); if ((GLboolean)status == GL_FALSE) - fprintf(stderr, "ERROR: ImGui_ImplOpenGL3_CreateDeviceObjects: failed to link %s! (with GLSL '%s')\n", desc, g_GlslVersionString); + spdlog::error("ImGui_ImplOpenGL3_CreateDeviceObjects: failed to link {}! (with GLSL '{}')", desc, g_GlslVersionString); if (log_length > 1) { ImVector buf; buf.resize((int)(log_length + 1)); glGetProgramInfoLog(handle, log_length, NULL, (GLchar*)buf.begin()); - fprintf(stderr, "%s\n", buf.begin()); + spdlog::error("{}", buf.begin()); } return (GLboolean)status == GL_TRUE; } @@ -478,16 +479,12 @@ void ImGui_ImplOpenGL3_NewFrame() if (!g_ShaderHandle) ImGui_ImplOpenGL3_CreateDeviceObjects(); else if (!glIsProgram(g_ShaderHandle)) { // TODO Got created in a now dead context? -#ifndef NDEBUG - fprintf(stderr, "MANGOHUD: recreating lost objects\n"); -#endif + spdlog::debug("Recreating lost objects"); ImGui_ImplOpenGL3_CreateDeviceObjects(); } if (!glIsTexture(g_FontTexture)) { -#ifndef NDEBUG - fprintf(stderr, "MANGOHUD: GL Texture lost? Regenerating.\n"); -#endif + spdlog::debug("GL Texture lost? Regenerating."); g_FontTexture = 0; ImGui_ImplOpenGL3_CreateFontsTexture(); } diff --git a/src/gl/inject_egl.cpp b/src/gl/inject_egl.cpp index 6080b368..5d7268cb 100644 --- a/src/gl/inject_egl.cpp +++ b/src/gl/inject_egl.cpp @@ -2,14 +2,13 @@ #include #include #include +#include +#include +#include #include "real_dlsym.h" #include "mesa/util/macros.h" #include "mesa/util/os_time.h" #include "blacklist.h" - -#include -#include - #include "imgui_hud.h" using namespace MangoHud::GL; @@ -23,7 +22,7 @@ void* get_egl_proc_address(const char* name) { if (!pfn_eglGetProcAddress) { void *handle = real_dlopen("libEGL.so.1", RTLD_LAZY|RTLD_LOCAL); if (!handle) { - std::cerr << "MANGOHUD: Failed to open " << "" MANGOHUD_ARCH << " libEGL.so.1: " << dlerror() << std::endl; + spdlog::error("Failed to open " MANGOHUD_ARCH " libEGL.so.1: {}", dlerror()); } else { pfn_eglGetProcAddress = reinterpret_cast(real_dlsym(handle, "eglGetProcAddress")); } @@ -36,7 +35,7 @@ void* get_egl_proc_address(const char* name) { func = get_proc_address( name ); if (!func) { - std::cerr << "MANGOHUD: Failed to get function '" << name << "'" << std::endl; + spdlog::debug("Failed to get function '{}'", name); } return func; @@ -44,10 +43,7 @@ void* get_egl_proc_address(const char* name) { //EGLBoolean eglMakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx); EXPORT_C_(int) eglMakeCurrent_OFF(void *dpy, void *draw, void *read,void *ctx) { - -#ifndef NDEBUG - std::cerr << __func__ << ": " << draw << ", " << ctx << std::endl; -#endif + spdlog::trace("{}: draw: {}, ctx: {}", __func__, draw, ctx); int ret = 0; return ret; } @@ -63,9 +59,6 @@ EXPORT_C_(unsigned int) eglSwapBuffers( void* dpy, void* surf) if (!pfn_eglQuerySurface) pfn_eglQuerySurface = reinterpret_cast(get_egl_proc_address("eglQuerySurface")); - - //std::cerr << __func__ << "\n"; - imgui_create(surf); int width=0, height=0; @@ -73,7 +66,6 @@ EXPORT_C_(unsigned int) eglSwapBuffers( void* dpy, void* surf) pfn_eglQuerySurface(dpy, surf, 0x3057, &width)) imgui_render(width, height); - //std::cerr << "\t" << width << " x " << height << "\n"; using namespace std::chrono_literals; if (fps_limit_stats.targetFrameTime > 0s){ fps_limit_stats.frameStart = Clock::now(); @@ -111,10 +103,9 @@ EXPORT_C_(void *) mangohud_find_egl_ptr(const char *name) } EXPORT_C_(void *) eglGetProcAddress(const char* procName) { - //std::cerr << __func__ << ": " << procName << std::endl; - void* real_func = get_egl_proc_address(procName); void* func = mangohud_find_egl_ptr(procName); + spdlog::trace("{}: proc: {}, real: {}, fun: {}", __func__, procName, real_func, func); if (func && real_func) return func; diff --git a/src/gl/inject_glx.cpp b/src/gl/inject_glx.cpp index 4b38b631..47e8a3ff 100644 --- a/src/gl/inject_glx.cpp +++ b/src/gl/inject_glx.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include "real_dlsym.h" #include "loaders/loader_glx.h" #include "loaders/loader_x11.h" @@ -47,7 +48,7 @@ void* get_glx_proc_address(const char* name) { func = get_proc_address( name ); if (!func) { - std::cerr << "MANGOHUD: Failed to get function '" << name << "'" << std::endl; + spdlog::error("Failed to get function '{}'", name); } return func; @@ -59,9 +60,7 @@ EXPORT_C_(void *) glXCreateContext(void *dpy, void *vis, void *shareList, int di void *ctx = glx.CreateContext(dpy, vis, shareList, direct); if (ctx) refcnt++; -#ifndef NDEBUG - std::cerr << __func__ << ":" << ctx << std::endl; -#endif + spdlog::debug("{}: {}", __func__, ctx); return ctx; } @@ -71,9 +70,7 @@ EXPORT_C_(void *) glXCreateContextAttribs(void *dpy, void *config,void *share_co void *ctx = glx.CreateContextAttribs(dpy, config, share_context, direct, attrib_list); if (ctx) refcnt++; -#ifndef NDEBUG - std::cerr << __func__ << ":" << ctx << std::endl; -#endif + spdlog::debug("{}: {}", __func__, ctx); return ctx; } @@ -83,9 +80,7 @@ EXPORT_C_(void *) glXCreateContextAttribsARB(void *dpy, void *config,void *share void *ctx = glx.CreateContextAttribsARB(dpy, config, share_context, direct, attrib_list); if (ctx) refcnt++; -#ifndef NDEBUG - std::cerr << __func__ << ":" << ctx << std::endl; -#endif + spdlog::debug("{}: {}", __func__, ctx); return ctx; } @@ -96,25 +91,18 @@ EXPORT_C_(void) glXDestroyContext(void *dpy, void *ctx) refcnt--; if (refcnt <= 0) imgui_shutdown(); -#ifndef NDEBUG - std::cerr << __func__ << ":" << ctx << std::endl; -#endif + spdlog::debug("{}: {}", __func__, ctx); } EXPORT_C_(int) glXMakeCurrent(void* dpy, void* drawable, void* ctx) { glx.Load(); -#ifndef NDEBUG - std::cerr << __func__ << ": " << drawable << ", " << ctx << std::endl; -#endif - + spdlog::debug("{}: {}, {}", __func__, drawable, ctx); int ret = glx.MakeCurrent(dpy, drawable, ctx); if (!is_blacklisted()) { if (ret) { imgui_set_context(ctx); -#ifndef NDEBUG - std::cerr << "MANGOHUD: GL ref count: " << refcnt << "\n"; -#endif + spdlog::debug("GL ref count: {}", refcnt); } // Afaik -1 only works with EXT version if it has GLX_EXT_swap_control_tear, maybe EGL_MESA_swap_control_tear someday @@ -159,6 +147,7 @@ static void do_imgui_swap(void *dpy, void *drawable) break; } + spdlog::trace("swap buffers: {}x{}", width, height); imgui_render(width, height); } } @@ -196,9 +185,7 @@ EXPORT_C_(int64_t) glXSwapBuffersMscOML(void* dpy, void* drawable, int64_t targe } EXPORT_C_(void) glXSwapIntervalEXT(void *dpy, void *draw, int interval) { -#ifndef NDEBUG - std::cerr << __func__ << ": " << interval << std::endl; -#endif + spdlog::debug("{}: {}", __func__, interval); glx.Load(); if (!glx.SwapIntervalEXT) return; @@ -210,9 +197,7 @@ EXPORT_C_(void) glXSwapIntervalEXT(void *dpy, void *draw, int interval) { } EXPORT_C_(int) glXSwapIntervalSGI(int interval) { -#ifndef NDEBUG - std::cerr << __func__ << ": " << interval << std::endl; -#endif + spdlog::debug("{}: {}", __func__, interval); glx.Load(); if (!glx.SwapIntervalSGI) return -1; @@ -224,9 +209,7 @@ EXPORT_C_(int) glXSwapIntervalSGI(int interval) { } EXPORT_C_(int) glXSwapIntervalMESA(unsigned int interval) { -#ifndef NDEBUG - std::cerr << __func__ << ": " << interval << std::endl; -#endif + spdlog::debug("{}: {}", __func__, interval); glx.Load(); if (!glx.SwapIntervalMESA) return -1; @@ -256,9 +239,7 @@ EXPORT_C_(int) glXGetSwapIntervalMESA() { } } -#ifndef NDEBUG - std::cerr << __func__ << ": " << interval << std::endl; -#endif + spdlog::debug("{}: {}", __func__, interval); return interval; } @@ -300,10 +281,10 @@ EXPORT_C_(void *) mangohud_find_glx_ptr(const char *name) } EXPORT_C_(void *) glXGetProcAddress(const unsigned char* procName) { - //std::cerr << __func__ << ":" << procName << std::endl; - void *real_func = get_glx_proc_address((const char*)procName); void *func = mangohud_find_glx_ptr( (const char*)procName ); + spdlog::trace("{}: '{}', real: {}, fun: {}", __func__, procName, real_func, func); + if (func && real_func) return func; @@ -311,10 +292,9 @@ EXPORT_C_(void *) glXGetProcAddress(const unsigned char* procName) { } EXPORT_C_(void *) glXGetProcAddressARB(const unsigned char* procName) { - //std::cerr << __func__ << ":" << procName << std::endl; - void *real_func = get_glx_proc_address((const char*)procName); void *func = mangohud_find_glx_ptr( (const char*)procName ); + spdlog::trace("{}: '{}', real: {}, fun: {}", __func__, procName, real_func, func); if (func && real_func) return func; diff --git a/src/gpu.cpp b/src/gpu.cpp index 5daf6a9e..1f5a9d4c 100644 --- a/src/gpu.cpp +++ b/src/gpu.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include "nvctrl.h" #include "timing.hpp" #ifdef HAVE_NVML @@ -229,20 +230,20 @@ bool amdgpu_open(const char *path) { int fd = open(path, O_RDWR | O_CLOEXEC); if (fd < 0) { - perror("MANGOHUD: Failed to open DRM device: "); // Gives sensible perror message? + spdlog::error("Failed to open DRM device: {}", strerror(errno)); return false; } drmVersionPtr ver = libdrm_ptr->drmGetVersion(fd); if (!ver) { - perror("MANGOHUD: Failed to query driver version: "); + spdlog::error("Failed to query driver version: {}", strerror(errno)); close(fd); return false; } if (strcmp(ver->name, "amdgpu") || !DRM_ATLEAST_VERSION(ver, 3, 11)) { - fprintf(stderr, "MANGOHUD: Unsupported driver/version: %s %d.%d.%d\n", ver->name, ver->version_major, ver->version_minor, ver->version_patchlevel); + spdlog::error("Unsupported driver/version: {} {}.{}.{}", ver->name, ver->version_major, ver->version_minor, ver->version_patchlevel); close(fd); libdrm_ptr->drmFreeVersion(ver); return false; @@ -259,7 +260,7 @@ bool amdgpu_open(const char *path) { uint32_t drm_major, drm_minor; amdgpu_device_handle dev; if (libdrm_ptr->amdgpu_device_initialize(fd, &drm_major, &drm_minor, &dev)){ - perror("MANGOHUD: Failed to initialize amdgpu device"); + spdlog::error("Failed to initialize amdgpu device: {}", strerror(errno)); close(fd); return false; } diff --git a/src/loaders/loader_dbus.cpp b/src/loaders/loader_dbus.cpp index 0c981a33..b91b21aa 100644 --- a/src/loaders/loader_dbus.cpp +++ b/src/loaders/loader_dbus.cpp @@ -1,6 +1,7 @@ #include "loaders/loader_dbus.h" #include +#include // Put these sanity checks here so that they fire at most once // (to avoid cluttering the build output). @@ -26,7 +27,7 @@ bool libdbus_loader::Load(const std::string& library_name) { #if defined(LIBRARY_LOADER_DBUS_H_DLOPEN) library_ = dlopen(library_name.c_str(), RTLD_LAZY); if (!library_) { - std::cerr << "MANGOHUD: Failed to open " << "" MANGOHUD_ARCH << " " << library_name << ": " << dlerror() << std::endl; + spdlog::error("Failed to open " MANGOHUD_ARCH " {}: {}", library_name, dlerror()); return false; } diff --git a/src/loaders/loader_glx.cpp b/src/loaders/loader_glx.cpp index dfe0b7f2..ca22f636 100644 --- a/src/loaders/loader_glx.cpp +++ b/src/loaders/loader_glx.cpp @@ -1,4 +1,5 @@ #include +#include #include "real_dlsym.h" #include "loaders/loader_glx.h" @@ -24,7 +25,7 @@ bool glx_loader::Load() { if (!handle) handle = real_dlopen("libGL.so.1", RTLD_LAZY); if (!handle) { - std::cerr << "MANGOHUD: Failed to open " << "" MANGOHUD_ARCH << " libGL.so.1: " << dlerror() << std::endl; + spdlog::error("Failed to open " MANGOHUD_ARCH " libGL.so.1: {}", dlerror()); return false; } diff --git a/src/loaders/loader_libdrm.cpp b/src/loaders/loader_libdrm.cpp index 1e95d5a2..3f0a8247 100644 --- a/src/loaders/loader_libdrm.cpp +++ b/src/loaders/loader_libdrm.cpp @@ -1,6 +1,7 @@ #include "loaders/loader_libdrm.h" #include +#include // Put these sanity checks here so that they fire at most once // (to avoid cluttering the build output). @@ -27,13 +28,13 @@ bool libdrm_loader::Load() { #if defined(LIBRARY_LOADER_LIBDRM_H_DLOPEN) library_drm = dlopen("libdrm.so.2", RTLD_LAZY); if (!library_drm) { - std::cerr << "MANGOHUD: Failed to open " << "" MANGOHUD_ARCH << " libdrm.so.2: " << dlerror() << std::endl; + spdlog::error("Failed to open " MANGOHUD_ARCH " libdrm.so.2: {}", dlerror()); return false; } library_amdgpu = dlopen("libdrm_amdgpu.so.1", RTLD_LAZY); if (!library_amdgpu) { - std::cerr << "MANGOHUD: Failed to open " << "" MANGOHUD_ARCH << " libdrm_amdgpu.so.1: " << dlerror() << std::endl; + spdlog::error("Failed to open " MANGOHUD_ARCH " libdrm_amdgpu.so.1: {}", dlerror()); CleanUp(true); return false; } diff --git a/src/loaders/loader_nvctrl.cpp b/src/loaders/loader_nvctrl.cpp index 915b1e3e..a3e91155 100644 --- a/src/loaders/loader_nvctrl.cpp +++ b/src/loaders/loader_nvctrl.cpp @@ -1,6 +1,7 @@ #include "loader_nvctrl.h" #include #include +#include // Put these sanity checks here so that they fire at most once // (to avoid cluttering the build output). @@ -35,7 +36,7 @@ bool libnvctrl_loader::Load(const std::string& library_name) { #if defined(LIBRARY_LOADER_NVCTRL_H_DLOPEN) library_ = dlopen(library_name.c_str(), RTLD_LAZY); if (!library_) { - std::cerr << "MANGOHUD: Failed to open " << "" MANGOHUD_ARCH << " " << library_name << ": " << dlerror() << std::endl; + spdlog::error("Failed to open " MANGOHUD_ARCH " {}: {}", library_name, dlerror()); return false; } diff --git a/src/loaders/loader_nvml.cpp b/src/loaders/loader_nvml.cpp index eef5875b..7d2c93c2 100644 --- a/src/loaders/loader_nvml.cpp +++ b/src/loaders/loader_nvml.cpp @@ -4,6 +4,7 @@ #include "loader_nvml.h" #include #include +#include // Put these sanity checks here so that they fire at most once // (to avoid cluttering the build output). @@ -38,7 +39,7 @@ bool libnvml_loader::Load(const std::string& library_name) { #if defined(LIBRARY_LOADER_NVML_H_DLOPEN) library_ = dlopen(library_name.c_str(), RTLD_LAZY); if (!library_) { - std::cerr << "MANGOHUD: Failed to open " << "" MANGOHUD_ARCH << " " << library_name << ": " << dlerror() << std::endl; + spdlog::error("Failed to open " MANGOHUD_ARCH " {}: {}", library_name, dlerror()); return false; } #endif diff --git a/src/loaders/loader_x11.cpp b/src/loaders/loader_x11.cpp index 25c65bfd..93ea05a4 100644 --- a/src/loaders/loader_x11.cpp +++ b/src/loaders/loader_x11.cpp @@ -1,5 +1,6 @@ #include "loader_x11.h" #include +#include libx11_loader::libx11_loader() : loaded_(false) { } @@ -15,7 +16,7 @@ bool libx11_loader::Load(const std::string& library_name) { library_ = dlopen(library_name.c_str(), RTLD_LAZY); if (!library_) { - std::cerr << "MANGOHUD: Failed to open " << "" MANGOHUD_ARCH << " " << library_name << ": " << dlerror() << std::endl; + spdlog::error("Failed to open " MANGOHUD_ARCH " {}: {}", library_name, dlerror()); return false; } diff --git a/src/logging.cpp b/src/logging.cpp index ee8600ba..05b2d641 100644 --- a/src/logging.cpp +++ b/src/logging.cpp @@ -1,5 +1,6 @@ #include #include +#include #include "logging.h" #include "overlay.h" #include "config.h" @@ -58,9 +59,7 @@ void upload_files(const std::vector& logFiles){ void writeFile(string filename){ auto& logArray = logger->get_log_data(); -#ifndef NDEBUG - std::cerr << "Writing log file [" << filename << "], " << logArray.size() << " entries\n"; -#endif + spdlog::debug("Writing log file [{}], {} entries", filename, logArray.size()); std::ofstream out(filename, ios::out | ios::app); if (out){ out << "os," << "cpu," << "gpu," << "ram," << "kernel," << "driver," << "cpuscheduler" << endl; @@ -110,9 +109,7 @@ Logger::Logger(overlay_params* in_params) m_values_valid(false), m_params(in_params) { -#ifndef NDEBUG - std::cerr << "Logger constructed!\n"; -#endif + spdlog::debug("Logger constructed!"); } void Logger::start_logging() { diff --git a/src/meson.build b/src/meson.build index 35eb7c48..8bc94635 100644 --- a/src/meson.build +++ b/src/meson.build @@ -186,6 +186,7 @@ vklayer_mesa_overlay = shared_library( dependencies : [ vulkan_wsi_deps, dearimgui_dep, + spdlog_dep, dep_libdrm, #dep_libdrm_amdgpu, dbus_dep, diff --git a/src/notify.cpp b/src/notify.cpp index 47f0be80..27ac8f33 100644 --- a/src/notify.cpp +++ b/src/notify.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include "config.h" #include "notify.h" @@ -27,9 +28,7 @@ static void fileChanged(void *params_void) { std::this_thread::sleep_for(std::chrono::milliseconds(100)); parse_overlay_config(&local_params, getenv("MANGOHUD_CONFIG")); if ((event->mask & IN_DELETE_SELF) || (nt->params->config_file_path != local_params.config_file_path)) { -#ifndef NDEBUG - fprintf(stderr, "MANGOHUD: watching config file: %s\n", local_params.config_file_path.c_str()); -#endif + spdlog::debug("Watching config file: {}", local_params.config_file_path.c_str()); inotify_rm_watch(nt->fd, nt->wd); nt->wd = inotify_add_watch(nt->fd, local_params.config_file_path.c_str(), IN_MODIFY | IN_DELETE_SELF); } @@ -46,7 +45,7 @@ bool start_notifier(notify_thread& nt) { nt.fd = inotify_init1(IN_NONBLOCK); if (nt.fd < 0) { - perror("MANGOHUD: inotify_init1"); + spdlog::error("inotify_init1 failed: {}", strerror(errno)); return false; } diff --git a/src/nvctrl.cpp b/src/nvctrl.cpp index 792c99e7..185a118b 100644 --- a/src/nvctrl.cpp +++ b/src/nvctrl.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include "nvctrl.h" #include "loaders/loader_nvctrl.h" #include "loaders/loader_x11.h" @@ -25,7 +26,7 @@ static bool find_nv_x11(libnvctrl_loader& nvctrl, Display*& dpy) if (d) { if (nvctrl.XNVCTRLIsNvScreen(d, 0)) { dpy = d; - std::cerr << "MANGOHUD: XNVCtrl is using display " << buf << std::endl; + spdlog::debug("XNVCtrl is using display {}", buf); return true; } g_x11->XCloseDisplay(d); @@ -36,14 +37,12 @@ static bool find_nv_x11(libnvctrl_loader& nvctrl, Display*& dpy) bool checkXNVCtrl() { - if (!g_x11->IsLoaded()) { - std::cerr << "MANGOHUD: XNVCtrl: X11 loader failed to load\n"; + if (!g_x11->IsLoaded()) return false; - } auto& nvctrl = get_libnvctrl_loader(); if (!nvctrl.IsLoaded()) { - std::cerr << "MANGOHUD: XNVCtrl loader failed to load\n"; + spdlog::error("XNVCtrl loader failed to load"); return false; } @@ -51,7 +50,7 @@ bool checkXNVCtrl() nvctrlSuccess = find_nv_x11(nvctrl, dpy); if (!nvctrlSuccess) { - std::cerr << "MANGOHUD: XNVCtrl didn't find the correct display" << std::endl; + spdlog::error("XNVCtrl didn't find the correct display"); return false; } @@ -86,7 +85,6 @@ static void parse_token(std::string token, string_map& options) { param = token.substr(0, equal); trim(param); trim(value); - //std::cerr << __func__ << ": " << param << "=" << value << std::endl; if (!param.empty()) options[param] = value; } @@ -94,7 +92,7 @@ static void parse_token(std::string token, string_map& options) { char* get_attr_target_string(libnvctrl_loader& nvctrl, int attr, int target_type, int target_id) { char* c = nullptr; if (!nvctrl.XNVCTRLQueryTargetStringAttribute(display.get(), target_type, target_id, 0, attr, &c)) { - std::cerr << "Failed to query attribute '" << attr << "'.\n"; + spdlog::error("Failed to query attribute '{}'", attr); } return c; } diff --git a/src/nvml.cpp b/src/nvml.cpp index 0461dea1..5e4ef7b8 100644 --- a/src/nvml.cpp +++ b/src/nvml.cpp @@ -1,3 +1,4 @@ +#include #include "loaders/loader_nvml.h" #include "nvidia_info.h" #include @@ -16,30 +17,30 @@ bool checkNVML(const char* pciBusId){ if (nvml.IsLoaded()){ result = nvml.nvmlInit(); if (NVML_SUCCESS != result) { - std::cerr << "MANGOHUD: Nvidia module not loaded\n"; + spdlog::error("Nvidia module not loaded"); } else { nvmlReturn_t ret = NVML_ERROR_UNKNOWN; if (pciBusId && ((ret = nvml.nvmlDeviceGetHandleByPciBusId(pciBusId, &nvidiaDevice)) != NVML_SUCCESS)) { - std::cerr << "MANGOHUD: Getting device handle by PCI bus ID failed: " << nvml.nvmlErrorString(ret) << "\n"; - std::cerr << " Using index 0.\n"; + spdlog::error("Getting device handle by PCI bus ID failed: {}", nvml.nvmlErrorString(ret)); + spdlog::error("Using index 0."); } if (ret != NVML_SUCCESS) ret = nvml.nvmlDeviceGetHandleByIndex(0, &nvidiaDevice); if (ret != NVML_SUCCESS) - std::cerr << "MANGOHUD: Getting device handle failed: " << nvml.nvmlErrorString(ret) << "\n"; + spdlog::error("Getting device handle failed: {}", nvml.nvmlErrorString(ret)); nvmlSuccess = (ret == NVML_SUCCESS); if (ret == NVML_SUCCESS) nvml.nvmlDeviceGetPciInfo_v3(nvidiaDevice, &nvidiaPciInfo); - + return nvmlSuccess; } } else { - std::cerr << "MANGOHUD: Failed to load NVML\n"; + spdlog::error("Failed to load NVML"); } - + return false; } diff --git a/src/overlay.cpp b/src/overlay.cpp index 8284d3f0..6055fe9d 100644 --- a/src/overlay.cpp +++ b/src/overlay.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include "overlay.h" #include "logging.h" #include "cpu.h" @@ -517,12 +518,10 @@ void init_gpu_stats(uint32_t& vendorID, overlay_params& params) << std::setw(1) << pci.func; params.pci_dev = ss.str(); pci_dev = params.pci_dev.c_str(); -#ifndef NDEBUG - std::cerr << "MANGOHUD: PCI device ID: '" << pci_dev << "'\n"; -#endif + spdlog::debug("PCI device ID: '{}'", pci_dev); } else { - std::cerr << "MANGOHUD: Failed to parse PCI device ID: '" << pci_dev << "'\n"; - std::cerr << "MANGOHUD: Specify it as 'domain:bus:slot.func'\n"; + spdlog::error("Failed to parse PCI device ID: '{}'", pci_dev); + spdlog::error("Specify it as 'domain:bus:slot.func'"); } } @@ -549,9 +548,8 @@ void init_gpu_stats(uint32_t& vendorID, overlay_params& params) for (auto& dir : dirs) { path = drm + dir; -#ifndef NDEBUG - std::cerr << "amdgpu path check: " << path << "/device/vendor" << std::endl; -#endif + spdlog::debug("amdgpu path check: {}/device/vendor", path); + string device = read_line(path + "/device/device"); deviceID = strtol(device.c_str(), NULL, 16); string line = read_line(path + "/device/vendor"); @@ -561,18 +559,14 @@ void init_gpu_stats(uint32_t& vendorID, overlay_params& params) if (pci_bus_parsed && pci_dev) { string pci_device = read_symlink((path + "/device").c_str()); -#ifndef NDEBUG - std::cerr << "PCI device symlink: " << pci_device << "\n"; -#endif + spdlog::debug("PCI device symlink: '{}'", pci_device); if (!ends_with(pci_device, pci_dev)) { - std::cerr << "MANGOHUD: skipping GPU, no PCI ID match\n"; + spdlog::debug("skipping GPU, no PCI ID match"); continue; } } -#ifndef NDEBUG - std::cerr << "using amdgpu path: " << path << std::endl; -#endif + spdlog::debug("using amdgpu path: {}", path); #ifdef HAVE_LIBDRM_AMDGPU int idx = -1; @@ -585,12 +579,12 @@ void init_gpu_stats(uint32_t& vendorID, overlay_params& params) using_libdrm = true; getAmdGpuInfo_actual = getAmdGpuInfo_libdrm; amdgpu_set_sampling_period(params.fps_sampling_period); -#ifndef NDEBUG - std::cerr << "MANGOHUD: using libdrm\n"; -#endif + + spdlog::debug("Using libdrm"); + // fall through and open sysfs handles for fallback or check DRM version beforehand } else if (!params.enabled[OVERLAY_PARAM_ENABLED_force_amdgpu_hwmon]) { - std::cerr << "MANGOHUD: Failed to open device '/dev/dri/card" << idx << "' with libdrm, falling back to using hwmon sysfs.\n"; + spdlog::error("Failed to open device '/dev/dri/card{}' with libdrm, falling back to using hwmon sysfs.", idx); } #endif @@ -626,7 +620,7 @@ void init_gpu_stats(uint32_t& vendorID, overlay_params& params) } #endif if (!params.permit_upload) - printf("MANGOHUD: Uploading is disabled (permit_upload = 0)\n"); + spdlog::info("Uploading is disabled (permit_upload = 0)"); } void init_system_info(){ @@ -719,15 +713,14 @@ void init_system_info(){ if (ld_preload) setenv("LD_PRELOAD", ld_preload, 1); -#ifndef NDEBUG - std::cout << "Ram:" << ram << "\n" - << "Cpu:" << cpu << "\n" - << "Kernel:" << kernel << "\n" - << "Os:" << os << "\n" - << "Gpu:" << gpu << "\n" - << "Driver:" << driver << "\n" - << "CPU Scheduler:" << cpusched << std::endl; -#endif + + spdlog::debug("Ram:{}", ram); + spdlog::debug("Cpu:{}", cpu); + spdlog::debug("Kernel:{}", kernel); + spdlog::debug("Os:{}", os); + spdlog::debug("Gpu:{}", gpu); + spdlog::debug("Driver:{}", driver); + spdlog::debug("CPU Scheduler:{}", cpusched); #endif } diff --git a/src/overlay_params.cpp b/src/overlay_params.cpp index 86450fa0..8949cdfb 100644 --- a/src/overlay_params.cpp +++ b/src/overlay_params.cpp @@ -16,6 +16,9 @@ #include #include #include +#include +#include +#include #include "overlay_params.h" #include "overlay.h" @@ -92,8 +95,8 @@ parse_control(const char *str) { int ret = os_socket_listen_abstract(str, 1); if (ret < 0) { - fprintf(stderr, "ERROR: Couldn't create socket pipe at '%s'\n", str); - fprintf(stderr, "ERROR: '%s'\n", strerror(errno)); + spdlog::error("Couldn't create socket pipe at '{}'\n", str); + spdlog::error("ERROR: '{}'", strerror(errno)); return ret; } @@ -126,7 +129,7 @@ parse_string_to_keysym_vec(const char *str) if (xk) keys.push_back(xk); else - std::cerr << "MANGOHUD: Unrecognized key: '" << ks << "'\n"; + spdlog::error("Unrecognized key: '{}'", ks); } } return keys; @@ -167,7 +170,7 @@ parse_fps_limit(const char *str) try { as_int = static_cast(std::stoul(value)); } catch (const std::invalid_argument&) { - std::cerr << "MANGOHUD: invalid fps_limit value: '" << value << "'\n"; + spdlog::error("invalid fps_limit value: '{}'", value); continue; } @@ -317,17 +320,17 @@ parse_benchmark_percentiles(const char *str) try { as_float = parse_float(value, &float_len); } catch (const std::invalid_argument&) { - std::cerr << "MANGOHUD: invalid benchmark percentile: '" << value << "'\n"; + spdlog::error("invalid benchmark percentile: '{}'", value); continue; } if (float_len != value.length()) { - std::cerr << "MANGOHUD: invalid benchmark percentile: '" << value << "'\n"; + spdlog::error("invalid benchmark percentile: '{}'", value); continue; } if (as_float > 100 || as_float < 0) { - std::cerr << "MANGOHUD: benchmark percentile is not between 0 and 100 (" << value << ")\n"; + spdlog::error("benchmark percentile is not between 0 and 100 ({})", value); continue; } @@ -495,9 +498,8 @@ parse_string(const char *s, char *out_param, char *out_value) } if (*s && !i) { - fprintf(stderr, "MANGOHUD: syntax error: unexpected '%c' (%i) while " - "parsing a string\n", *s, *s); - fflush(stderr); + spdlog::error("syntax error: unexpected '{0:c}' ({0:d}) while " + "parsing a string", *s); } return i; @@ -547,7 +549,7 @@ parse_overlay_env(struct overlay_params *params, OVERLAY_PARAMS #undef OVERLAY_PARAM_BOOL #undef OVERLAY_PARAM_CUSTOM - fprintf(stderr, "Unknown option '%s'\n", key); + spdlog::error("Unknown option '{}'", key); } } @@ -555,6 +557,9 @@ void parse_overlay_config(struct overlay_params *params, const char *env) { + if (!spdlog::get("MANGOHUD")) + spdlog::set_default_logger(spdlog::stderr_color_mt("MANGOHUD")); // Just to get the name in log + spdlog::cfg::load_env_levels(); *params = {}; @@ -684,7 +689,7 @@ parse_overlay_config(struct overlay_params *params, OVERLAY_PARAMS #undef OVERLAY_PARAM_BOOL #undef OVERLAY_PARAM_CUSTOM - fprintf(stderr, "Unknown option '%s'\n", it.first.c_str()); + spdlog::error("Unknown option '{}'", it.first.c_str()); } } diff --git a/src/shared_x11.cpp b/src/shared_x11.cpp index 88eb1bf4..48760709 100644 --- a/src/shared_x11.cpp +++ b/src/shared_x11.cpp @@ -1,9 +1,10 @@ -#include "shared_x11.h" -#include "loaders/loader_x11.h" #include #include #include #include +#include +#include "shared_x11.h" +#include "loaders/loader_x11.h" static std::unique_ptr> display; @@ -16,7 +17,7 @@ bool init_x11() { return true; if (!g_x11->IsLoaded()) { - std::cerr << "MANGOHUD: X11 loader failed to load\n"; + spdlog::error("X11 loader failed to load"); failed = true; return false; } @@ -34,7 +35,7 @@ bool init_x11() { failed = !display; if (failed) - std::cerr << "MANGOHUD: XOpenDisplay failed to open display '" << displayid << "'\n"; + spdlog::error("XOpenDisplay failed to open display '{}'", displayid); return !!display; } diff --git a/src/vulkan.cpp b/src/vulkan.cpp index 813b195f..7c5515d8 100644 --- a/src/vulkan.cpp +++ b/src/vulkan.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #include #include @@ -207,7 +208,7 @@ static void unmap_object(uint64_t obj) do { \ VkResult __result = (expr); \ if (__result != VK_SUCCESS) { \ - fprintf(stderr, "'%s' line %i failed with %s\n", \ + spdlog::error("'{}' line {} failed with {}", \ #expr, __LINE__, vk_Result_to_str(__result)); \ } \ } while (0) @@ -708,7 +709,7 @@ static void check_fonts(struct swapchain_data* data) if (params.font_params_hash != data->sw_stats.font_params_hash) { - std::cerr << "MANGOHUD: recreating font image\n"; + spdlog::debug("Recreating font image"); VkDescriptorSet desc_set = (VkDescriptorSet)io.Fonts->TexID; create_fonts(instance_data->params, data->sw_stats.font1, data->sw_stats.font_text); unsigned char* pixels; @@ -725,14 +726,9 @@ static void check_fonts(struct swapchain_data* data) desc_set = create_image_with_desc(data, width, height, VK_FORMAT_R8_UNORM, data->font_image, data->font_mem, data->font_image_view); io.Fonts->SetTexID((ImTextureID)desc_set); - data->font_uploaded = false; data->sw_stats.font_params_hash = params.font_params_hash; - -#ifndef NDEBUG - std::cerr << "MANGOHUD: Default font tex size: " << width << "x" << height << "px (" << (width*height*1) << " bytes)" << "\n"; -#endif - + spdlog::debug("Default font tex size: {}x{}px", width, height); } } diff --git a/subprojects/spdlog.wrap b/subprojects/spdlog.wrap new file mode 100644 index 00000000..27cb9854 --- /dev/null +++ b/subprojects/spdlog.wrap @@ -0,0 +1,12 @@ +[wrap-file] +directory = spdlog-1.8.5 +source_url = https://github.com/gabime/spdlog/archive/v1.8.5.tar.gz +source_filename = v1.8.5.tar.gz +source_hash = 944d0bd7c763ac721398dca2bb0f3b5ed16f67cef36810ede5061f35a543b4b8 +patch_url = https://wrapdb.mesonbuild.com/v1/projects/spdlog/1.8.5/1/get_zip +patch_filename = spdlog-1.8.5-1-wrap.zip +patch_hash = 3c38f275d5792b1286391102594329e98b17737924b344f98312ab09929b74be + +[provide] +spdlog = spdlog_dep +