diff --git a/src/build.cc b/src/build.cc index 50ae716ac2..5b6e94bb31 100644 --- a/src/build.cc +++ b/src/build.cc @@ -79,7 +79,7 @@ bool DryRunCommandRunner::WaitForCommand(Result* result) { BuildStatus::BuildStatus(const BuildConfig& config) : config_(config), - started_edges_(0), finished_edges_(0), total_edges_(0), + started_edges_(0), finished_edges_(0), total_edges_(0), running_edges_(0), time_millis_(0), progress_status_format_(NULL), current_rate_(config.parallelism) { @@ -101,7 +101,7 @@ void BuildStatus::BuildEdgeStarted(Edge* edge, int64_t start_time_millis) { time_millis_ = start_time_millis; if (edge->use_console() || printer_.is_smart_terminal()) - PrintStatus(edge, start_time_millis, kEdgeStarted); + PrintStatus(edge, start_time_millis); if (edge->use_console()) printer_.SetConsoleLocked(true); @@ -120,7 +120,12 @@ void BuildStatus::BuildEdgeFinished(Edge* edge, int64_t end_time_millis, return; if (!edge->use_console()) - PrintStatus(edge, end_time_millis, kEdgeFinished); + PrintStatus(edge, end_time_millis); + + // Update running_edges_ after PrintStatus so that the number of running + // edges doesn't oscillate between config.parallelism_ and + // config.parallelism_ - 1. + --running_edges_; // Print the command that is spewing before printing its output. if (!success) { @@ -183,6 +188,9 @@ void BuildStatus::BuildLoadDyndeps() { } void BuildStatus::BuildStarted() { + started_edges_ = 0; + finished_edges_ = 0; + running_edges_ = 0; } void BuildStatus::BuildFinished() { @@ -191,7 +199,7 @@ void BuildStatus::BuildFinished() { } string BuildStatus::FormatProgressStatus( - const char* progress_status_format, int64_t time, EdgeStatus status) const { + const char* progress_status_format, int64_t time) const { string out; char buf[32]; for (const char* s = progress_status_format; *s != '\0'; ++s) { @@ -216,11 +224,7 @@ string BuildStatus::FormatProgressStatus( // Running edges. case 'r': { - int running_edges = started_edges_ - finished_edges_; - // count the edge that just finished as a running edge - if (status == kEdgeFinished) - running_edges++; - snprintf(buf, sizeof(buf), "%d", running_edges); + snprintf(buf, sizeof(buf), "%d", running_edges_); out += buf; break; } @@ -276,7 +280,7 @@ string BuildStatus::FormatProgressStatus( return out; } -void BuildStatus::PrintStatus(Edge* edge, int64_t time, EdgeStatus status) { +void BuildStatus::PrintStatus(Edge* edge, int64_t time) { if (config_.verbosity == BuildConfig::QUIET) return; @@ -286,7 +290,7 @@ void BuildStatus::PrintStatus(Edge* edge, int64_t time, EdgeStatus status) { if (to_print.empty() || force_full_command) to_print = edge->GetBinding("command"); - to_print = FormatProgressStatus(progress_status_format_, time, status) + to_print; + to_print = FormatProgressStatus(progress_status_format_, time) + to_print; printer_.Print(to_print, force_full_command ? LinePrinter::FULL : LinePrinter::ELIDE); diff --git a/src/build.h b/src/build.h index 8887dcbcc8..89988e09c6 100644 --- a/src/build.h +++ b/src/build.h @@ -252,25 +252,20 @@ struct BuildStatus { void BuildStarted(); void BuildFinished(); - enum EdgeStatus { - kEdgeStarted, - kEdgeFinished, - }; - /// Format the progress status string by replacing the placeholders. /// See the user manual for more information about the available /// placeholders. /// @param progress_status_format The format of the progress status. /// @param status The status of the edge. - string FormatProgressStatus(const char* progress_status_format, int64_t time, - EdgeStatus status) const; + string FormatProgressStatus(const char* progress_status_format, + int64_t time) const; private: - void PrintStatus(Edge* edge, int64_t time, EdgeStatus status); + void PrintStatus(Edge* edge, int64_t time); const BuildConfig& config_; - int started_edges_, finished_edges_, total_edges_; + int started_edges_, finished_edges_, total_edges_, running_edges_; int64_t time_millis_; /// Prints progress output. diff --git a/src/build_test.cc b/src/build_test.cc index 06df0592fe..81285d3e3f 100644 --- a/src/build_test.cc +++ b/src/build_test.cc @@ -1384,8 +1384,7 @@ TEST_F(BuildWithLogTest, RestatTest) { ASSERT_EQ("", err); EXPECT_TRUE(builder_.Build(&err)); ASSERT_EQ("", err); - EXPECT_EQ("[3/3]", builder_.status_->FormatProgressStatus("[%s/%t]", 0, - BuildStatus::kEdgeStarted)); + EXPECT_EQ("[3/3]", builder_.status_->FormatProgressStatus("[%s/%t]", 0)); command_runner_.commands_ran_.clear(); state_.Reset(); @@ -1827,14 +1826,12 @@ TEST_F(BuildTest, StatusFormatElapsed) { status_.BuildStarted(); // Before any task is done, the elapsed time must be zero. EXPECT_EQ("[%/e0.000]", - status_.FormatProgressStatus("[%%/e%e]", 0, - BuildStatus::kEdgeStarted)); + status_.FormatProgressStatus("[%%/e%e]", 0)); } TEST_F(BuildTest, StatusFormatReplacePlaceholder) { EXPECT_EQ("[%/s0/t0/r0/u0/f0]", - status_.FormatProgressStatus("[%%/s%s/t%t/r%r/u%u/f%f]", 0, - BuildStatus::kEdgeStarted)); + status_.FormatProgressStatus("[%%/s%s/t%t/r%r/u%u/f%f]", 0)); } TEST_F(BuildTest, FailedDepsParse) {