summaryrefslogtreecommitdiffstats
path: root/src/ninja.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/ninja.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/ninja.cc')
-rw-r--r--src/ninja.cc13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/ninja.cc b/src/ninja.cc
index 7d020db..e149f98 100644
--- a/src/ninja.cc
+++ b/src/ninja.cc
@@ -84,6 +84,7 @@ void Usage(const BuildConfig& config) {
" -f FILE specify input build file [default=build.ninja]\n"
"\n"
" -j N run N jobs in parallel [default=%d]\n"
+" -l N do not start new jobs if the load average is greater than N\n"
" -k N keep going until N jobs fail [default=1]\n"
" -n dry run (don't run commands but pretend they succeeded)\n"
" -v show all command lines while building\n"
@@ -633,7 +634,7 @@ int main(int argc, char** argv) {
int opt;
while (tool.empty() &&
- (opt = getopt_long(argc, argv, "d:f:hj:k:nt:vC:", kLongOptions,
+ (opt = getopt_long(argc, argv, "d:f:hj:k:l:nt:vC:", kLongOptions,
NULL)) != -1) {
switch (opt) {
case 'd':
@@ -646,11 +647,19 @@ int main(int argc, char** argv) {
case 'j':
globals.config.parallelism = atoi(optarg);
break;
+ case 'l': {
+ char* end;
+ double value = strtod(optarg, &end);
+ if (end == optarg)
+ Fatal("-l parameter not numeric: did you mean -l 0.0?");
+ globals.config.max_load_average = value;
+ break;
+ }
case 'k': {
char* end;
int value = strtol(optarg, &end, 10);
if (*end != 0)
- Fatal("-k parameter not numeric; did you mean -k0?");
+ Fatal("-k parameter not numeric; did you mean -k 0?");
// We want to go until N jobs fail, which means we should allow
// N failures and then stop. For N <= 0, INT_MAX is close enough