Skip to content

Commit

Permalink
If we are waiting for only one edge, print status for that edge
Browse files Browse the repository at this point in the history
With this patch, should the build stall, it should be clear what edge is responsible.

The patch introduces BuildStatus::last_edge_status_ to keep track of the last edge we printed status for. This is to avoid printing status for the same edge twice, which is mainly when the output doesn’t overwrite previously printed output (non-smart terminal).

It would be better to delay re-printing status until we have waited a certain amount of time, which would also allow us to handle the case where more than one edge is stalling the build, but this require some refactoring, as waiting for tasks is presently done without the ability to specify a timeout.
  • Loading branch information
sorbits committed Aug 2, 2013
1 parent 294e81e commit 7831cb8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/build.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ BuildStatus::BuildStatus(const BuildConfig& config)
: config_(config),
start_time_millis_(GetTimeMillis()),
started_edges_(0), finished_edges_(0), total_edges_(0),
last_edge_status_(0),
progress_status_format_(NULL),
overall_rate_(), current_rate_(config.parallelism) {

Expand All @@ -98,6 +99,15 @@ void BuildStatus::BuildEdgeStarted(Edge* edge) {
PrintStatus(edge);
}

void BuildStatus::PrintBuildEdgeStatus() {
if (running_edges_.size() == 1) {
Edge* running_edge = running_edges_.begin()->first;
if(last_edge_status_ != running_edge) {
PrintStatus(running_edge);
}
}
}

void BuildStatus::BuildEdgeFinished(Edge* edge,
bool success,
const string& output,
Expand All @@ -117,6 +127,9 @@ void BuildStatus::BuildEdgeFinished(Edge* edge,
if (printer_.is_smart_terminal())
PrintStatus(edge);

if (last_edge_status_ == edge)
last_edge_status_ = 0;

// Print the command that is spewing before printing its output.
if (!success)
printer_.PrintOnNewLine("FAILED: " + edge->EvaluateCommand() + "\n");
Expand Down Expand Up @@ -248,6 +261,7 @@ void BuildStatus::PrintStatus(Edge* edge) {

printer_.Print(to_print,
force_full_command ? LinePrinter::FULL : LinePrinter::ELIDE);
last_edge_status_ = edge;
}

Plan::Plan() : command_edges_(0), wanted_edges_(0) {}
Expand Down Expand Up @@ -630,6 +644,8 @@ bool Builder::Build(string* err) {

// See if we can reap any finished commands.
if (pending_commands) {
status_->PrintBuildEdgeStatus();

CommandRunner::Result result;
if (!command_runner_->WaitForCommand(&result) ||
result.status == ExitInterrupted) {
Expand Down
2 changes: 2 additions & 0 deletions src/build.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ struct BuildStatus {
explicit BuildStatus(const BuildConfig& config);
void PlanHasTotalEdges(int total);
void BuildEdgeStarted(Edge* edge);
void PrintBuildEdgeStatus();
void BuildEdgeFinished(Edge* edge, bool success, const string& output,
int* start_time, int* end_time);
void BuildFinished();
Expand All @@ -219,6 +220,7 @@ struct BuildStatus {
/// Map of running edge to time the edge started running.
typedef map<Edge*, int> RunningEdgeMap;
RunningEdgeMap running_edges_;
Edge* last_edge_status_;

/// Prints progress output.
LinePrinter printer_;
Expand Down

0 comments on commit 7831cb8

Please sign in to comment.