Skip to content

Commit

Permalink
gpu_fdinfo: find_fd() every 10 secs instead of once
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
17314642 committed Jan 4, 2025
1 parent f15bb7c commit 0251ced
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
16 changes: 12 additions & 4 deletions src/gpu_fdinfo.cpp
Original file line number Diff line number Diff line change
@@ -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);
Expand Down Expand Up @@ -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();

Expand Down
18 changes: 11 additions & 7 deletions src/gpu_fdinfo.h
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
#pragma once
#include <cstdint>
#include <filesystem.h>

#include <inttypes.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>

#include <cstdint>
#include <thread>
#include <atomic>
#include <map>
#include <set>
#include <regex>

#ifdef TEST_ONLY
#include <../src/mesa/util/os_time.h>
#else
#include "mesa/util/os_time.h"
#endif

#include "gpu_metrics_util.h"
#include <atomic>
#include <spdlog/spdlog.h>
#include <map>
#include <set>
#include <regex>
#include <filesystem.h>

#include "gpu_metrics_util.h"

struct hwmon_sensor {
std::regex rx;
Expand Down Expand Up @@ -53,6 +56,7 @@ class GPU_fdinfo {
mutable std::mutex metrics_mutex;

std::vector<std::ifstream> fdinfo;
uint64_t fdinfo_last_update_ms = 0;

std::map<std::string, hwmon_sensor> hwmon_sensors;

Expand Down

0 comments on commit 0251ced

Please sign in to comment.