mirror of
https://github.com/RPCS3/rpcs3.git
synced 2026-04-02 11:01:13 -06:00
sysinfo: Implement RAM Usage stats for Linux (#18473)
Reads memory statistics from "/proc/meminfo"
This commit is contained in:
parent
f8fe64ff77
commit
aa7cf5ea15
@ -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 };
|
||||
|
||||
Loading…
Reference in New Issue
Block a user