Skip to content

Commit

Permalink
add gamescope support for proc_mem and io_read/write
Browse files Browse the repository at this point in the history
  • Loading branch information
17314642 authored and flightlessmango committed Jan 8, 2025
1 parent 625a42a commit 0575c8e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
20 changes: 17 additions & 3 deletions src/iostats.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "iostats.h"
#include "string_utils.h"
#include <fstream>
#include "hud_elements.h"

struct iostats g_io_stats;

Expand All @@ -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));
}
Expand Down
13 changes: 11 additions & 2 deletions src/memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <array>

#include "memory.h"
#include "hud_elements.h"

float memused, memmax, swapused;
uint64_t proc_mem_resident, proc_mem_shared, proc_mem_virt;
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 0575c8e

Please sign in to comment.