Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add remaining time estimate to Ninja status. #1602

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/manual.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ Several placeholders are available:
`%c`:: Current rate of finished edges per second (average over builds
specified by `-j` or its default)
`%e`:: Elapsed time in seconds. _(Available since Ninja 1.2.)_
`%h`:: Estimated time remaining. _(Available since Ninja 1.10.)_
`%%`:: A plain `%` character.

The default progress status is `"[%f/%t] "` (note the trailing space
Expand Down
22 changes: 22 additions & 0 deletions src/build.cc
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,28 @@ string BuildStatus::FormatProgressStatus(
break;
}

case 'h': {
double ratio_finished = double(finished_edges_) / total_edges_;
if (overall_rate_.Elapsed() < 1.0 || ratio_finished < 0.01) {
snprintf(buf, sizeof(buf), "--m --s");
} else {
double time_remaining =
(1.0 / ratio_finished - 1) * overall_rate_.Elapsed();
int hours = int(time_remaining) / 3600;
int minutes = (int(time_remaining) % 3600) / 60;
int seconds = int(time_remaining) % 60;
if (hours > 0) {
snprintf(buf, sizeof(buf), "%dh %dm", hours, minutes);
} else if (minutes > 0) {
snprintf(buf, sizeof(buf), "%dm %ds", minutes, seconds);
} else {
snprintf(buf, sizeof(buf), "%ds", seconds);
}
}
out += buf;
break;
}

default:
Fatal("unknown placeholder '%%%c' in $NINJA_STATUS", *s);
return "";
Expand Down