Skip to content
This repository was archived by the owner on Jun 15, 2023. It is now read-only.

Commit 94c10a6

Browse files
committed
Implement GetLoadAverage on AIX using libperfstat
1 parent 164e7f9 commit 94c10a6

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

configure.py

+3
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,9 @@ def has_re2c():
505505
else:
506506
libs.append('-lninja')
507507

508+
if platform.is_aix():
509+
libs.append('-lperfstat')
510+
508511
all_targets = []
509512

510513
n.comment('Main executable is library plus main() function.')

src/util.cc

+12
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@
4545
#elif defined(__SVR4) && defined(__sun)
4646
#include <unistd.h>
4747
#include <sys/loadavg.h>
48+
#elif defined(_AIX)
49+
#include <libperfstat.h>
4850
#elif defined(linux) || defined(__GLIBC__)
4951
#include <sys/sysinfo.h>
5052
#endif
@@ -573,6 +575,16 @@ double GetLoadAverage() {
573575

574576
return posix_compatible_load;
575577
}
578+
#elif defined(_AIX)
579+
double GetLoadAverage() {
580+
perfstat_cpu_total_t cpu_stats;
581+
if (perfstat_cpu_total(NULL, &cpu_stats, sizeof(cpu_stats), 1) < 0) {
582+
return -0.0f;
583+
}
584+
585+
// Calculation taken from comment in libperfstats.h
586+
return double(cpu_stats.loadavg[0]) / double(1 << SBITS);
587+
}
576588
#else
577589
double GetLoadAverage() {
578590
double loadavg[3] = { 0.0f, 0.0f, 0.0f };

0 commit comments

Comments
 (0)