[Cmake-commits] CMake branch, next, updated. v3.2.3-1476-ga0340c2

Brad King brad.king at kitware.com
Thu Jun 4 09:25:27 EDT 2015


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "CMake".

The branch, next has been updated
       via  a0340c21719bd16512bec3bca20e0f25704803c9 (commit)
       via  bccbe281ff7039e145814d1858a45f38bb681173 (commit)
       via  6cafd8ed0bc8458ba2c6eb0e792c894cf4f37f90 (commit)
      from  408cd6d1aa7f6ed126b0e363843b4b390cb0d309 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=a0340c21719bd16512bec3bca20e0f25704803c9
commit a0340c21719bd16512bec3bca20e0f25704803c9
Merge: 408cd6d bccbe28
Author:     Brad King <brad.king at kitware.com>
AuthorDate: Thu Jun 4 09:25:26 2015 -0400
Commit:     CMake Topic Stage <kwrobot at kitware.com>
CommitDate: Thu Jun 4 09:25:26 2015 -0400

    Merge topic 'update-kwsys' into next
    
    bccbe281 Merge branch 'upstream-kwsys' into update-kwsys
    6cafd8ed KWSys 2015-06-03 (8533a79b)


http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=bccbe281ff7039e145814d1858a45f38bb681173
commit bccbe281ff7039e145814d1858a45f38bb681173
Merge: 0886880 6cafd8e
Author:     Brad King <brad.king at kitware.com>
AuthorDate: Thu Jun 4 09:22:53 2015 -0400
Commit:     Brad King <brad.king at kitware.com>
CommitDate: Thu Jun 4 09:22:53 2015 -0400

    Merge branch 'upstream-kwsys' into update-kwsys


http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=6cafd8ed0bc8458ba2c6eb0e792c894cf4f37f90
commit 6cafd8ed0bc8458ba2c6eb0e792c894cf4f37f90
Author:     KWSys Robot <kwrobot at kitware.com>
AuthorDate: Wed Jun 3 14:25:01 2015 -0400
Commit:     Brad King <brad.king at kitware.com>
CommitDate: Thu Jun 4 09:22:48 2015 -0400

    KWSys 2015-06-03 (8533a79b)
    
    Extract upstream KWSys using the following shell commands.
    
    $ git archive --prefix=upstream-kwsys/ 8533a79b | tar x
    $ git shortlog --no-merges --abbrev=8 --format='%h %s' 61e0419f..8533a79b
    Zack Galbreath (1):
          8533a79b SystemInformation: Add GetLoadAverage() method

diff --git a/CMakeLists.txt b/CMakeLists.txt
index c88e888..7eb678b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -786,6 +786,15 @@ IF(KWSYS_USE_SystemInformation)
     SET_PROPERTY(SOURCE SystemInformation.cxx APPEND PROPERTY
       COMPILE_DEFINITIONS KWSYS_BUILD_SHARED=1)
   ENDIF()
+
+  IF(UNIX AND NOT CYGWIN)
+    KWSYS_PLATFORM_CXX_TEST(KWSYS_CXX_HAS_GETLOADAVG
+      "Checking whether CXX compiler has getloadavg" DIRECT)
+    IF(KWSYS_CXX_HAS_GETLOADAVG)
+      SET_PROPERTY(SOURCE SystemInformation.cxx APPEND PROPERTY
+        COMPILE_DEFINITIONS KWSYS_CXX_HAS_GETLOADAVG=1)
+    ENDIF()
+  ENDIF()
 ENDIF()
 
 #-----------------------------------------------------------------------------
diff --git a/SystemInformation.cxx b/SystemInformation.cxx
index b0434f4..6e81b0b 100644
--- a/SystemInformation.cxx
+++ b/SystemInformation.cxx
@@ -81,6 +81,11 @@ typedef int siginfo_t;
 # include <errno.h> // extern int errno;
 #endif
 
+#if defined (__CYGWIN__) && !defined(_WIN32)
+# include <windows.h>
+# undef _WIN32
+#endif
+
 #ifdef __FreeBSD__
 # include <sys/sysctl.h>
 # include <fenv.h>
@@ -366,6 +371,8 @@ public:
         const char *procLimitEnvVarName);
   LongLong GetProcMemoryUsed();
 
+  double GetLoadAverage();
+
   // enable/disable stack trace signal handler.
   static
   void SetStackTraceOnError(int enable);
@@ -820,6 +827,11 @@ SystemInformation::LongLong SystemInformation::GetProcMemoryUsed()
   return this->Implementation->GetProcMemoryUsed();
 }
 
+double SystemInformation::GetLoadAverage()
+{
+  return this->Implementation->GetLoadAverage();
+}
+
 SystemInformation::LongLong SystemInformation::GetProcessId()
 {
   return this->Implementation->GetProcessId();
@@ -1490,6 +1502,60 @@ void SymbolProperties::Initialize(void *address)
 }
 #endif // don't define this class if we're not using it
 
