From 0251ced9d711dd17a789677f4aa3cfe3852693cb Mon Sep 17 00:00:00 2001 From: 17314642 <48242771@protonmail.ch> Date: Fri, 3 Jan 2025 09:10:02 +0300 Subject: [PATCH] gpu_fdinfo: find_fd() every 10 secs instead of once mass effect 1 creates 2 fds with stats, one at the start of the game and one after loading screen. mangohud does find_fd() only once at the start of the game and hence will miss second fd which has actual gpu stats. --- src/gpu_fdinfo.cpp | 16 ++++++++++++---- src/gpu_fdinfo.h | 18 +++++++++++------- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/gpu_fdinfo.cpp b/src/gpu_fdinfo.cpp index 0df61b3a9d..1753d84837 100644 --- a/src/gpu_fdinfo.cpp +++ b/src/gpu_fdinfo.cpp @@ -1,13 +1,12 @@ #include "gpu_fdinfo.h" #include "hud_elements.h" + namespace fs = ghc::filesystem; void GPU_fdinfo::find_fd() { - if (fdinfo.size() > 0) { - fdinfo.clear(); - fdinfo_data.clear(); - } + fdinfo.clear(); + fdinfo_data.clear(); auto dir = std::string("/proc/") + std::to_string(pid) + "/fdinfo"; auto path = fs::path(dir); @@ -497,6 +496,15 @@ void GPU_fdinfo::main_thread() find_fd(); } + // Recheck fds every 10secs, fixes Mass Effect 1, maybe some others too + { + auto t = os_time_get_nano() / 1'000'000; + if (t - fdinfo_last_update_ms >= 10'000) { + find_fd(); + fdinfo_last_update_ms = t; + } + } + gather_fdinfo_data(); get_current_hwmon_readings(); diff --git a/src/gpu_fdinfo.h b/src/gpu_fdinfo.h index 79bf07821f..5cefc46eb3 100644 --- a/src/gpu_fdinfo.h +++ b/src/gpu_fdinfo.h @@ -1,11 +1,16 @@ #pragma once -#include -#include + #include #include #include #include + +#include #include +#include +#include +#include +#include #ifdef TEST_ONLY #include <../src/mesa/util/os_time.h> @@ -13,12 +18,10 @@ #include "mesa/util/os_time.h" #endif -#include "gpu_metrics_util.h" -#include #include -#include -#include -#include +#include + +#include "gpu_metrics_util.h" struct hwmon_sensor { std::regex rx; @@ -53,6 +56,7 @@ class GPU_fdinfo { mutable std::mutex metrics_mutex; std::vector fdinfo; + uint64_t fdinfo_last_update_ms = 0; std::map hwmon_sensors;