Skip to content

Commit

Permalink
Symmetry: Make critical-path scheduler opt-in via --cp switch
Browse files Browse the repository at this point in the history
  • Loading branch information
kinke committed Jul 29, 2023
1 parent dd39592 commit 33deebe
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/build.cc
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,8 @@ bool Builder::AlreadyUpToDate() const {

bool Builder::Build(string* err) {
assert(!AlreadyUpToDate());
plan_.PrepareQueue(scan_.build_log());
plan_.PrepareQueue(config_.enable_critical_path_scheduler ? scan_.build_log()
: NULL);

status_->PlanHasTotalEdges(plan_.command_edge_count());
int pending_commands = 0;
Expand Down
6 changes: 4 additions & 2 deletions src/build.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,9 @@ struct CommandRunner {

/// Options (e.g. verbosity, parallelism) passed to a build.
struct BuildConfig {
BuildConfig() : verbosity(NORMAL), dry_run(false), parallelism(1),
failures_allowed(1), max_load_average(-0.0f) {}
BuildConfig()
: verbosity(NORMAL), dry_run(false), parallelism(1), failures_allowed(1),
max_load_average(-0.0f), enable_critical_path_scheduler(false) {}

enum Verbosity {
QUIET, // No output -- used when testing.
Expand All @@ -182,6 +183,7 @@ struct BuildConfig {
/// means that we do not have any limit.
double max_load_average;
DepfileParserOptions depfile_parser_options;
bool enable_critical_path_scheduler;
};

/// Builder wraps the build process: starting commands, updating status.
Expand Down
8 changes: 7 additions & 1 deletion src/ninja.cc
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ void Usage(const BuildConfig& config) {
" --version print ninja version (\"%s\")\n"
" -v, --verbose show all command lines while building\n"
" --quiet don't show progress status, just command output\n"
" --cp enable critical-path scheduler based on previous build times\n"
" (schedule slowest targets first; may require huge peak RAM!)\n"
"\n"
" -C DIR change to DIR before doing anything else\n"
" -f FILE specify input build file [default=build.ninja]\n"
Expand Down Expand Up @@ -1417,12 +1419,13 @@ int ReadFlags(int* argc, char*** argv,
Options* options, BuildConfig* config) {
DeferGuessParallelism deferGuessParallelism(config);

enum { OPT_VERSION = 1, OPT_QUIET = 2 };
enum { OPT_VERSION = 1, OPT_QUIET = 2, OPT_ENABLE_CP = 3 };
const option kLongOptions[] = {
{ "help", no_argument, NULL, 'h' },
{ "version", no_argument, NULL, OPT_VERSION },
{ "verbose", no_argument, NULL, 'v' },
{ "quiet", no_argument, NULL, OPT_QUIET },
{ "cp", no_argument, NULL, OPT_ENABLE_CP },
{ NULL, 0, NULL, 0 }
};

Expand Down Expand Up @@ -1494,6 +1497,9 @@ int ReadFlags(int* argc, char*** argv,
case OPT_VERSION:
printf("%s\n", kNinjaVersion);
return 0;
case OPT_ENABLE_CP:
config->enable_critical_path_scheduler = true;
break;
case 'h':
default:
deferGuessParallelism.Refresh();
Expand Down

0 comments on commit 33deebe

Please sign in to comment.