Use smaps_rollup for more accurate info.

This commit is contained in:
goeiecool9999 2022-09-10 14:33:54 +02:00 committed by klaas
parent 6aa7a0c7b2
commit fa27f1976e

View File

@ -2,30 +2,21 @@
#include "util/SystemInfo/SystemInfo.h"
#include <unistd.h>
#include <sys/times.h>
uint64 QueryRamUsage()
{
long page_size = sysconf(_SC_PAGESIZE);
if (page_size == -1)
{
return 0;
}
std::ifstream file("/proc/self/statm");
std::ifstream file("/proc/self/smaps_rollup");
if (file)
{
file.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
file.ignore(std::numeric_limits<std::streamsize>::max(), ' ');
uint64 no_pages;
file >> no_pages;
uint64 kilobytes;
file >> kilobytes;
return no_pages * page_size;
}
else
{
return 0;
return kilobytes / 1000;
}
return 0;
}
void QueryProcTime(uint64 &out_now, uint64 &out_user, uint64 &out_kernel)
@ -64,4 +55,4 @@ void QueryCoreTimes(uint32 count, ProcessorTime out[])
}
}
#endif
#endif