Skip to content
Snippets Groups Projects
Commit f2e265b6 authored by Maxime Graulich's avatar Maxime Graulich
Browse files

add TotalRam() to get amount of physical memory, in Megabytes

parent 46e52440
No related branches found
No related tags found
No related merge requests found
...@@ -17,6 +17,14 @@ ...@@ -17,6 +17,14 @@
#include "GmshConfig.h" #include "GmshConfig.h"
#include "StringUtils.h" #include "StringUtils.h"
#if defined(__APPLE__)
#include <sys/sysctl.h>
#endif
#if defined(__linux__)
#include <sys/sysinfo.h>
#endif
#if !defined(WIN32) || defined(__CYGWIN__) #if !defined(WIN32) || defined(__CYGWIN__)
#include <unistd.h> #include <unistd.h>
#include <sys/time.h> #include <sys/time.h>
...@@ -262,6 +270,28 @@ double Cpu() ...@@ -262,6 +270,28 @@ double Cpu()
return s; return s;
} }
double TotalRam()
{
double ram = 0;
#if defined(__APPLE__)
int name[] = {CTL_HW, HW_MEMSIZE};
int64_t value;
size_t len = sizeof(value);
if(sysctl(name, 2, &value, &len, NULL, 0) != -1)
ram = value / (1024 * 1024);
#elif defined (WIN32)
MEMORYSTATUSEX status;
status.dwLength = sizeof(status);
GlobalMemoryStatusEx(&status);
ram = status.ullTotalPhys / ((double)1024 * 1024);
#elif defined(__linux__)
struct sysinfo infos;
if(sysinfo(&infos) != -1)
ram = infos.totalram * (unsigned long)infos.mem_unit / ((double)1024 * 1024);
#endif
return ram;
}
long GetMemoryUsage() long GetMemoryUsage()
{ {
long mem = 0; long mem = 0;
......
...@@ -15,6 +15,7 @@ double GetTimeInSeconds(); ...@@ -15,6 +15,7 @@ double GetTimeInSeconds();
void SleepInSeconds(double s); void SleepInSeconds(double s);
void CheckResources(); void CheckResources();
double Cpu(); double Cpu();
double TotalRam();
long GetMemoryUsage(); long GetMemoryUsage();
int GetProcessId(); int GetProcessId();
std::string GetHostName(); std::string GetHostName();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment