Implement GetLoadAverage on AIX using libperfstat
authorMike Seplowitz <mseplowitz@bloomberg.net>
Tue, 13 Jan 2015 01:48:07 +0000 (20:48 -0500)
committerMike Seplowitz <mseplowitz@bloomberg.net>
Wed, 19 Aug 2015 12:43:58 +0000 (08:43 -0400)
configure.py
src/util.cc

index f9ea8eb..fcea72a 100755 (executable)
@@ -505,6 +505,9 @@ if platform.is_msvc():
 else:
     libs.append('-lninja')
 
+if platform.is_aix():
+    libs.append('-lperfstat')
+
 all_targets = []
 
 n.comment('Main executable is library plus main() function.')
index aa47f2f..d150fe2 100644 (file)
@@ -45,6 +45,8 @@
 #elif defined(__SVR4) && defined(__sun)
 #include <unistd.h>
 #include <sys/loadavg.h>
+#elif defined(_AIX)
+#include <libperfstat.h>
 #elif defined(linux) || defined(__GLIBC__)
 #include <sys/sysinfo.h>
 #endif
@@ -573,6 +575,16 @@ double GetLoadAverage() {
 
   return posix_compatible_load;
 }
+#elif defined(_AIX)
+double GetLoadAverage() {
+  perfstat_cpu_total_t cpu_stats;
+  if (perfstat_cpu_total(NULL, &cpu_stats, sizeof(cpu_stats), 1) < 0) {
+    return -0.0f;
+  }
+
+  // Calculation taken from comment in libperfstats.h
+  return double(cpu_stats.loadavg[0]) / double(1 << SBITS);
+}
 #else
 double GetLoadAverage() {
   double loadavg[3] = { 0.0f, 0.0f, 0.0f };