Add `spdlog` wrap and logging

libinput_only
jackun 3 years ago
parent 537b527af4
commit 2f807a4c0d
No known key found for this signature in database
GPG Key ID: 119DB3F1D05A9ED3

1
.gitignore vendored

@ -40,6 +40,7 @@ lib32-mangohud*.tar.*
subprojects/packagecache/ subprojects/packagecache/
subprojects/Vulkan-Headers-*/ subprojects/Vulkan-Headers-*/
subprojects/imgui-*/ subprojects/imgui-*/
subprojects/spdlog-*/
#GNU Global Metadata #GNU Global Metadata
**/GPATH **/GPATH

@ -242,6 +242,16 @@ dearimgui_sp = subproject('imgui', default_options: [
]) ])
dearimgui_dep = dearimgui_sp.get_variable('imgui_dep') 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()) if ['windows', 'mingw'].contains(host_machine.system())
subdir('modules/minhook') subdir('modules/minhook')
inc_common += ( include_directories('modules/minhook/include')) inc_common += ( include_directories('modules/minhook/include'))

@ -1,5 +1,6 @@
option('glibcxx_asserts', type : 'boolean', value : false) 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_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('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('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"') option('ld_libdir_prefix', type : 'boolean', value : false, description: 'Set ld libdir to "$prefix/lib/mangohud/\$LIB"')

@ -1,6 +1,7 @@
#include <stdio.h> #include <stdio.h>
#include "battery.h" #include "battery.h"
#include <filesystem.h> #include <filesystem.h>
#include <spdlog/spdlog.h>
namespace fs = ghc::filesystem; namespace fs = ghc::filesystem;
@ -26,7 +27,7 @@ void BatteryStats::update() {
if (!batt_check) { if (!batt_check) {
numBattery(); numBattery();
if (batt_count == 0) { if (batt_count == 0) {
std::cerr<<"MANGOHUD: No battery found\n"; spdlog::error("No battery found");
} }
} }

@ -5,6 +5,7 @@
#include <thread> #include <thread>
#include <unordered_map> #include <unordered_map>
#include <string> #include <string>
#include <spdlog/spdlog.h>
#include "config.h" #include "config.h"
#include "file_utils.h" #include "file_utils.h"
#include "string_utils.h" #include "string_utils.h"
@ -110,17 +111,16 @@ void parseConfigFile(overlay_params& params) {
std::ifstream stream(*p); std::ifstream stream(*p);
if (!stream.good()) { if (!stream.good()) {
// printing just so user has an idea of possible configs // 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; continue;
} }
stream.imbue(std::locale::classic()); stream.imbue(std::locale::classic());
std::cerr << "parsing config: " << *p; spdlog::info("parsing config: '{}'", *p);
while (std::getline(stream, line)) while (std::getline(stream, line))
{ {
parseConfigLine(line, params.options); parseConfigLine(line, params.options);
} }
std::cerr << " [ ok ]" << std::endl;
params.config_file_path = *p; params.config_file_path = *p;
return; return;
} }

@ -9,6 +9,7 @@
#include <algorithm> #include <algorithm>
#include <regex> #include <regex>
#include <inttypes.h> #include <inttypes.h>
#include <spdlog/spdlog.h>
#include "string_utils.h" #include "string_utils.h"
#ifndef PROCDIR #ifndef PROCDIR
@ -116,13 +117,13 @@ bool CPUStats::Init()
m_cpuData.clear(); m_cpuData.clear();
if (!file.is_open()) { if (!file.is_open()) {
std::cerr << "Failed to opening " << PROCSTATFILE << std::endl; spdlog::error("Failed to opening " PROCSTATFILE);
return false; return false;
} }
do { do {
if (!std::getline(file, line)) { 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; return false;
} else if (starts_with(line, "cpu")) { } else if (starts_with(line, "cpu")) {
if (first) { if (first) {
@ -175,7 +176,7 @@ bool CPUStats::UpdateCPUData()
bool ret = false; bool ret = false;
if (!file.is_open()) { if (!file.is_open()) {
std::cerr << "Failed to opening " << PROCSTATFILE << std::endl; spdlog::error("Failed to opening " PROCSTATFILE);
return false; 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", } 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) { &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) { if (!ret) {
//std::cerr << "Failed to parse 'cpu' line" << std::endl; spdlog::debug("Failed to parse 'cpu' line:{}", line);
std::cerr << "Failed to parse 'cpu' line:" << line << std::endl;
return false; return false;
} }
if (cpuid < 0 /* can it? */) { 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; return false;
} }
if ((size_t)cpuid >= m_cpuData.size()) { 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(); return Reinit();
} }
@ -399,9 +399,7 @@ static bool find_fallback_temp_input(const std::string path, std::string& input)
if (!ends_with(file, "_input")) if (!ends_with(file, "_input"))
continue; continue;
input = path + "/" + file; input = path + "/" + file;
#ifndef NDEBUG spdlog::debug("fallback cpu temp input: {}", input);
std::cerr << "fallback cpu temp input: " << input << "\n";
#endif
return true; return true;
} }
return false; return false;
@ -418,9 +416,8 @@ bool CPUStats::GetCpuFile() {
for (auto& dir : dirs) { for (auto& dir : dirs) {
path = hwmon + dir; path = hwmon + dir;
name = read_line(path + "/name"); name = read_line(path + "/name");
#ifndef NDEBUG spdlog::debug("hwmon: sensor name: {}", name);
std::cerr << "hwmon: sensor name: " << name << std::endl;
#endif
if (name == "coretemp") { if (name == "coretemp") {
find_temp_input(path, input, "Package id 0"); find_temp_input(path, input, "Package id 0");
break; break;
@ -437,12 +434,11 @@ bool CPUStats::GetCpuFile() {
} }
if (path.empty() || (!file_exists(input) && !find_fallback_temp_input(path, input))) { 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; return false;
} else { } else {
#ifndef NDEBUG
std::cerr << "hwmon: using input: " << input << std::endl; spdlog::debug("hwmon: using input: {}", input);
#endif
m_cpuTempFile = fopen(input.c_str(), "r"); m_cpuTempFile = fopen(input.c_str(), "r");
} }
return true; 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, "in", socVoltageInput, "Vsoc")) return nullptr;
if(!find_input(path, "curr", socCurrentInput, "Isoc")) return nullptr; if(!find_input(path, "curr", socCurrentInput, "Isoc")) return nullptr;
#ifndef NDEBUG spdlog::debug("hwmon: using input: {}", coreVoltageInput);
std::cerr << "hwmon: using input: " << coreVoltageInput << std::endl; spdlog::debug("hwmon: using input: {}", coreCurrentInput);
std::cerr << "hwmon: using input: " << coreCurrentInput << std::endl; spdlog::debug("hwmon: using input: {}", socVoltageInput);
std::cerr << "hwmon: using input: " << socVoltageInput << std::endl; spdlog::debug("hwmon: using input: {}", socCurrentInput);
std::cerr << "hwmon: using input: " << socCurrentInput << std::endl;
#endif
powerData->coreVoltageFile = fopen(coreVoltageInput.c_str(), "r"); powerData->coreVoltageFile = fopen(coreVoltageInput.c_str(), "r");
powerData->coreCurrentFile = fopen(coreCurrentInput.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", corePowerInput, "SVI2_P_Core")) return nullptr;
if(!find_input(path, "power", socPowerInput, "SVI2_P_SoC")) return nullptr; if(!find_input(path, "power", socPowerInput, "SVI2_P_SoC")) return nullptr;
#ifndef NDEBUG spdlog::debug("hwmon: using input: {}", corePowerInput);
std::cerr << "hwmon: using input: " << corePowerInput << std::endl; spdlog::debug("hwmon: using input: {}", socPowerInput);
std::cerr << "hwmon: using input: " << socPowerInput << std::endl;
#endif
powerData->corePowerFile = fopen(corePowerInput.c_str(), "r"); powerData->corePowerFile = fopen(corePowerInput.c_str(), "r");
powerData->socPowerFile = fopen(socPowerInput.c_str(), "r"); powerData->socPowerFile = fopen(socPowerInput.c_str(), "r");
@ -538,9 +530,8 @@ bool CPUStats::InitCpuPowerData() {
for (auto& dir : dirs) { for (auto& dir : dirs) {
path = hwmon + dir; path = hwmon + dir;
name = read_line(path + "/name"); name = read_line(path + "/name");
#ifndef NDEBUG spdlog::debug("hwmon: sensor name: {}", name);
std::cerr << "hwmon: sensor name: " << name << std::endl;
#endif
if (name == "k10temp") { if (name == "k10temp") {
cpuPowerData = (CPUPowerData*)init_cpu_power_data_k10temp(path); cpuPowerData = (CPUPowerData*)init_cpu_power_data_k10temp(path);
break; break;
@ -556,9 +547,7 @@ bool CPUStats::InitCpuPowerData() {
for (auto& dir : powercap_dirs) { for (auto& dir : powercap_dirs) {
path = powercap + dir; path = powercap + dir;
name = read_line(path + "/name"); name = read_line(path + "/name");
#ifndef NDEBUG spdlog::debug("powercap: name: {}", name);
std::cerr << "powercap: name: " << name << std::endl;
#endif
if (name == "package-0") { if (name == "package-0") {
cpuPowerData = (CPUPowerData*)init_cpu_power_data_rapl(path); cpuPowerData = (CPUPowerData*)init_cpu_power_data_rapl(path);
break; break;
@ -567,7 +556,7 @@ bool CPUStats::InitCpuPowerData() {
} }
if(cpuPowerData == nullptr) { if(cpuPowerData == nullptr) {
std::cerr << "MANGOHUD: Failed to initialize CPU power data" << std::endl; spdlog::error("Failed to initialize CPU power data");
return false; return false;
} }

@ -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")) { 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; return false;
} }
@ -173,14 +173,13 @@ bool dbus_manager::init(const std::string& requested_player) {
if (nullptr == if (nullptr ==
(m_dbus_conn = m_dbus_ldr.bus_get(DBUS_BUS_SESSION, &m_error))) { (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); m_dbus_ldr.error_free(&m_error);
return false; return false;
} }
std::cout << "MANGOHUD: Connected to D-Bus as \"" spdlog::debug("Connected to D-Bus as \"{}\"",
<< m_dbus_ldr.bus_get_unique_name(m_dbus_conn) << "\"." m_dbus_ldr.bus_get_unique_name(m_dbus_conn));
<< std::endl;
dbus_list_name_to_owner(); dbus_list_name_to_owner();
connect_to_signals(); connect_to_signals();
@ -198,10 +197,7 @@ bool dbus_manager::select_active_player() {
// If the requested player is available, use it // If the requested player is available, use it
if (m_name_owners.count(m_requested_player) > 0) { if (m_name_owners.count(m_requested_player) > 0) {
m_active_player = m_requested_player; m_active_player = m_requested_player;
#ifndef NDEBUG spdlog::debug("Selecting requested player: {}", m_requested_player);
std::cerr << "Selecting requested player: " << m_requested_player
<< "\n";
#endif
get_media_player_metadata(meta, m_active_player); get_media_player_metadata(meta, m_active_player);
} }
} else { } else {
@ -221,9 +217,7 @@ bool dbus_manager::select_active_player() {
if(it != m_name_owners.end()){ if(it != m_name_owners.end()){
m_active_player = it->first; m_active_player = it->first;
#ifndef NDEBUG spdlog::debug("Selecting fallback player: {}", m_active_player);
std::cerr << "Selecting fallback player: " << m_active_player << "\n";
#endif
} }
} }
} }
@ -232,9 +226,7 @@ bool dbus_manager::select_active_player() {
onNewPlayer(meta); onNewPlayer(meta);
return true; return true;
} else { } else {
#ifndef NDEBUG spdlog::debug("No active players");
std::cerr << "No active players\n";
#endif
if (!old_active_player.empty()) { if (!old_active_player.empty()) {
onNoPlayer(); onNoPlayer();
} }
@ -333,8 +325,7 @@ void dbus_manager::connect_to_signals() {
auto signal = format_signal(kv); auto signal = format_signal(kv);
m_dbus_ldr.bus_add_match(m_dbus_conn, signal.c_str(), &m_error); m_dbus_ldr.bus_add_match(m_dbus_conn, signal.c_str(), &m_error);
if (m_dbus_ldr.error_is_set(&m_error)) { if (m_dbus_ldr.error_is_set(&m_error)) {
::perror(m_error.name); spdlog::error("{}: {}", m_error.name, m_error.message);
::perror(m_error.message);
m_dbus_ldr.error_free(&m_error); m_dbus_ldr.error_free(&m_error);
// return; // return;
} }
@ -352,8 +343,7 @@ void dbus_manager::disconnect_from_signals() {
auto signal = format_signal(kv); auto signal = format_signal(kv);
m_dbus_ldr.bus_remove_match(m_dbus_conn, signal.c_str(), &m_error); m_dbus_ldr.bus_remove_match(m_dbus_conn, signal.c_str(), &m_error);
if (m_dbus_ldr.error_is_set(&m_error)) { if (m_dbus_ldr.error_is_set(&m_error)) {
::perror(m_error.name); spdlog::error("{}: {}", m_error.name, m_error.message);
::perror(m_error.message);
m_dbus_ldr.error_free(&m_error); m_dbus_ldr.error_free(&m_error);
} }
} }

@ -3,6 +3,7 @@
#define MANGOHUD_DBUS_HELPERS #define MANGOHUD_DBUS_HELPERS
#include <vector> #include <vector>
#include <spdlog/spdlog.h>
#include "loaders/loader_dbus.h" #include "loaders/loader_dbus.h"
@ -136,8 +137,8 @@ template <class T>
auto DBusMessageIter_wrap::get_primitive() -> T { auto DBusMessageIter_wrap::get_primitive() -> T {
auto requested_type = detail::dbus_type_identifier<T>; auto requested_type = detail::dbus_type_identifier<T>;
if (requested_type != type()) { if (requested_type != type()) {
std::cerr << "Type mismatch: '" << ((char)requested_type) << "' vs '" spdlog::error("Type mismatch: '{}' vs '{}'",
<< (char)type() << "'\n"; ((char)requested_type), (char)type());
#ifndef NDEBUG #ifndef NDEBUG
exit(-1); exit(-1);
#else #else
@ -190,13 +191,13 @@ auto DBusMessageIter_wrap::get_stringified() -> std::string {
if (is_unsigned()) return std::to_string(get_unsigned()); if (is_unsigned()) return std::to_string(get_unsigned());
if (is_signed()) return std::to_string(get_signed()); if (is_signed()) return std::to_string(get_signed());
if (is_double()) return std::to_string(get_primitive<double>()); if (is_double()) return std::to_string(get_primitive<double>());
std::cerr << "stringify failed\n"; spdlog::error("stringify failed");
return std::string(); return std::string();
} }
auto DBusMessageIter_wrap::get_array_iter() -> DBusMessageIter_wrap { auto DBusMessageIter_wrap::get_array_iter() -> DBusMessageIter_wrap {
if (!is_array()) { if (!is_array()) {
std::cerr << "Not an array; " << (char)type() << "\n"; spdlog::error("Not an array; {}", (char)type());
return DBusMessageIter_wrap(DBusMessageIter{}, m_DBus); 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 { auto DBusMessageIter_wrap::get_dict_entry_iter() -> DBusMessageIter_wrap {
if (type() != DBUS_TYPE_DICT_ENTRY) { 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); 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, auto reply = m_DBus->connection_send_with_reply_and_block(conn, m_msg,
timeout, &err); timeout, &err);
if (reply == nullptr) { if (reply == nullptr) {
std::cerr << "MangoHud[" << __func__ << "]: " << err.message << "\n"; spdlog::error("[{}]: {}", __func__, err.message);
free_if_owning(); free_if_owning();
m_DBus->error_free(&err); m_DBus->error_free(&err);
} }

@ -8,6 +8,7 @@
#include <fstream> #include <fstream>
#include <cstring> #include <cstring>
#include <string> #include <string>
#include <spdlog/spdlog.h>
std::string read_line(const std::string& filename) 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; struct dirent* dp;
DIR* dirp = opendir(root); DIR* dirp = opendir(root);
if (!dirp) { if (!dirp) {
std::cerr << "Error opening directory '" << root << "': "; spdlog::error("Error opening directory '{}': {}", root, strerror(errno));
perror("");
return false; return false;
} }
@ -52,8 +52,7 @@ std::vector<std::string> ls(const char* root, const char* prefix, LS_FLAGS flags
DIR* dirp = opendir(root); DIR* dirp = opendir(root);
if (!dirp) { if (!dirp) {
std::cerr << "Error opening directory '" << root << "': "; spdlog::error("Error opening directory '{}': {}", root, strerror(errno));
perror("");
return list; return list;
} }

@ -168,10 +168,6 @@ void imgui_create(void *ctx)
void imgui_shutdown() void imgui_shutdown()
{ {
#ifndef NDEBUG
std::cerr << __func__ << std::endl;
#endif
if (state.imgui_ctx) { if (state.imgui_ctx) {
ImGui::SetCurrentContext(state.imgui_ctx); ImGui::SetCurrentContext(state.imgui_ctx);
ImGui_ImplOpenGL3_Shutdown(); ImGui_ImplOpenGL3_Shutdown();
@ -185,10 +181,6 @@ void imgui_set_context(void *ctx)
{ {
if (!ctx) if (!ctx)
return; return;
#ifndef NDEBUG
std::cerr << __func__ << ": " << ctx << std::endl;
#endif
imgui_create(ctx); imgui_create(ctx);
} }

@ -70,6 +70,7 @@
#include <stdint.h> // intptr_t #include <stdint.h> // intptr_t
#include <sstream> #include <sstream>
#include <spdlog/spdlog.h>
#include <glad/glad.h> #include <glad/glad.h>
#include "overlay.h" #include "overlay.h"
@ -138,13 +139,13 @@ static bool CheckShader(GLuint handle, const char* desc)
glGetShaderiv(handle, GL_COMPILE_STATUS, &status); glGetShaderiv(handle, GL_COMPILE_STATUS, &status);
glGetShaderiv(handle, GL_INFO_LOG_LENGTH, &log_length); glGetShaderiv(handle, GL_INFO_LOG_LENGTH, &log_length);
if ((GLboolean)status == GL_FALSE) 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) if (log_length > 1)
{ {
ImVector<char> buf; ImVector<char> buf;
buf.resize((int)(log_length + 1)); buf.resize((int)(log_length + 1));
glGetShaderInfoLog(handle, log_length, NULL, (GLchar*)buf.begin()); glGetShaderInfoLog(handle, log_length, NULL, (GLchar*)buf.begin());
fprintf(stderr, "%s\n", buf.begin()); spdlog::error("{}", buf.begin());
} }
return (GLboolean)status == GL_TRUE; 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_LINK_STATUS, &status);
glGetProgramiv(handle, GL_INFO_LOG_LENGTH, &log_length); glGetProgramiv(handle, GL_INFO_LOG_LENGTH, &log_length);
if ((GLboolean)status == GL_FALSE) 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) if (log_length > 1)
{ {
ImVector<char> buf; ImVector<char> buf;
buf.resize((int)(log_length + 1)); buf.resize((int)(log_length + 1));
glGetProgramInfoLog(handle, log_length, NULL, (GLchar*)buf.begin()); glGetProgramInfoLog(handle, log_length, NULL, (GLchar*)buf.begin());
fprintf(stderr, "%s\n", buf.begin()); spdlog::error("{}", buf.begin());
} }
return (GLboolean)status == GL_TRUE; return (GLboolean)status == GL_TRUE;
} }
@ -478,16 +479,12 @@ void ImGui_ImplOpenGL3_NewFrame()
if (!g_ShaderHandle) if (!g_ShaderHandle)
ImGui_ImplOpenGL3_CreateDeviceObjects(); ImGui_ImplOpenGL3_CreateDeviceObjects();
else if (!glIsProgram(g_ShaderHandle)) { // TODO Got created in a now dead context? else if (!glIsProgram(g_ShaderHandle)) { // TODO Got created in a now dead context?
#ifndef NDEBUG spdlog::debug("Recreating lost objects");
fprintf(stderr, "MANGOHUD: recreating lost objects\n");
#endif
ImGui_ImplOpenGL3_CreateDeviceObjects(); ImGui_ImplOpenGL3_CreateDeviceObjects();
} }
if (!glIsTexture(g_FontTexture)) { if (!glIsTexture(g_FontTexture)) {
#ifndef NDEBUG spdlog::debug("GL Texture lost? Regenerating.");
fprintf(stderr, "MANGOHUD: GL Texture lost? Regenerating.\n");
#endif
g_FontTexture = 0; g_FontTexture = 0;
ImGui_ImplOpenGL3_CreateFontsTexture(); ImGui_ImplOpenGL3_CreateFontsTexture();
} }

@ -2,14 +2,13 @@
#include <array> #include <array>
#include <cstring> #include <cstring>
#include <dlfcn.h> #include <dlfcn.h>
#include <chrono>
#include <iomanip>
#include <spdlog/spdlog.h>
#include "real_dlsym.h" #include "real_dlsym.h"
#include "mesa/util/macros.h" #include "mesa/util/macros.h"
#include "mesa/util/os_time.h" #include "mesa/util/os_time.h"
#include "blacklist.h" #include "blacklist.h"
#include <chrono>
#include <iomanip>
#include "imgui_hud.h" #include "imgui_hud.h"
using namespace MangoHud::GL; using namespace MangoHud::GL;
@ -23,7 +22,7 @@ void* get_egl_proc_address(const char* name) {
if (!pfn_eglGetProcAddress) { if (!pfn_eglGetProcAddress) {
void *handle = real_dlopen("libEGL.so.1", RTLD_LAZY|RTLD_LOCAL); void *handle = real_dlopen("libEGL.so.1", RTLD_LAZY|RTLD_LOCAL);
if (!handle) { 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 { } else {
pfn_eglGetProcAddress = reinterpret_cast<decltype(pfn_eglGetProcAddress)>(real_dlsym(handle, "eglGetProcAddress")); pfn_eglGetProcAddress = reinterpret_cast<decltype(pfn_eglGetProcAddress)>(real_dlsym(handle, "eglGetProcAddress"));
} }
@ -36,7 +35,7 @@ void* get_egl_proc_address(const char* name) {
func = get_proc_address( name ); func = get_proc_address( name );
if (!func) { if (!func) {
std::cerr << "MANGOHUD: Failed to get function '" << name << "'" << std::endl; spdlog::debug("Failed to get function '{}'", name);
} }
return func; return func;
@ -44,10 +43,7 @@ void* get_egl_proc_address(const char* name) {
//EGLBoolean eglMakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx); //EGLBoolean eglMakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx);
EXPORT_C_(int) eglMakeCurrent_OFF(void *dpy, void *draw, void *read,void *ctx) { EXPORT_C_(int) eglMakeCurrent_OFF(void *dpy, void *draw, void *read,void *ctx) {
spdlog::trace("{}: draw: {}, ctx: {}", __func__, draw, ctx);
#ifndef NDEBUG
std::cerr << __func__ << ": " << draw << ", " << ctx << std::endl;
#endif
int ret = 0; int ret = 0;
return ret; return ret;
} }
@ -63,9 +59,6 @@ EXPORT_C_(unsigned int) eglSwapBuffers( void* dpy, void* surf)
if (!pfn_eglQuerySurface) if (!pfn_eglQuerySurface)
pfn_eglQuerySurface = reinterpret_cast<decltype(pfn_eglQuerySurface)>(get_egl_proc_address("eglQuerySurface")); pfn_eglQuerySurface = reinterpret_cast<decltype(pfn_eglQuerySurface)>(get_egl_proc_address("eglQuerySurface"));
//std::cerr << __func__ << "\n";
imgui_create(surf); imgui_create(surf);
int width=0, height=0; int width=0, height=0;
@ -73,7 +66,6 @@ EXPORT_C_(unsigned int) eglSwapBuffers( void* dpy, void* surf)
pfn_eglQuerySurface(dpy, surf, 0x3057, &width)) pfn_eglQuerySurface(dpy, surf, 0x3057, &width))
imgui_render(width, height); imgui_render(width, height);
//std::cerr << "\t" << width << " x " << height << "\n";
using namespace std::chrono_literals; using namespace std::chrono_literals;
if (fps_limit_stats.targetFrameTime > 0s){ if (fps_limit_stats.targetFrameTime > 0s){
fps_limit_stats.frameStart = Clock::now(); 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) { EXPORT_C_(void *) eglGetProcAddress(const char* procName) {
//std::cerr << __func__ << ": " << procName << std::endl;
void* real_func = get_egl_proc_address(procName); void* real_func = get_egl_proc_address(procName);
void* func = mangohud_find_egl_ptr(procName); void* func = mangohud_find_egl_ptr(procName);
spdlog::trace("{}: proc: {}, real: {}, fun: {}", __func__, procName, real_func, func);
if (func && real_func) if (func && real_func)
return func; return func;

@ -6,6 +6,7 @@
#include <algorithm> #include <algorithm>
#include <atomic> #include <atomic>
#include <cstring> #include <cstring>
#include <spdlog/spdlog.h>
#include "real_dlsym.h" #include "real_dlsym.h"
#include "loaders/loader_glx.h" #include "loaders/loader_glx.h"
#include "loaders/loader_x11.h" #include "loaders/loader_x11.h"
@ -47,7 +48,7 @@ void* get_glx_proc_address(const char* name) {
func = get_proc_address( name ); func = get_proc_address( name );
if (!func) { if (!func) {
std::cerr << "MANGOHUD: Failed to get function '" << name << "'" << std::endl; spdlog::error("Failed to get function '{}'", name);
} }
return func; 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); void *ctx = glx.CreateContext(dpy, vis, shareList, direct);
if (ctx) if (ctx)
refcnt++; refcnt++;
#ifndef NDEBUG spdlog::debug("{}: {}", __func__, ctx);
std::cerr << __func__ << ":" << ctx << std::endl;
#endif
return 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); void *ctx = glx.CreateContextAttribs(dpy, config, share_context, direct, attrib_list);
if (ctx) if (ctx)
refcnt++; refcnt++;
#ifndef NDEBUG spdlog::debug("{}: {}", __func__, ctx);
std::cerr << __func__ << ":" << ctx << std::endl;
#endif
return 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); void *ctx = glx.CreateContextAttribsARB(dpy, config, share_context, direct, attrib_list);
if (ctx) if (ctx)
refcnt++; refcnt++;
#ifndef NDEBUG spdlog::debug("{}: {}", __func__, ctx);
std::cerr << __func__ << ":" << ctx << std::endl;
#endif
return ctx; return ctx;
} }
@ -96,25 +91,18 @@ EXPORT_C_(void) glXDestroyContext(void *dpy, void *ctx)
refcnt--; refcnt--;
if (refcnt <= 0) if (refcnt <= 0)
imgui_shutdown(); imgui_shutdown();
#ifndef NDEBUG spdlog::debug("{}: {}", __func__, ctx);
std::cerr << __func__ << ":" << ctx << std::endl;
#endif
} }
EXPORT_C_(int) glXMakeCurrent(void* dpy, void* drawable, void* ctx) { EXPORT_C_(int) glXMakeCurrent(void* dpy, void* drawable, void* ctx) {
glx.Load(); glx.Load();
#ifndef NDEBUG spdlog::debug("{}: {}, {}", __func__, drawable, ctx);
std::cerr << __func__ << ": " << drawable << ", " << ctx << std::endl;
#endif
int ret = glx.MakeCurrent(dpy, drawable, ctx); int ret = glx.MakeCurrent(dpy, drawable, ctx);
if (!is_blacklisted()) { if (!is_blacklisted()) {
if (ret) { if (ret) {
imgui_set_context(ctx); imgui_set_context(ctx);
#ifndef NDEBUG spdlog::debug("GL ref count: {}", refcnt);
std::cerr << "MANGOHUD: GL ref count: " << refcnt << "\n";
#endif
} }
// Afaik -1 only works with EXT version if it has GLX_EXT_swap_control_tear, maybe EGL_MESA_swap_control_tear someday // 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; break;
} }
spdlog::trace("swap buffers: {}x{}", width, height);
imgui_render(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) { EXPORT_C_(void) glXSwapIntervalEXT(void *dpy, void *draw, int interval) {
#ifndef NDEBUG spdlog::debug("{}: {}", __func__, interval);
std::cerr << __func__ << ": " << interval << std::endl;
#endif
glx.Load(); glx.Load();
if (!glx.SwapIntervalEXT) if (!glx.SwapIntervalEXT)
return; return;
@ -210,9 +197,7 @@ EXPORT_C_(void) glXSwapIntervalEXT(void *dpy, void *draw, int interval) {
} }
EXPORT_C_(int) glXSwapIntervalSGI(int interval) { EXPORT_C_(int) glXSwapIntervalSGI(int interval) {
#ifndef NDEBUG spdlog::debug("{}: {}", __func__, interval);
std::cerr << __func__ << ": " << interval << std::endl;
#endif
glx.Load(); glx.Load();
if (!glx.SwapIntervalSGI) if (!glx.SwapIntervalSGI)
return -1; return -1;
@ -224,9 +209,7 @@ EXPORT_C_(int) glXSwapIntervalSGI(int interval) {
} }
EXPORT_C_(int) glXSwapIntervalMESA(unsigned int interval) { EXPORT_C_(int) glXSwapIntervalMESA(unsigned int interval) {
#ifndef NDEBUG spdlog::debug("{}: {}", __func__, interval);
std::cerr << __func__ << ": " << interval << std::endl;
#endif
glx.Load(); glx.Load();
if (!glx.SwapIntervalMESA) if (!glx.SwapIntervalMESA)
return -1; return -1;
@ -256,9 +239,7 @@ EXPORT_C_(int) glXGetSwapIntervalMESA() {
} }
} }
#ifndef NDEBUG spdlog::debug("{}: {}", __func__, interval);
std::cerr << __func__ << ": " << interval << std::endl;
#endif
return 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) { 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 *real_func = get_glx_proc_address((const char*)procName);
void *func = mangohud_find_glx_ptr( (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) if (func && real_func)
return func; return func;
@ -311,10 +292,9 @@ EXPORT_C_(void *) glXGetProcAddress(const unsigned char* procName) {
} }
EXPORT_C_(void *) glXGetProcAddressARB(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 *real_func = get_glx_proc_address((const char*)procName);
void *func = mangohud_find_glx_ptr( (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) if (func && real_func)
return func; return func;

@ -4,6 +4,7 @@
#include <functional> #include <functional>
#include <thread> #include <thread>
#include <cstring> #include <cstring>
#include <spdlog/spdlog.h>
#include "nvctrl.h" #include "nvctrl.h"
#include "timing.hpp" #include "timing.hpp"
#ifdef HAVE_NVML #ifdef HAVE_NVML
@ -229,20 +230,20 @@ bool amdgpu_open(const char *path) {
int fd = open(path, O_RDWR | O_CLOEXEC); int fd = open(path, O_RDWR | O_CLOEXEC);
if (fd < 0) { 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; return false;
} }
drmVersionPtr ver = libdrm_ptr->drmGetVersion(fd); drmVersionPtr ver = libdrm_ptr->drmGetVersion(fd);
if (!ver) { if (!ver) {
perror("MANGOHUD: Failed to query driver version: "); spdlog::error("Failed to query driver version: {}", strerror(errno));
close(fd); close(fd);
return false; return false;
} }
if (strcmp(ver->name, "amdgpu") || !DRM_ATLEAST_VERSION(ver, 3, 11)) { 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); close(fd);
libdrm_ptr->drmFreeVersion(ver); libdrm_ptr->drmFreeVersion(ver);
return false; return false;
@ -259,7 +260,7 @@ bool amdgpu_open(const char *path) {
uint32_t drm_major, drm_minor; uint32_t drm_major, drm_minor;
amdgpu_device_handle dev; amdgpu_device_handle dev;
if (libdrm_ptr->amdgpu_device_initialize(fd, &drm_major, &drm_minor, &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); close(fd);
return false; return false;
} }

@ -1,6 +1,7 @@
#include "loaders/loader_dbus.h" #include "loaders/loader_dbus.h"
#include <iostream> #include <iostream>
#include <spdlog/spdlog.h>
// Put these sanity checks here so that they fire at most once // Put these sanity checks here so that they fire at most once
// (to avoid cluttering the build output). // (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) #if defined(LIBRARY_LOADER_DBUS_H_DLOPEN)
library_ = dlopen(library_name.c_str(), RTLD_LAZY); library_ = dlopen(library_name.c_str(), RTLD_LAZY);
if (!library_) { 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; return false;
} }

@ -1,4 +1,5 @@
#include <iostream> #include <iostream>
#include <spdlog/spdlog.h>
#include "real_dlsym.h" #include "real_dlsym.h"
#include "loaders/loader_glx.h" #include "loaders/loader_glx.h"
@ -24,7 +25,7 @@ bool glx_loader::Load() {
if (!handle) if (!handle)
handle = real_dlopen("libGL.so.1", RTLD_LAZY); handle = real_dlopen("libGL.so.1", RTLD_LAZY);
if (!handle) { 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; return false;
} }

@ -1,6 +1,7 @@
#include "loaders/loader_libdrm.h" #include "loaders/loader_libdrm.h"
#include <iostream> #include <iostream>
#include <spdlog/spdlog.h>
// Put these sanity checks here so that they fire at most once // Put these sanity checks here so that they fire at most once
// (to avoid cluttering the build output). // (to avoid cluttering the build output).
@ -27,13 +28,13 @@ bool libdrm_loader::Load() {
#if defined(LIBRARY_LOADER_LIBDRM_H_DLOPEN) #if defined(LIBRARY_LOADER_LIBDRM_H_DLOPEN)
library_drm = dlopen("libdrm.so.2", RTLD_LAZY); library_drm = dlopen("libdrm.so.2", RTLD_LAZY);
if (!library_drm) { 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; return false;
} }
library_amdgpu = dlopen("libdrm_amdgpu.so.1", RTLD_LAZY); library_amdgpu = dlopen("libdrm_amdgpu.so.1", RTLD_LAZY);
if (!library_amdgpu) { 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); CleanUp(true);
return false; return false;
} }

@ -1,6 +1,7 @@
#include "loader_nvctrl.h" #include "loader_nvctrl.h"
#include <iostream> #include <iostream>
#include <memory> #include <memory>
#include <spdlog/spdlog.h>
// Put these sanity checks here so that they fire at most once // Put these sanity checks here so that they fire at most once
// (to avoid cluttering the build output). // (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) #if defined(LIBRARY_LOADER_NVCTRL_H_DLOPEN)
library_ = dlopen(library_name.c_str(), RTLD_LAZY); library_ = dlopen(library_name.c_str(), RTLD_LAZY);
if (!library_) { 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; return false;
} }

@ -4,6 +4,7 @@
#include "loader_nvml.h" #include "loader_nvml.h"
#include <iostream> #include <iostream>
#include <memory> #include <memory>
#include <spdlog/spdlog.h>
// Put these sanity checks here so that they fire at most once // Put these sanity checks here so that they fire at most once
// (to avoid cluttering the build output). // (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) #if defined(LIBRARY_LOADER_NVML_H_DLOPEN)
library_ = dlopen(library_name.c_str(), RTLD_LAZY); library_ = dlopen(library_name.c_str(), RTLD_LAZY);
if (!library_) { 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; return false;
} }
#endif #endif

@ -1,5 +1,6 @@
#include "loader_x11.h" #include "loader_x11.h"
#include <iostream> #include <iostream>
#include <spdlog/spdlog.h>
libx11_loader::libx11_loader() : loaded_(false) { 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); library_ = dlopen(library_name.c_str(), RTLD_LAZY);
if (!library_) { 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; return false;
} }

@ -1,5 +1,6 @@
#include <sstream> #include <sstream>
#include <iomanip> #include <iomanip>
#include <spdlog/spdlog.h>
#include "logging.h" #include "logging.h"
#include "overlay.h" #include "overlay.h"
#include "config.h" #include "config.h"
@ -58,9 +59,7 @@ void upload_files(const std::vector<std::string>& logFiles){
void writeFile(string filename){ void writeFile(string filename){
auto& logArray = logger->get_log_data(); auto& logArray = logger->get_log_data();
#ifndef NDEBUG spdlog::debug("Writing log file [{}], {} entries", filename, logArray.size());
std::cerr << "Writing log file [" << filename << "], " << logArray.size() << " entries\n";
#endif
std::ofstream out(filename, ios::out | ios::app); std::ofstream out(filename, ios::out | ios::app);
if (out){ if (out){
out << "os," << "cpu," << "gpu," << "ram," << "kernel," << "driver," << "cpuscheduler" << endl; out << "os," << "cpu," << "gpu," << "ram," << "kernel," << "driver," << "cpuscheduler" << endl;
@ -110,9 +109,7 @@ Logger::Logger(overlay_params* in_params)
m_values_valid(false), m_values_valid(false),
m_params(in_params) m_params(in_params)
{ {
#ifndef NDEBUG spdlog::debug("Logger constructed!");
std::cerr << "Logger constructed!\n";
#endif
} }
void Logger::start_logging() { void Logger::start_logging() {

@ -186,6 +186,7 @@ vklayer_mesa_overlay = shared_library(
dependencies : [ dependencies : [
vulkan_wsi_deps, vulkan_wsi_deps,
dearimgui_dep, dearimgui_dep,
spdlog_dep,
dep_libdrm, dep_libdrm,
#dep_libdrm_amdgpu, #dep_libdrm_amdgpu,
dbus_dep, dbus_dep,

@ -3,6 +3,7 @@
#include <fcntl.h> #include <fcntl.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/inotify.h> #include <sys/inotify.h>
#include <spdlog/spdlog.h>
#include "config.h" #include "config.h"
#include "notify.h" #include "notify.h"
@ -27,9 +28,7 @@ static void fileChanged(void *params_void) {
std::this_thread::sleep_for(std::chrono::milliseconds(100)); std::this_thread::sleep_for(std::chrono::milliseconds(100));
parse_overlay_config(&local_params, getenv("MANGOHUD_CONFIG")); parse_overlay_config(&local_params, getenv("MANGOHUD_CONFIG"));
if ((event->mask & IN_DELETE_SELF) || (nt->params->config_file_path != local_params.config_file_path)) { if ((event->mask & IN_DELETE_SELF) || (nt->params->config_file_path != local_params.config_file_path)) {
#ifndef NDEBUG spdlog::debug("Watching config file: {}", local_params.config_file_path.c_str());
fprintf(stderr, "MANGOHUD: watching config file: %s\n", local_params.config_file_path.c_str());
#endif
inotify_rm_watch(nt->fd, nt->wd); 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); 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); nt.fd = inotify_init1(IN_NONBLOCK);
if (nt.fd < 0) { if (nt.fd < 0) {
perror("MANGOHUD: inotify_init1"); spdlog::error("inotify_init1 failed: {}", strerror(errno));
return false; return false;
} }

@ -4,6 +4,7 @@
#include <unordered_map> #include <unordered_map>
#include <memory> #include <memory>
#include <functional> #include <functional>
#include <spdlog/spdlog.h>
#include "nvctrl.h" #include "nvctrl.h"
#include "loaders/loader_nvctrl.h" #include "loaders/loader_nvctrl.h"
#include "loaders/loader_x11.h" #include "loaders/loader_x11.h"
@ -25,7 +26,7 @@ static bool find_nv_x11(libnvctrl_loader& nvctrl, Display*& dpy)
if (d) { if (d) {
if (nvctrl.XNVCTRLIsNvScreen(d, 0)) { if (nvctrl.XNVCTRLIsNvScreen(d, 0)) {
dpy = d; dpy = d;
std::cerr << "MANGOHUD: XNVCtrl is using display " << buf << std::endl; spdlog::debug("XNVCtrl is using display {}", buf);
return true; return true;
} }
g_x11->XCloseDisplay(d); g_x11->XCloseDisplay(d);
@ -36,14 +37,12 @@ static bool find_nv_x11(libnvctrl_loader& nvctrl, Display*& dpy)
bool checkXNVCtrl() bool checkXNVCtrl()
{ {
if (!g_x11->IsLoaded()) { if (!g_x11->IsLoaded())
std::cerr << "MANGOHUD: XNVCtrl: X11 loader failed to load\n";
return false; return false;
}
auto& nvctrl = get_libnvctrl_loader(); auto& nvctrl = get_libnvctrl_loader();
if (!nvctrl.IsLoaded()) { if (!nvctrl.IsLoaded()) {
std::cerr << "MANGOHUD: XNVCtrl loader failed to load\n"; spdlog::error("XNVCtrl loader failed to load");
return false; return false;
} }
@ -51,7 +50,7 @@ bool checkXNVCtrl()
nvctrlSuccess = find_nv_x11(nvctrl, dpy); nvctrlSuccess = find_nv_x11(nvctrl, dpy);
if (!nvctrlSuccess) { 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; return false;
} }
@ -86,7 +85,6 @@ static void parse_token(std::string token, string_map& options) {
param = token.substr(0, equal); param = token.substr(0, equal);
trim(param); trim(param);
trim(value); trim(value);
//std::cerr << __func__ << ": " << param << "=" << value << std::endl;
if (!param.empty()) if (!param.empty())
options[param] = value; 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* get_attr_target_string(libnvctrl_loader& nvctrl, int attr, int target_type, int target_id) {
char* c = nullptr; char* c = nullptr;
if (!nvctrl.XNVCTRLQueryTargetStringAttribute(display.get(), target_type, target_id, 0, attr, &c)) { 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; return c;
} }

@ -1,3 +1,4 @@
#include <spdlog/spdlog.h>
#include "loaders/loader_nvml.h" #include "loaders/loader_nvml.h"
#include "nvidia_info.h" #include "nvidia_info.h"
#include <iostream> #include <iostream>
@ -16,30 +17,30 @@ bool checkNVML(const char* pciBusId){
if (nvml.IsLoaded()){ if (nvml.IsLoaded()){
result = nvml.nvmlInit(); result = nvml.nvmlInit();
if (NVML_SUCCESS != result) { if (NVML_SUCCESS != result) {
std::cerr << "MANGOHUD: Nvidia module not loaded\n"; spdlog::error("Nvidia module not loaded");
} else { } else {
nvmlReturn_t ret = NVML_ERROR_UNKNOWN; nvmlReturn_t ret = NVML_ERROR_UNKNOWN;
if (pciBusId && ((ret = nvml.nvmlDeviceGetHandleByPciBusId(pciBusId, &nvidiaDevice)) != NVML_SUCCESS)) { if (pciBusId && ((ret = nvml.nvmlDeviceGetHandleByPciBusId(pciBusId, &nvidiaDevice)) != NVML_SUCCESS)) {
std::cerr << "MANGOHUD: Getting device handle by PCI bus ID failed: " << nvml.nvmlErrorString(ret) << "\n"; spdlog::error("Getting device handle by PCI bus ID failed: {}", nvml.nvmlErrorString(ret));
std::cerr << " Using index 0.\n"; spdlog::error("Using index 0.");
} }
if (ret != NVML_SUCCESS) if (ret != NVML_SUCCESS)
ret = nvml.nvmlDeviceGetHandleByIndex(0, &nvidiaDevice); ret = nvml.nvmlDeviceGetHandleByIndex(0, &nvidiaDevice);
if (ret != NVML_SUCCESS) 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); nvmlSuccess = (ret == NVML_SUCCESS);
if (ret == NVML_SUCCESS) if (ret == NVML_SUCCESS)
nvml.nvmlDeviceGetPciInfo_v3(nvidiaDevice, &nvidiaPciInfo); nvml.nvmlDeviceGetPciInfo_v3(nvidiaDevice, &nvidiaPciInfo);
return nvmlSuccess; return nvmlSuccess;
} }
} else { } else {
std::cerr << "MANGOHUD: Failed to load NVML\n"; spdlog::error("Failed to load NVML");
} }
return false; return false;
} }

@ -1,6 +1,7 @@
#include <sstream> #include <sstream>
#include <iomanip> #include <iomanip>
#include <algorithm> #include <algorithm>
#include <spdlog/spdlog.h>
#include "overlay.h" #include "overlay.h"
#include "logging.h" #include "logging.h"
#include "cpu.h" #include "cpu.h"
@ -517,12 +518,10 @@ void init_gpu_stats(uint32_t& vendorID, overlay_params& params)
<< std::setw(1) << pci.func; << std::setw(1) << pci.func;
params.pci_dev = ss.str(); params.pci_dev = ss.str();
pci_dev = params.pci_dev.c_str(); pci_dev = params.pci_dev.c_str();
#ifndef NDEBUG spdlog::debug("PCI device ID: '{}'", pci_dev);
std::cerr << "MANGOHUD: PCI device ID: '" << pci_dev << "'\n";
#endif
} else { } else {
std::cerr << "MANGOHUD: Failed to parse PCI device ID: '" << pci_dev << "'\n"; spdlog::error("Failed to parse PCI device ID: '{}'", pci_dev);
std::cerr << "MANGOHUD: Specify it as 'domain:bus:slot.func'\n"; 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) { for (auto& dir : dirs) {
path = drm + dir; path = drm + dir;
#ifndef NDEBUG spdlog::debug("amdgpu path check: {}/device/vendor", path);
std::cerr << "amdgpu path check: " << path << "/device/vendor" << std::endl;
#endif
string device = read_line(path + "/device/device"); string device = read_line(path + "/device/device");
deviceID = strtol(device.c_str(), NULL, 16); deviceID = strtol(device.c_str(), NULL, 16);
string line = read_line(path + "/device/vendor"); 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) { if (pci_bus_parsed && pci_dev) {
string pci_device = read_symlink((path + "/device").c_str()); string pci_device = read_symlink((path + "/device").c_str());
#ifndef NDEBUG spdlog::debug("PCI device symlink: '{}'", pci_device);
std::cerr << "PCI device symlink: " << pci_device << "\n";
#endif
if (!ends_with(pci_device, pci_dev)) { 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; continue;
} }
} }
#ifndef NDEBUG spdlog::debug("using amdgpu path: {}", path);
std::cerr << "using amdgpu path: " << path << std::endl;
#endif
#ifdef HAVE_LIBDRM_AMDGPU #ifdef HAVE_LIBDRM_AMDGPU
int idx = -1; int idx = -1;
@ -585,12 +579,12 @@ void init_gpu_stats(uint32_t& vendorID, overlay_params& params)
using_libdrm = true; using_libdrm = true;
getAmdGpuInfo_actual = getAmdGpuInfo_libdrm; getAmdGpuInfo_actual = getAmdGpuInfo_libdrm;
amdgpu_set_sampling_period(params.fps_sampling_period); amdgpu_set_sampling_period(params.fps_sampling_period);
#ifndef NDEBUG
std::cerr << "MANGOHUD: using libdrm\n"; spdlog::debug("Using libdrm");
#endif
// fall through and open sysfs handles for fallback or check DRM version beforehand // fall through and open sysfs handles for fallback or check DRM version beforehand
} else if (!params.enabled[OVERLAY_PARAM_ENABLED_force_amdgpu_hwmon]) { } 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 #endif
@ -626,7 +620,7 @@ void init_gpu_stats(uint32_t& vendorID, overlay_params& params)
} }
#endif #endif
if (!params.permit_upload) 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(){ void init_system_info(){
@ -719,15 +713,14 @@ void init_system_info(){
if (ld_preload) if (ld_preload)
setenv("LD_PRELOAD", ld_preload, 1); setenv("LD_PRELOAD", ld_preload, 1);
#ifndef NDEBUG
std::cout << "Ram:" << ram << "\n" spdlog::debug("Ram:{}", ram);
<< "Cpu:" << cpu << "\n" spdlog::debug("Cpu:{}", cpu);
<< "Kernel:" << kernel << "\n" spdlog::debug("Kernel:{}", kernel);
<< "Os:" << os << "\n" spdlog::debug("Os:{}", os);
<< "Gpu:" << gpu << "\n" spdlog::debug("Gpu:{}", gpu);
<< "Driver:" << driver << "\n" spdlog::debug("Driver:{}", driver);
<< "CPU Scheduler:" << cpusched << std::endl; spdlog::debug("CPU Scheduler:{}", cpusched);
#endif
#endif #endif
} }

@ -16,6 +16,9 @@
#include <cctype> #include <cctype>
#include <array> #include <array>
#include <functional> #include <functional>
#include <spdlog/spdlog.h>
#include <spdlog/cfg/env.h>
#include <spdlog/sinks/stdout_color_sinks.h>
#include "overlay_params.h" #include "overlay_params.h"
#include "overlay.h" #include "overlay.h"
@ -92,8 +95,8 @@ parse_control(const char *str)
{ {
int ret = os_socket_listen_abstract(str, 1); int ret = os_socket_listen_abstract(str, 1);
if (ret < 0) { if (ret < 0) {
fprintf(stderr, "ERROR: Couldn't create socket pipe at '%s'\n", str); spdlog::error("Couldn't create socket pipe at '{}'\n", str);
fprintf(stderr, "ERROR: '%s'\n", strerror(errno)); spdlog::error("ERROR: '{}'", strerror(errno));
return ret; return ret;
} }
@ -126,7 +129,7 @@ parse_string_to_keysym_vec(const char *str)
if (xk) if (xk)
keys.push_back(xk); keys.push_back(xk);
else else
std::cerr << "MANGOHUD: Unrecognized key: '" << ks << "'\n"; spdlog::error("Unrecognized key: '{}'", ks);
} }
} }
return keys; return keys;
@ -167,7 +170,7 @@ parse_fps_limit(const char *str)
try { try {
as_int = static_cast<uint32_t>(std::stoul(value)); as_int = static_cast<uint32_t>(std::stoul(value));
} catch (const std::invalid_argument&) { } catch (const std::invalid_argument&) {
std::cerr << "MANGOHUD: invalid fps_limit value: '" << value << "'\n"; spdlog::error("invalid fps_limit value: '{}'", value);
continue; continue;
} }
@ -317,17 +320,17 @@ parse_benchmark_percentiles(const char *str)
try { try {
as_float = parse_float(value, &float_len); as_float = parse_float(value, &float_len);
} catch (const std::invalid_argument&) { } catch (const std::invalid_argument&) {
std::cerr << "MANGOHUD: invalid benchmark percentile: '" << value << "'\n"; spdlog::error("invalid benchmark percentile: '{}'", value);
continue; continue;
} }
if (float_len != value.length()) { if (float_len != value.length()) {
std::cerr << "MANGOHUD: invalid benchmark percentile: '" << value << "'\n"; spdlog::error("invalid benchmark percentile: '{}'", value);
continue; continue;
} }
if (as_float > 100 || as_float < 0) { 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; continue;
} }
@ -495,9 +498,8 @@ parse_string(const char *s, char *out_param, char *out_value)
} }
if (*s && !i) { if (*s && !i) {
fprintf(stderr, "MANGOHUD: syntax error: unexpected '%c' (%i) while " spdlog::error("syntax error: unexpected '{0:c}' ({0:d}) while "
"parsing a string\n", *s, *s); "parsing a string", *s);
fflush(stderr);
} }
return i; return i;
@ -547,7 +549,7 @@ parse_overlay_env(struct overlay_params *params,
OVERLAY_PARAMS OVERLAY_PARAMS
#undef OVERLAY_PARAM_BOOL #undef OVERLAY_PARAM_BOOL
#undef OVERLAY_PARAM_CUSTOM #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, parse_overlay_config(struct overlay_params *params,
const char *env) 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 = {}; *params = {};
@ -684,7 +689,7 @@ parse_overlay_config(struct overlay_params *params,
OVERLAY_PARAMS OVERLAY_PARAMS
#undef OVERLAY_PARAM_BOOL #undef OVERLAY_PARAM_BOOL
#undef OVERLAY_PARAM_CUSTOM #undef OVERLAY_PARAM_CUSTOM
fprintf(stderr, "Unknown option '%s'\n", it.first.c_str()); spdlog::error("Unknown option '{}'", it.first.c_str());
} }
} }

@ -1,9 +1,10 @@
#include "shared_x11.h"
#include "loaders/loader_x11.h"
#include <cstdlib> #include <cstdlib>
#include <iostream> #include <iostream>
#include <memory> #include <memory>
#include <functional> #include <functional>
#include <spdlog/spdlog.h>
#include "shared_x11.h"
#include "loaders/loader_x11.h"
static std::unique_ptr<Display, std::function<void(Display*)>> display; static std::unique_ptr<Display, std::function<void(Display*)>> display;
@ -16,7 +17,7 @@ bool init_x11() {
return true; return true;
if (!g_x11->IsLoaded()) { if (!g_x11->IsLoaded()) {
std::cerr << "MANGOHUD: X11 loader failed to load\n"; spdlog::error("X11 loader failed to load");
failed = true; failed = true;
return false; return false;
} }
@ -34,7 +35,7 @@ bool init_x11() {
failed = !display; failed = !display;
if (failed) if (failed)
std::cerr << "MANGOHUD: XOpenDisplay failed to open display '" << displayid << "'\n"; spdlog::error("XOpenDisplay failed to open display '{}'", displayid);
return !!display; return !!display;
} }

@ -34,6 +34,7 @@
#include <list> #include <list>
#include <array> #include <array>
#include <iomanip> #include <iomanip>
#include <spdlog/spdlog.h>
#include <vulkan/vulkan.h> #include <vulkan/vulkan.h>
#include <vulkan/vk_layer.h> #include <vulkan/vk_layer.h>
@ -207,7 +208,7 @@ static void unmap_object(uint64_t obj)
do { \ do { \
VkResult __result = (expr); \ VkResult __result = (expr); \
if (__result != VK_SUCCESS) { \ 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)); \ #expr, __LINE__, vk_Result_to_str(__result)); \
} \ } \
} while (0) } 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) 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; VkDescriptorSet desc_set = (VkDescriptorSet)io.Fonts->TexID;
create_fonts(instance_data->params, data->sw_stats.font1, data->sw_stats.font_text); create_fonts(instance_data->params, data->sw_stats.font1, data->sw_stats.font_text);
unsigned char* pixels; 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); 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); io.Fonts->SetTexID((ImTextureID)desc_set);
data->font_uploaded = false; data->font_uploaded = false;
data->sw_stats.font_params_hash = params.font_params_hash; data->sw_stats.font_params_hash = params.font_params_hash;
spdlog::debug("Default font tex size: {}x{}px", width, height);
#ifndef NDEBUG
std::cerr << "MANGOHUD: Default font tex size: " << width << "x" << height << "px (" << (width*height*1) << " bytes)" << "\n";
#endif
} }
} }

@ -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
Loading…
Cancel
Save