mirror of
https://github.com/libretro/RetroArch
synced 2025-04-09 21:45:45 +00:00
get_mem_used should now report more accurate values
This commit is contained in:
parent
1e91689919
commit
549bc8dc5e
@ -1912,23 +1912,49 @@ static void frontend_linux_exitspawn(char *core_path, size_t core_path_size)
|
|||||||
|
|
||||||
static uint64_t frontend_linux_get_mem_total(void)
|
static uint64_t frontend_linux_get_mem_total(void)
|
||||||
{
|
{
|
||||||
uint64_t pageSize = sysconf(_SC_PAGESIZE);
|
FILE* data = fopen("/proc/meminfo", "r");
|
||||||
uint64_t totalNumPages = sysconf(_SC_PHYS_PAGES);
|
if (!data)
|
||||||
return pageSize * totalNumPages;
|
return 0;
|
||||||
}
|
|
||||||
|
|
||||||
static uint64_t frontend_linux_get_mem_free(void)
|
char line[256];
|
||||||
{
|
uint64_t total = 0;
|
||||||
uint64_t pageSize = sysconf(_SC_PAGESIZE);
|
while (fgets(line, sizeof(line), data)) {
|
||||||
uint64_t availNumPages = sysconf(_SC_AVPHYS_PAGES);
|
if (sscanf(line, "MemTotal: %lu kB", &total) == 1) {
|
||||||
return availNumPages * pageSize;
|
fclose(data);
|
||||||
|
total *= 1024;
|
||||||
|
return total;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose(data);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint64_t frontend_linux_get_mem_used(void)
|
static uint64_t frontend_linux_get_mem_used(void)
|
||||||
{
|
{
|
||||||
uint64_t free_mem = frontend_linux_get_mem_free();
|
FILE* data = fopen("/proc/meminfo", "r");
|
||||||
uint64_t total_mem = frontend_linux_get_mem_total();
|
if (!data)
|
||||||
return total_mem - free_mem;
|
return 0;
|
||||||
|
|
||||||
|
uint64_t total = 0;
|
||||||
|
uint64_t freemem = 0;
|
||||||
|
uint64_t buffers = 0;
|
||||||
|
uint64_t cached = 0;
|
||||||
|
|
||||||
|
char line[256];
|
||||||
|
while (fgets(line, sizeof(line), data)) {
|
||||||
|
if (sscanf(line, "MemTotal: %lu kB", &total) == 1)
|
||||||
|
total *= 1024;
|
||||||
|
if (sscanf(line, "MemFree: %lu kB", &freemem) == 1)
|
||||||
|
freemem *= 1024;
|
||||||
|
if (sscanf(line, "Buffers: %lu kB", &buffers) == 1)
|
||||||
|
buffers *= 1024;
|
||||||
|
if (sscanf(line, "Cached: %lu kB", &cached) == 1)
|
||||||
|
cached *= 1024;
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose(data);
|
||||||
|
return total - freemem - buffers - cached;
|
||||||
}
|
}
|
||||||
|
|
||||||
frontend_ctx_driver_t frontend_ctx_linux = {
|
frontend_ctx_driver_t frontend_ctx_linux = {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user