summaryrefslogtreecommitdiffstats
path: root/Source/kwsys/SystemInformation.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'Source/kwsys/SystemInformation.cxx')
-rw-r--r--Source/kwsys/SystemInformation.cxx163
1 files changed, 52 insertions, 111 deletions
diff --git a/Source/kwsys/SystemInformation.cxx b/Source/kwsys/SystemInformation.cxx
index c565823..ed1cdc0 100644
--- a/Source/kwsys/SystemInformation.cxx
+++ b/Source/kwsys/SystemInformation.cxx
@@ -169,34 +169,6 @@ typedef struct rlimit ResourceLimitType;
#include <cstring>
#include <memory.h>
-#if defined(KWSYS_USE_LONG_LONG)
-# if defined(KWSYS_IOS_HAS_OSTREAM_LONG_LONG)
-# define iostreamLongLong(x) (x)
-# else
-# define iostreamLongLong(x) ((long)(x))
-# endif
-#elif defined(KWSYS_USE___INT64)
-# if defined(KWSYS_IOS_HAS_OSTREAM___INT64)
-# define iostreamLongLong(x) (x)
-# else
-# define iostreamLongLong(x) ((long)(x))
-# endif
-#else
-# error "No Long Long"
-#endif
-
-#if defined(KWSYS_CXX_HAS_ATOLL)
-# define atoLongLong atoll
-#else
-# if defined(KWSYS_CXX_HAS__ATOI64)
-# define atoLongLong _atoi64
-# elif defined(KWSYS_CXX_HAS_ATOL)
-# define atoLongLong atol
-# else
-# define atoLongLong atoi
-# endif
-#endif
-
#if defined(_MSC_VER) && (_MSC_VER >= 1300) && !defined(_WIN64) && \
!defined(__clang__)
# define USE_ASM_INSTRUCTIONS 1
@@ -212,8 +184,7 @@ typedef struct rlimit ResourceLimitType;
# define USE_CPUID_INTRINSICS 0
#endif
-#if USE_ASM_INSTRUCTIONS || USE_CPUID_INTRINSICS || \
- defined(KWSYS_CXX_HAS_BORLAND_ASM_CPUID)
+#if USE_ASM_INSTRUCTIONS || USE_CPUID_INTRINSICS
# define USE_CPUID 1
#else
# define USE_CPUID 0
@@ -273,21 +244,6 @@ static bool call_cpuid(int select, int result[4])
}
memcpy(result, tmp, sizeof(tmp));
-# elif defined(KWSYS_CXX_HAS_BORLAND_ASM_CPUID)
- unsigned int a, b, c, d;
- __asm {
- mov EAX, select;
- cpuid
- mov a, EAX;
- mov b, EBX;
- mov c, ECX;
- mov d, EDX;
- }
-
- result[0] = a;
- result[1] = b;
- result[2] = c;
- result[3] = d;
# endif
// The cpuid instruction succeeded.
@@ -313,7 +269,6 @@ using DELAY_FUNC = void (*)(unsigned int);
class SystemInformationImplementation
{
public:
- using LongLong = SystemInformation::LongLong;
SystemInformationImplementation();
~SystemInformationImplementation() = default;
@@ -353,16 +308,16 @@ public:
size_t GetTotalPhysicalMemory() const;
size_t GetAvailablePhysicalMemory() const;
- LongLong GetProcessId();
+ long long GetProcessId();
// Retrieve memory information in KiB.
- LongLong GetHostMemoryTotal();
- LongLong GetHostMemoryAvailable(const char* hostLimitEnvVarName);
- LongLong GetHostMemoryUsed();
+ long long GetHostMemoryTotal();
+ long long GetHostMemoryAvailable(const char* hostLimitEnvVarName);
+ long long GetHostMemoryUsed();
- LongLong GetProcMemoryAvailable(const char* hostLimitEnvVarName,
- const char* procLimitEnvVarName);
- LongLong GetProcMemoryUsed();
+ long long GetProcMemoryAvailable(const char* hostLimitEnvVarName,
+ const char* procLimitEnvVarName);
+ long long GetProcMemoryUsed();
double GetLoadAverage();
@@ -521,7 +476,8 @@ protected:
void CPUCountWindows(); // For windows
unsigned char GetAPICId(); // For windows
bool IsSMTSupported() const;
- static LongLong GetCyclesDifference(DELAY_FUNC, unsigned int); // For windows
+ static long long GetCyclesDifference(DELAY_FUNC,
+ unsigned int); // For windows
// For Linux and Cygwin, /proc/cpuinfo formats are slightly different
bool RetreiveInformationFromCpuInfoFile();
@@ -812,42 +768,41 @@ std::string SystemInformation::GetMemoryDescription(
const char* hostLimitEnvVarName, const char* procLimitEnvVarName)
{
std::ostringstream oss;
- oss << "Host Total: " << iostreamLongLong(this->GetHostMemoryTotal())
+ oss << "Host Total: " << this->GetHostMemoryTotal()
<< " KiB, Host Available: "
- << iostreamLongLong(this->GetHostMemoryAvailable(hostLimitEnvVarName))
+ << this->GetHostMemoryAvailable(hostLimitEnvVarName)
<< " KiB, Process Available: "
- << iostreamLongLong(this->GetProcMemoryAvailable(hostLimitEnvVarName,
- procLimitEnvVarName))
+ << this->GetProcMemoryAvailable(hostLimitEnvVarName, procLimitEnvVarName)
<< " KiB";
return oss.str();
}
// host memory info in units of KiB.
-SystemInformation::LongLong SystemInformation::GetHostMemoryTotal()
+long long SystemInformation::GetHostMemoryTotal()
{
return this->Implementation->GetHostMemoryTotal();
}
-SystemInformation::LongLong SystemInformation::GetHostMemoryAvailable(
+long long SystemInformation::GetHostMemoryAvailable(
const char* hostLimitEnvVarName)
{
return this->Implementation->GetHostMemoryAvailable(hostLimitEnvVarName);
}
-SystemInformation::LongLong SystemInformation::GetHostMemoryUsed()
+long long SystemInformation::GetHostMemoryUsed()
{
return this->Implementation->GetHostMemoryUsed();
}
// process memory info in units of KiB.
-SystemInformation::LongLong SystemInformation::GetProcMemoryAvailable(
+long long SystemInformation::GetProcMemoryAvailable(
const char* hostLimitEnvVarName, const char* procLimitEnvVarName)
{
return this->Implementation->GetProcMemoryAvailable(hostLimitEnvVarName,
procLimitEnvVarName);
}
-SystemInformation::LongLong SystemInformation::GetProcMemoryUsed()
+long long SystemInformation::GetProcMemoryUsed()
{
return this->Implementation->GetProcMemoryUsed();
}
@@ -857,7 +812,7 @@ double SystemInformation::GetLoadAverage()
return this->Implementation->GetLoadAverage();
}
-SystemInformation::LongLong SystemInformation::GetProcessId()
+long long SystemInformation::GetProcessId()
{
return this->Implementation->GetProcessId();
}
@@ -3628,8 +3583,7 @@ bool SystemInformationImplementation::QueryProcessor()
/**
Get total system RAM in units of KiB.
*/
-SystemInformation::LongLong
-SystemInformationImplementation::GetHostMemoryTotal()
+long long SystemInformationImplementation::GetHostMemoryTotal()
{
#if defined(_WIN32)
# if defined(_MSC_VER) && _MSC_VER < 1300
@@ -3644,7 +3598,7 @@ SystemInformationImplementation::GetHostMemoryTotal()
return statex.ullTotalPhys / 1024;
# endif
#elif defined(__linux)
- SystemInformation::LongLong memTotal = 0;
+ long long memTotal = 0;
int ierr = GetFieldFromFile("/proc/meminfo", "MemTotal:", memTotal);
if (ierr) {
return -1;
@@ -3667,11 +3621,10 @@ SystemInformationImplementation::GetHostMemoryTotal()
Get total system RAM in units of KiB. This may differ from the
host total if a host-wide resource limit is applied.
*/
-SystemInformation::LongLong
-SystemInformationImplementation::GetHostMemoryAvailable(
+long long SystemInformationImplementation::GetHostMemoryAvailable(
const char* hostLimitEnvVarName)
{
- SystemInformation::LongLong memTotal = this->GetHostMemoryTotal();
+ long long memTotal = this->GetHostMemoryTotal();
// the following mechanism is provided for systems that
// apply resource limits across groups of processes.
@@ -3682,8 +3635,7 @@ SystemInformationImplementation::GetHostMemoryAvailable(
if (hostLimitEnvVarName) {
const char* hostLimitEnvVarValue = getenv(hostLimitEnvVarName);
if (hostLimitEnvVarValue) {
- SystemInformation::LongLong hostLimit =
- atoLongLong(hostLimitEnvVarValue);
+ long long hostLimit = std::atoll(hostLimitEnvVarValue);
if (hostLimit > 0) {
memTotal = min(hostLimit, memTotal);
}
@@ -3697,20 +3649,17 @@ SystemInformationImplementation::GetHostMemoryAvailable(
Get total system RAM in units of KiB. This may differ from the
host total if a per-process resource limit is applied.
*/
-SystemInformation::LongLong
-SystemInformationImplementation::GetProcMemoryAvailable(
+long long SystemInformationImplementation::GetProcMemoryAvailable(
const char* hostLimitEnvVarName, const char* procLimitEnvVarName)
{
- SystemInformation::LongLong memAvail =
- this->GetHostMemoryAvailable(hostLimitEnvVarName);
+ long long memAvail = this->GetHostMemoryAvailable(hostLimitEnvVarName);
// the following mechanism is provide for systems where rlimits
// are not employed. Units are in KiB.
if (procLimitEnvVarName) {
const char* procLimitEnvVarValue = getenv(procLimitEnvVarName);
if (procLimitEnvVarValue) {
- SystemInformation::LongLong procLimit =
- atoLongLong(procLimitEnvVarValue);
+ long long procLimit = std::atoll(procLimitEnvVarValue);
if (procLimit > 0) {
memAvail = min(procLimit, memAvail);
}
@@ -3722,28 +3671,24 @@ SystemInformationImplementation::GetProcMemoryAvailable(
ResourceLimitType rlim;
ierr = GetResourceLimit(RLIMIT_DATA, &rlim);
if ((ierr == 0) && (rlim.rlim_cur != RLIM_INFINITY)) {
- memAvail =
- min((SystemInformation::LongLong)rlim.rlim_cur / 1024, memAvail);
+ memAvail = min((long long)rlim.rlim_cur / 1024, memAvail);
}
ierr = GetResourceLimit(RLIMIT_AS, &rlim);
if ((ierr == 0) && (rlim.rlim_cur != RLIM_INFINITY)) {
- memAvail =
- min((SystemInformation::LongLong)rlim.rlim_cur / 1024, memAvail);
+ memAvail = min((long long)rlim.rlim_cur / 1024, memAvail);
}
#elif defined(__APPLE__)
struct rlimit rlim;
int ierr;
ierr = getrlimit(RLIMIT_DATA, &rlim);
if ((ierr == 0) && (rlim.rlim_cur != RLIM_INFINITY)) {
- memAvail =
- min((SystemInformation::LongLong)rlim.rlim_cur / 1024, memAvail);
+ memAvail = min((long long)rlim.rlim_cur / 1024, memAvail);
}
ierr = getrlimit(RLIMIT_RSS, &rlim);
if ((ierr == 0) && (rlim.rlim_cur != RLIM_INFINITY)) {
- memAvail =
- min((SystemInformation::LongLong)rlim.rlim_cur / 1024, memAvail);
+ memAvail = min((long long)rlim.rlim_cur / 1024, memAvail);
}
#endif
@@ -3753,8 +3698,7 @@ SystemInformationImplementation::GetProcMemoryAvailable(
/**
Get RAM used by all processes in the host, in units of KiB.
*/
-SystemInformation::LongLong
-SystemInformationImplementation::GetHostMemoryUsed()
+long long SystemInformationImplementation::GetHostMemoryUsed()
{
#if defined(_WIN32)
# if defined(_MSC_VER) && _MSC_VER < 1300
@@ -3771,39 +3715,38 @@ SystemInformationImplementation::GetHostMemoryUsed()
#elif defined(__linux)
// First try to use MemAvailable, but it only works on newer kernels
const char* names2[3] = { "MemTotal:", "MemAvailable:", nullptr };
- SystemInformation::LongLong values2[2] = { SystemInformation::LongLong(0) };
+ long long values2[2] = { 0 };
int ierr = GetFieldsFromFile("/proc/meminfo", names2, values2);
if (ierr) {
const char* names4[5] = { "MemTotal:", "MemFree:", "Buffers:", "Cached:",
nullptr };
- SystemInformation::LongLong values4[4] = { SystemInformation::LongLong(
- 0) };
+ long long values4[4] = { 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];
+ long long& memTotal = values4[0];
+ long long& memFree = values4[1];
+ long long& memBuffers = values4[2];
+ long long& memCached = values4[3];
return memTotal - memFree - memBuffers - memCached;
}
- SystemInformation::LongLong& memTotal = values2[0];
- SystemInformation::LongLong& memAvail = values2[1];
+ long long& memTotal = values2[0];
+ long long& memAvail = values2[1];
return memTotal - memAvail;
#elif defined(__APPLE__)
- SystemInformation::LongLong psz = getpagesize();
+ long long psz = getpagesize();
if (psz < 1) {
return -1;
}
const char* names[3] = { "Pages wired down:", "Pages active:", nullptr };
- SystemInformation::LongLong values[2] = { SystemInformation::LongLong(0) };
+ long long values[2] = { 0 };
int ierr = GetFieldsFromCommand("vm_stat", names, values);
if (ierr) {
return -1;
}
- SystemInformation::LongLong& vmWired = values[0];
- SystemInformation::LongLong& vmActive = values[1];
+ long long& vmWired = values[0];
+ long long& vmActive = values[1];
return ((vmActive + vmWired) * psz) / 1024;
#else
return 0;
@@ -3814,8 +3757,7 @@ SystemInformationImplementation::GetHostMemoryUsed()
Get system RAM used by the process associated with the given
process id in units of KiB.
*/
-SystemInformation::LongLong
-SystemInformationImplementation::GetProcMemoryUsed()
+long long SystemInformationImplementation::GetProcMemoryUsed()
{
#if defined(_WIN32) && defined(KWSYS_SYS_HAS_PSAPI)
long pid = GetCurrentProcessId();
@@ -3832,14 +3774,14 @@ SystemInformationImplementation::GetProcMemoryUsed()
}
return pmc.WorkingSetSize / 1024;
#elif defined(__linux)
- SystemInformation::LongLong memUsed = 0;
+ long long memUsed = 0;
int ierr = GetFieldFromFile("/proc/self/status", "VmRSS:", memUsed);
if (ierr) {
return -1;
}
return memUsed;
#elif defined(__APPLE__)
- SystemInformation::LongLong memUsed = 0;
+ long long memUsed = 0;
pid_t pid = getpid();
std::ostringstream oss;
oss << "ps -o rss= -p " << pid;
@@ -3903,7 +3845,7 @@ double SystemInformationImplementation::GetLoadAverage()
/**
Get the process id of the running process.
*/
-SystemInformation::LongLong SystemInformationImplementation::GetProcessId()
+long long SystemInformationImplementation::GetProcessId()
{
#if defined(_WIN32)
return GetCurrentProcessId();
@@ -4316,9 +4258,8 @@ size_t SystemInformationImplementation::GetAvailablePhysicalMemory() const
}
/** Get Cycle differences */
-SystemInformation::LongLong
-SystemInformationImplementation::GetCyclesDifference(DELAY_FUNC DelayFunction,
- unsigned int uiParameter)
+long long SystemInformationImplementation::GetCyclesDifference(
+ DELAY_FUNC DelayFunction, unsigned int uiParameter)
{
#if defined(_MSC_VER) && (_MSC_VER >= 1400)
unsigned __int64 stamp1, stamp2;
@@ -4449,12 +4390,12 @@ void SystemInformationImplementation::CPUCountWindows()
DWORD Length = 0;
DWORD rc = pGetLogicalProcessorInformation(nullptr, &Length);
assert(FALSE == rc);
- (void)rc; // Silence unused variable warning in Borland C++ 5.81
+ (void)rc; // Silence unused variable warning
assert(GetLastError() == ERROR_INSUFFICIENT_BUFFER);
ProcInfo.resize(Length / sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION));
rc = pGetLogicalProcessorInformation(&ProcInfo[0], &Length);
assert(rc != FALSE);
- (void)rc; // Silence unused variable warning in Borland C++ 5.81
+ (void)rc; // Silence unused variable warning
}
typedef std::vector<SYSTEM_LOGICAL_PROCESSOR_INFORMATION>::iterator