summaryrefslogtreecommitdiffstats
path: root/src/util.cc
diff options
context:
space:
mode:
authorNicolas Despres <nicolas.despres@gmail.com>2012-04-05 13:44:36 (GMT)
committerNicolas Despres <nicolas.despres@gmail.com>2012-04-19 13:29:26 (GMT)
commitb50f7d1f30991998564f62aa717862efb7555044 (patch)
tree95161e6f0fd8c201ac5bc30c0fb5bd4796ba90ce /src/util.cc
parent5da8529d9c0e5fa2ad586c0608b5a936286cf9a2 (diff)
downloadNinja-b50f7d1f30991998564f62aa717862efb7555044.zip
Ninja-b50f7d1f30991998564f62aa717862efb7555044.tar.gz
Ninja-b50f7d1f30991998564f62aa717862efb7555044.tar.bz2
Add -l N option to limit the load average.
This is similar to GNU make -l/--load-average option. It limits the number of job started if the load average exceed the given value. It can be very useful when running ninja on a continuous integration server where we want to use parallelism as much as possible without overloading the server.
Diffstat (limited to 'src/util.cc')
-rw-r--r--src/util.cc29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/util.cc b/src/util.cc
index c88dc4e..73f13f8 100644
--- a/src/util.cc
+++ b/src/util.cc
@@ -293,3 +293,32 @@ string StripAnsiEscapeCodes(const string& in) {
}
return stripped;
}
+
+#ifdef _WIN32
+static double GetLoadAverage_win32()
+{
+ // TODO(nicolas.despres@gmail.com): Find a way to implement it on Windows.
+ return -0.0f;
+}
+#else
+static double GetLoadAverage_unix()
+{
+ double loadavg[3] = { 0.0f, 0.0f, 0.0f };
+ if (getloadavg(loadavg, 3) < 0)
+ {
+ // Maybe we should return an error here or the availability of
+ // getloadavg(3) should be checked when ninja is configured.
+ return -0.0f;
+ }
+ return loadavg[0];
+}
+#endif // _WIN32
+
+double GetLoadAverage()
+{
+#ifdef _WIN32
+ return GetLoadAverage_win32();
+#else
+ return GetLoadAverage_unix();
+#endif // _WIN32
+}