summaryrefslogtreecommitdiffstats
path: root/Source/kwsys/SystemInformation.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2016-02-24 14:39:18 (GMT)
committerCMake Topic Stage <kwrobot@kitware.com>2016-02-24 14:39:18 (GMT)
commit0f48312386d77b6e95bd23ced8d7ff2a51928738 (patch)
treee7cb6acb26cc4ae62a46f76e12ddf0b8a4a1e270 /Source/kwsys/SystemInformation.cxx
parent3cff48b1bbb37c9a48cae49ddea6effdb11bde73 (diff)
parentd010ba9fa71035f44e6df2fdf86bf38ab8559df5 (diff)
downloadCMake-0f48312386d77b6e95bd23ced8d7ff2a51928738.zip
CMake-0f48312386d77b6e95bd23ced8d7ff2a51928738.tar.gz
CMake-0f48312386d77b6e95bd23ced8d7ff2a51928738.tar.bz2
Merge topic 'update-kwsys'
d010ba9f Merge branch 'upstream-KWSys' into update-kwsys a132064b KWSys 2016-02-22 (4847aedd)
Diffstat (limited to 'Source/kwsys/SystemInformation.cxx')
-rw-r--r--Source/kwsys/SystemInformation.cxx40
1 files changed, 25 insertions, 15 deletions
diff --git a/Source/kwsys/SystemInformation.cxx b/Source/kwsys/SystemInformation.cxx
index cddcc8d..127a048 100644
--- a/Source/kwsys/SystemInformation.cxx
+++ b/Source/kwsys/SystemInformation.cxx
@@ -43,7 +43,6 @@
#if 0
# include "SystemInformation.hxx.in"
# include "Process.h.in"
-# include "Configure.hxx.in"
#endif
#include <iostream>
@@ -3570,33 +3569,44 @@ SystemInformationImplementation::GetHostMemoryUsed()
return (statex.ullTotalPhys - statex.ullAvailPhys)/1024;
# endif
#elif defined(__linux)
- const char *names[3]={"MemTotal:","MemFree:",NULL};
- SystemInformation::LongLong values[2]={SystemInformation::LongLong(0)};
- int ierr=GetFieldsFromFile("/proc/meminfo",names,values);
+ // First try to use MemAvailable, but it only works on newer kernels
+ const char *names2[3]={"MemTotal:","MemAvailable:",NULL};
+ SystemInformation::LongLong values2[2]={SystemInformation::LongLong(0)};
+ int ierr=GetFieldsFromFile("/proc/meminfo",names2,values2);
if (ierr)
{
- return ierr;
- }
- SystemInformation::LongLong &memTotal=values[0];
- SystemInformation::LongLong &memFree=values[1];
- return memTotal - memFree;
+ const char *names4[5]={"MemTotal:","MemFree:","Buffers:","Cached:",NULL};
+ SystemInformation::LongLong values4[4]={SystemInformation::LongLong(0)};
+ ierr=GetFieldsFromFile("/proc/meminfo",names4,values4);
+ if(ierr)
+ {
+ return ierr;
+ }
+ SystemInformation::LongLong &memTotal=values4[0];
+ SystemInformation::LongLong &memFree=values4[1];
+ SystemInformation::LongLong &memBuffers=values4[2];
+ SystemInformation::LongLong &memCached=values4[3];
+ return memTotal - memFree - memBuffers - memCached;
+ }
+ SystemInformation::LongLong &memTotal=values2[0];
+ SystemInformation::LongLong &memAvail=values2[1];
+ return memTotal - memAvail;
#elif defined(__APPLE__)
SystemInformation::LongLong psz=getpagesize();
if (psz<1)
{
return -1;
}
- const char *names[4]={"Pages active:","Pages inactive:","Pages wired down:",NULL};
- SystemInformation::LongLong values[3]={SystemInformation::LongLong(0)};
+ const char *names[3]={"Pages wired down:","Pages active:",NULL};
+ SystemInformation::LongLong values[2]={SystemInformation::LongLong(0)};
int ierr=GetFieldsFromCommand("vm_stat", names, values);
if (ierr)
{
return -1;
}
- SystemInformation::LongLong &vmActive=values[0];
- SystemInformation::LongLong &vmInactive=values[1];
- SystemInformation::LongLong &vmWired=values[2];
- return ((vmActive+vmInactive+vmWired)*psz)/1024;
+ SystemInformation::LongLong &vmWired=values[0];
+ SystemInformation::LongLong &vmActive=values[1];
+ return ((vmActive+vmWired)*psz)/1024;
#else
return 0;
#endif