Skip to content
Snippets Groups Projects
Commit 6072e63b authored by Burlen Loring's avatar Burlen Loring
Browse files

SystemInformation: support for resource limits

Add methods to report host memory total, host memory available,
process memory available, host memory used, and process memory
used. In this context memory is unavailable if there are resource
limits in place that would prevent its use. Such resource limits
assumed to be applied on a per host basis both to cooperatively
operating process groups, such as mpi programms running in parallel,
and to individual processes. When reporting host memory available
consult an application specified environment variable. When reporting
process memory available consult unix resource rlimits and an
application specified environment variable. The environmant variables
provide a means of communicating resource limits that are being
applied in a non-standard way.

Change-Id: Ifb3b0fdaab8db0ab87140fa2dcafad3c51e2d874
parent bab53989
No related branches found
No related tags found
No related merge requests found
......@@ -509,19 +509,28 @@ ENDIF(KWSYS_USE_FundamentalType)
IF(KWSYS_USE_IOStream)
# Determine whether iostreams support long long.
SET(KWSYS_PLATFORM_CXX_TEST_DEFINES
-DKWSYS_IOS_USE_ANSI=${KWSYS_IOS_USE_ANSI}
-DKWSYS_IOS_HAVE_STD=${KWSYS_IOS_HAVE_STD})
IF(KWSYS_CXX_HAS_LONG_LONG)
SET(KWSYS_PLATFORM_CXX_TEST_DEFINES
-DKWSYS_IOS_USE_ANSI=${KWSYS_IOS_USE_ANSI}
-DKWSYS_IOS_HAVE_STD=${KWSYS_IOS_HAVE_STD})
KWSYS_PLATFORM_CXX_TEST(KWSYS_IOS_HAS_ISTREAM_LONG_LONG
"Checking if istream supports long long" DIRECT)
KWSYS_PLATFORM_CXX_TEST(KWSYS_IOS_HAS_OSTREAM_LONG_LONG
"Checking if ostream supports long long" DIRECT)
SET(KWSYS_PLATFORM_CXX_TEST_DEFINES)
ELSE()
SET(KWSYS_IOS_HAS_ISTREAM_LONG_LONG 0)
SET(KWSYS_IOS_HAS_OSTREAM_LONG_LONG 0)
ENDIF()
IF(KWSYS_CXX_HAS___INT64)
KWSYS_PLATFORM_CXX_TEST(KWSYS_IOS_HAS_ISTREAM___INT64
"Checking if istream supports __int64" DIRECT)
KWSYS_PLATFORM_CXX_TEST(KWSYS_IOS_HAS_OSTREAM___INT64
"Checking if ostream supports __int64" DIRECT)
ELSE()
SET(KWSYS_IOS_HAS_ISTREAM___INT64 0)
SET(KWSYS_IOS_HAS_OSTREAM___INT64 0)
ENDIF()
SET(KWSYS_PLATFORM_CXX_TEST_DEFINES)
ENDIF(KWSYS_USE_IOStream)
IF(KWSYS_NAMESPACE MATCHES "^kwsys$")
......@@ -588,6 +597,54 @@ IF(KWSYS_USE_SystemInformation)
ENDIF()
ENDIF()
ENDIF()
IF(KWSYS_LFS_AVAILABLE AND NOT KWSYS_LFS_DISABLE)
SET(KWSYS_PLATFORM_CXX_TEST_DEFINES -DKWSYS_HAS_LFS=1)
ENDIF()
KWSYS_PLATFORM_CXX_TEST(KWSYS_CXX_HAS_RLIMIT64
"Checking whether CXX compiler has rlimit64" DIRECT)
SET(KWSYS_PLATFORM_CXX_TEST_DEFINES)
IF(KWSYS_CXX_HAS_RLIMIT64)
SET_PROPERTY(SOURCE SystemInformation.cxx APPEND PROPERTY
COMPILE_DEFINITIONS KWSYS_CXX_HAS_RLIMIT64=1)
ENDIF()
KWSYS_PLATFORM_CXX_TEST(KWSYS_CXX_HAS_ATOL
"Checking whether CXX compiler has atol" DIRECT)
IF(KWSYS_CXX_HAS_ATOL)
SET_PROPERTY(SOURCE SystemInformation.cxx APPEND PROPERTY
COMPILE_DEFINITIONS KWSYS_CXX_HAS_ATOL=1)
ENDIF()
KWSYS_PLATFORM_CXX_TEST(KWSYS_CXX_HAS_ATOLL
"Checking whether CXX compiler has atoll" DIRECT)
IF(KWSYS_CXX_HAS_ATOLL)
SET_PROPERTY(SOURCE SystemInformation.cxx APPEND PROPERTY
COMPILE_DEFINITIONS KWSYS_CXX_HAS_ATOLL=1)
ENDIF()
KWSYS_PLATFORM_CXX_TEST(KWSYS_CXX_HAS__ATOI64
"Checking whether CXX compiler has _atoi64" DIRECT)
IF(KWSYS_CXX_HAS__ATOI64)
SET_PROPERTY(SOURCE SystemInformation.cxx APPEND PROPERTY
COMPILE_DEFINITIONS KWSYS_CXX_HAS__ATOI64=1)
ENDIF()
IF(KWSYS_USE___INT64)
SET_PROPERTY(SOURCE SystemInformation.cxx testSystemInformation.cxx APPEND PROPERTY
COMPILE_DEFINITIONS KWSYS_USE___INT64=1)
ENDIF()
IF(KWSYS_USE_LONG_LONG)
SET_PROPERTY(SOURCE SystemInformation.cxx testSystemInformation.cxx APPEND PROPERTY
COMPILE_DEFINITIONS KWSYS_USE_LONG_LONG=1)
ENDIF()
IF(KWSYS_IOS_HAS_OSTREAM_LONG_LONG)
SET_PROPERTY(SOURCE SystemInformation.cxx testSystemInformation.cxx APPEND PROPERTY
COMPILE_DEFINITIONS KWSYS_IOS_HAS_OSTREAM_LONG_LONG=1)
ENDIF()
IF(KWSYS_IOS_HAS_OSTREAM___INT64)
SET_PROPERTY(SOURCE SystemInformation.cxx testSystemInformation.cxx APPEND PROPERTY
COMPILE_DEFINITIONS KWSYS_IOS_HAS_OSTREAM___INT64=1)
ENDIF()
IF(KWSYS_BUILD_SHARED)
SET_PROPERTY(SOURCE SystemInformation.cxx APPEND PROPERTY
COMPILE_DEFINITIONS KWSYS_BUILD_SHARED=1)
ENDIF()
ENDIF()
#-----------------------------------------------------------------------------
......
This diff is collapsed.
......@@ -24,7 +24,6 @@
namespace @KWSYS_NAMESPACE@
{
// forward declare the implementation class
class SystemInformationImplementation;
......@@ -96,15 +95,44 @@ public:
size_t GetTotalPhysicalMemory();
size_t GetAvailablePhysicalMemory();
// returns an informative general description if the ram
// on this system
kwsys_stl::string GetMemoryDescription();
// Retrieve physical memory information in kib
LongLong GetMemoryTotal();
LongLong GetMemoryUsed();
// enable/disable stack trace signal handler.
// returns an informative general description if the installed and
// available ram on this system. See the GetHostMmeoryTotal, and
// Get{Host,Proc}MemoryAvailable methods for more information.
kwsys_stl::string GetMemoryDescription(
const char *hostLimitEnvVarName=NULL,
const char *procLimitEnvVarName=NULL);
// Retrieve amount of physical memory installed on the system in KiB
// units.
LongLong GetHostMemoryTotal();
// Get total system RAM in units of KiB available colectivley to all
// processes in a process group. An example of a process group
// are the processes comprising an mpi program which is running in
// parallel. The amount of memory reported may differ from the host
// total if a host wide resource limit is applied. Such reource limits
// are reported to us via an applicaiton specified environment variable.
LongLong GetHostMemoryAvailable(const char *hostLimitEnvVarName=NULL);
// Get total system RAM in units of KiB available to this process.
// This may differ from the host available if a per-process resource
// limit is applied. per-process memory limits are applied on unix
// system via rlimit api. Resource limits that are not imposed via
// rlimit api may be reported to us via an application specified
// environment variable.
LongLong GetProcMemoryAvailable(
const char *hostLimitEnvVarName=NULL,
const char *procLimitEnvVarName=NULL);
// Get the system RAM used by all processes on the host, in units of KiB.
LongLong GetHostMemoryUsed();
// Get system RAM used by this process id in units of KiB.
LongLong GetProcMemoryUsed();
// enable/disable stack trace signal handler. In order to
// produce an informative stack trace the application should
// be dynamically linked and compiled with debug symbols.
static
void SetStackTraceOnError(int enable);
......@@ -113,6 +141,7 @@ public:
void RunOSCheck();
void RunMemoryCheck();
};
} // namespace @KWSYS_NAMESPACE@
/* Undefine temporary macros. */
......
......@@ -358,6 +358,30 @@ int main()
}
#endif
#ifdef TEST_KWSYS_IOS_HAS_ISTREAM___INT64
int test_istream(kwsys_ios::istream& is, __int64& x)
{
return (is >> x)? 1:0;
}
int main()
{
__int64 x = 0;
return test_istream(kwsys_ios::cin, x);
}
#endif
#ifdef TEST_KWSYS_IOS_HAS_OSTREAM___INT64
int test_ostream(kwsys_ios::ostream& os, __int64 x)
{
return (os << x)? 1:0;
}
int main()
{
__int64 x = 0;
return test_ostream(kwsys_ios::cout, x);
}
#endif
#ifdef TEST_KWSYS_CHAR_IS_SIGNED
/* Return 0 for char signed and 1 for char unsigned. */
int main()
......@@ -428,6 +452,48 @@ int main()
}
#endif
#ifdef TEST_KWSYS_CXX_HAS_RLIMIT64
# if defined(KWSYS_HAS_LFS)
# define _LARGEFILE_SOURCE
# define _LARGEFILE64_SOURCE
# define _LARGE_FILES
# define _FILE_OFFSET_BITS 64
# endif
# include <sys/resource.h>
int main()
{
struct rlimit64 rlim;
return getrlimit64(0,&rlim);
}
#endif
#ifdef TEST_KWSYS_CXX_HAS_ATOLL
#include <stdlib.h>
int main()
{
const char *str="1024";
return static_cast<int>(atoll(str));
}
#endif
#ifdef TEST_KWSYS_CXX_HAS_ATOL
#include <stdlib.h>
int main()
{
const char *str="1024";
return static_cast<int>(atol(str));
}
#endif
#ifdef TEST_KWSYS_CXX_HAS__ATOI64
#include <stdlib.h>
int main()
{
const char *str="1024";
return static_cast<int>(_atoi64(str));
}
#endif
#ifdef TEST_KWSYS_CXX_TYPE_INFO
/* Collect fundamental type information and save it to a CMake script. */
......
......@@ -13,8 +13,6 @@
#include KWSYS_HEADER(SystemInformation.hxx)
#include KWSYS_HEADER(ios/iostream)
// Work-around CMake dependency scanning limitation. This must
// duplicate the above list of headers.
#if 0
......@@ -22,12 +20,31 @@
# include "kwsys_ios_iostream.h.in"
#endif
#define printMethod(inof, m) kwsys_ios::cout << #m << ": " \
#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
#define printMethod(info, m) kwsys_ios::cout << #m << ": " \
<< info.m() << "\n"
#define printMethod2(inof, m, unit) kwsys_ios::cout << #m << ": " \
#define printMethod2(info, m, unit) kwsys_ios::cout << #m << ": " \
<< info.m() << " " << unit << "\n"
#define printMethod3(info, m, unit) kwsys_ios::cout << #m << ": " \
<< iostreamLongLong(info.m) << " " << unit << "\n"
int testSystemInformation(int, char*[])
{
kwsys::SystemInformation info;
......@@ -35,7 +52,11 @@ int testSystemInformation(int, char*[])
info.RunOSCheck();
info.RunMemoryCheck();
printMethod(info, GetOSName);
printMethod(info, GetOSIsLinux);
printMethod(info, GetOSIsApple);
printMethod(info, GetOSIsWindows);
printMethod(info, GetHostname);
printMethod(info, GetFullyQualifiedDomainName);
printMethod(info, GetOSRelease);
printMethod(info, GetOSVersion);
printMethod(info, GetOSPlatform);
......@@ -58,6 +79,11 @@ int testSystemInformation(int, char*[])
printMethod2(info, GetAvailableVirtualMemory, "MB");
printMethod2(info, GetTotalPhysicalMemory, "MB");
printMethod2(info, GetAvailablePhysicalMemory, "MB");
printMethod3(info, GetHostMemoryTotal(), "KiB");
printMethod3(info, GetHostMemoryAvailable("KWSHL"), "KiB");
printMethod3(info, GetProcMemoryAvailable("KWSHL","KWSPL"), "KiB");
printMethod3(info, GetHostMemoryUsed(), "KiB");
printMethod3(info, GetProcMemoryUsed(), "KiB");
//int GetProcessorCacheXSize(long int);
// bool DoesCPUSupportFeature(long int);
......
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