sysinfo: Implement RAM Usage stats for Linux (#18473)

Reads memory statistics from "/proc/meminfo"
This commit is contained in:
Ani 2026-03-29 18:48:59 +02:00 committed by GitHub
parent f8fe64ff77
commit aa7cf5ea15
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -743,7 +743,26 @@ std::pair<u64, u64> utils::get_memory_usage()
status.dwLength = sizeof(status);
::GlobalMemoryStatusEx(&status);
return { status.ullTotalPhys, status.ullTotalPhys - status.ullAvailPhys };
#elif __linux__
std::ifstream proc("/proc/meminfo");
std::string line;
uint64_t mem_total = get_total_memory();
uint64_t mem_available = 0;
while (std::getline(proc, line))
{
if (line.rfind("MemTotal:", 0) == 0 && line.find("kB") != std::string::npos)
{
mem_total = std::stoull(line.substr(line.find_first_of("0123456789"))) * 1024;
}
else if (line.rfind("MemAvailable:", 0) == 0 && line.find("kB") != std::string::npos)
{
mem_available = std::stoull(line.substr(line.find_first_of("0123456789"))) * 1024;
break;
}
}
return { mem_total, mem_total - mem_available };
#else
// TODO
return { get_total_memory(), 0 };