+// --------------------------------------------------------------------------
+#if defined(_WIN32) || defined(__CYGWIN__)
+# define KWSYS_SYSTEMINFORMATION_USE_GetSystemTimes
+#endif
+#if defined(_MSC_VER) && _MSC_VER < 1310
+# undef KWSYS_SYSTEMINFORMATION_USE_GetSystemTimes
+#endif
+#if defined(KWSYS_SYSTEMINFORMATION_USE_GetSystemTimes)
+double calculateCPULoad(unsigned __int64 idleTicks,
+                        unsigned __int64 totalTicks)
+{
+  static double previousLoad = -0.0;
+  static unsigned __int64 previousIdleTicks = 0;
+  static unsigned __int64 previousTotalTicks = 0;
+
+  unsigned __int64 const idleTicksSinceLastTime =
+    idleTicks - previousIdleTicks;
+  unsigned __int64 const totalTicksSinceLastTime =
+    totalTicks - previousTotalTicks;
+
+  double load;
+  if (previousTotalTicks == 0 || totalTicksSinceLastTime == 0)
+    {
+    // No new information.  Use previous result.
+    load = previousLoad;
+    }
+  else
+    {
+    // Calculate load since last time.
+    load = 1.0 - double(idleTicksSinceLastTime) / totalTicksSinceLastTime;
+
+    // Smooth if possible.
+    if (previousLoad > 0)
+      {
+      load = 0.25 * load + 0.75 * previousLoad;
+      }
+    }
+
+  previousLoad = load;
+  previousIdleTicks = idleTicks;
+  previousTotalTicks = totalTicks;
+
+  return load;
+}
+
+unsigned __int64 fileTimeToUInt64(FILETIME const& ft)
+{
+  LARGE_INTEGER out;
+  out.HighPart = ft.dwHighDateTime;
+  out.LowPart = ft.dwLowDateTime;
+  return out.QuadPart;
+}
+#endif
+
 } // anonymous namespace
 
 
@@ -3612,6 +3678,38 @@ SystemInformationImplementation::GetProcMemoryUsed()
 #endif
 }
 
+double SystemInformationImplementation::GetLoadAverage()
+{
+#if defined(KWSYS_CXX_HAS_GETLOADAVG)
+  double loadavg[3] = { 0.0, 0.0, 0.0 };
+  if (getloadavg(loadavg, 3) > 0)
+    {
+    return loadavg[0];
+    }
+  return -0.0;
+#elif defined(KWSYS_SYSTEMINFORMATION_USE_GetSystemTimes)
+  // Old windows.h headers do not provide GetSystemTimes.
+  typedef BOOL (WINAPI *GetSystemTimesType)(LPFILETIME, LPFILETIME,
+                                            LPFILETIME);
+  static GetSystemTimesType pGetSystemTimes =
+    (GetSystemTimesType)GetProcAddress(GetModuleHandleW(L"kernel32"),
+                                       "GetSystemTimes");
+  FILETIME idleTime, kernelTime, userTime;
+  if (pGetSystemTimes && pGetSystemTimes(&idleTime, &kernelTime, &userTime))
+    {
+    unsigned __int64 const idleTicks =
+      fileTimeToUInt64(idleTime);
+    unsigned __int64 const totalTicks =
+      fileTimeToUInt64(kernelTime) + fileTimeToUInt64(userTime);
+    return calculateCPULoad(idleTicks, totalTicks) * GetNumberOfPhysicalCPU();
+    }
+  return -0.0;
+#else
+  // Not implemented on this platform.
+  return -0.0;
+#endif
+}
+
 /**
 Get the process id of the running process.
 */
diff --git a/SystemInformation.hxx.in b/SystemInformation.hxx.in
index a9fd05d..4acdc4f 100644
--- a/SystemInformation.hxx.in
+++ b/SystemInformation.hxx.in
@@ -130,6 +130,10 @@ public:
   // Get system RAM used by this process id in units of KiB.
   LongLong GetProcMemoryUsed();
 
+  // Return the load average of the machine or -0.0 if it cannot
+  // be determined.
+  double GetLoadAverage();
+
   // 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.
diff --git a/kwsysPlatformTestsCXX.cxx b/kwsysPlatformTestsCXX.cxx
index 82620da..1596fe4 100644
--- a/kwsysPlatformTestsCXX.cxx
+++ b/kwsysPlatformTestsCXX.cxx
@@ -452,6 +452,19 @@ int main()
 }
 #endif
 
+#ifdef TEST_KWSYS_CXX_HAS_GETLOADAVG
+// Match feature definitions from SystemInformation.cxx
+#if (defined(__GNUC__) || defined(__PGI)) && !defined(_GNU_SOURCE)
+# define _GNU_SOURCE
+#endif
+#include <stdlib.h>
+int main()
+{
+  double loadavg[3] = { 0.0, 0.0, 0.0 };
+  return getloadavg(loadavg, 3);
+}
+#endif
+
 #ifdef TEST_KWSYS_CXX_HAS_RLIMIT64
 # if defined(KWSYS_HAS_LFS)
 #  define _LARGEFILE_SOURCE
diff --git a/testSystemInformation.cxx b/testSystemInformation.cxx
index 53d51ac..fc8ea55 100644
--- a/testSystemInformation.cxx
+++ b/testSystemInformation.cxx
@@ -87,6 +87,7 @@ int testSystemInformation(int, char*[])
   printMethod3(info, GetProcMemoryAvailable("KWSHL","KWSPL"), "KiB");
   printMethod3(info, GetHostMemoryUsed(), "KiB");
   printMethod3(info, GetProcMemoryUsed(), "KiB");
+  printMethod(info, GetLoadAverage);
 
   for (long int i = 0; i <= 31; i++)
     {

-----------------------------------------------------------------------

Summary of changes:
 Source/kwsys/CMakeLists.txt            |    9 +++
 Source/kwsys/SystemInformation.cxx     |   98 ++++++++++++++++++++++++++++++++
 Source/kwsys/SystemInformation.hxx.in  |    4 ++
 Source/kwsys/kwsysPlatformTestsCXX.cxx |   13 +++++
 Source/kwsys/testSystemInformation.cxx |    1 +
 5 files changed, 125 insertions(+)


hooks/post-receive
-- 
CMake


More information about the Cmake-commits mailing list