diff --git a/src/iostats.cpp b/src/iostats.cpp index 089afdb1c5..0da526b3e1 100644 --- a/src/iostats.cpp +++ b/src/iostats.cpp @@ -1,6 +1,7 @@ #include "iostats.h" #include "string_utils.h" #include +#include "hud_elements.h" struct iostats g_io_stats; @@ -11,9 +12,22 @@ void getIoStats(iostats& io) { io.prev.read_bytes = io.curr.read_bytes; io.prev.write_bytes = io.curr.write_bytes; - std::string line; - std::ifstream f("/proc/self/io"); - while (std::getline(f, line)) { + std::string f = "/proc/"; + + { + auto gs_pid = HUDElements.g_gamescopePid; + f += gs_pid < 1 ? "self" : std::to_string(gs_pid); + f += "/io"; + } + + std::ifstream file(f); + + if (!file.is_open()) { + SPDLOG_ERROR("can't open {}", f); + return; + } + + for (std::string line; std::getline(file, line);) { if (starts_with(line, "read_bytes:")) { try_stoull(io.curr.read_bytes, line.substr(12)); } diff --git a/src/memory.cpp b/src/memory.cpp index b19700b938..d76338a842 100644 --- a/src/memory.cpp +++ b/src/memory.cpp @@ -6,6 +6,7 @@ #include #include "memory.h" +#include "hud_elements.h" float memused, memmax, swapused; uint64_t proc_mem_resident, proc_mem_shared, proc_mem_virt; @@ -35,10 +36,18 @@ void update_procmem() auto page_size = sysconf(_SC_PAGESIZE); if (page_size < 0) page_size = 4096; - std::ifstream file("/proc/self/statm"); + std::string f = "/proc/"; + + { + auto gs_pid = HUDElements.g_gamescopePid; + f += gs_pid < 1 ? "self" : std::to_string(gs_pid); + f += "/statm"; + } + + std::ifstream file(f); if (!file.is_open()) { - SPDLOG_ERROR("can't open /proc/self/statm"); + SPDLOG_ERROR("can't open {}", f); return; }