20 #ifndef __STDC_FORMAT_MACROS
21 #define __STDC_FORMAT_MACROS
45 : config_(config), started_edges_(0), finished_edges_(0), total_edges_(0),
46 running_edges_(0), progress_status_format_(NULL),
47 current_rate_(config.parallelism) {
119 double actual_average_cpu_time_millis =
122 double previous_average_cpu_time_millis =
126 double ratio = std::max(previous_average_cpu_time_millis,
127 actual_average_cpu_time_millis) /
128 std::min(previous_average_cpu_time_millis,
129 actual_average_cpu_time_millis);
132 use_previous_times = ratio < 10;
136 if (use_previous_times)
138 if (edges_with_known_runtime == 0)
141 int edges_with_unknown_runtime = use_previous_times
149 if (use_previous_times)
150 edges_known_runtime_total_millis +=
153 double average_cpu_time_millis =
154 (double)edges_known_runtime_total_millis / edges_with_known_runtime;
159 double unpredictable_cpu_time_remaining_millis =
160 average_cpu_time_millis * edges_with_unknown_runtime;
163 double total_cpu_time_remaining_millis =
164 unpredictable_cpu_time_remaining_millis;
165 if (use_previous_times)
166 total_cpu_time_remaining_millis +=
168 double total_cpu_time_millis =
170 if (total_cpu_time_millis == 0.0)
179 const string& output) {
183 int64_t elapsed = end_time_millis - start_time_millis;
208 for (vector<Node*>::const_iterator o = edge->
outputs_.begin();
210 outputs += (*o)->path() +
" ";
212 string failed =
"FAILED: [code=" + std::to_string(exit_code) +
"] ";
221 if (!output.empty()) {
225 _setmode(_fileno(stdout), _O_BINARY);
248 _setmode(_fileno(stdout), _O_TEXT);
268 for (
const char* s = progress_status_format; *s !=
'\0'; ++s) {
325 snprintf(buf,
sizeof(buf),
"%3i%%", percent);
330 #define FORMAT_TIME_HMMSS(t) \
331 "%" PRId64 ":%02" PRId64 ":%02" PRId64 "", (t) / 3600, ((t) % 3600) / 60, \
333 #define FORMAT_TIME_MMSS(t) "%02" PRId64 ":%02" PRId64 "", (t) / 60, (t) % 60
352 const bool print_with_hours =
353 elapsed_sec >= 60 * 60 || eta_sec >= 60 * 60;
368 snprintf(buf,
sizeof(buf),
"?");
373 snprintf(buf,
sizeof(buf),
"%.3f", sec);
377 if (print_with_hours)
390 snprintf(buf,
sizeof(buf),
"%3i%%",
397 Fatal(
"unknown placeholder '%%%c' in $NINJA_STATUS", *s);
411 std::vector<std::string> explanations;
415 if (!explanations.empty()) {
419 for (
const auto& exp : explanations) {
420 fprintf(stderr,
"ninja explain: %s\n", exp.c_str());
433 string to_print = edge->
GetBinding(
"description");
434 if (to_print.empty() || force_full_command)
#define FORMAT_TIME_HMMSS(t)
#define FORMAT_TIME_MMSS(t)
Options (e.g. verbosity, parallelism) passed to a build.
An edge in the dependency graph; links between Nodes using Rules.
int64_t prev_elapsed_time_millis
std::string GetBinding(const std::string &key) const
Returns the shell-escaped value of |key|.
std::vector< Node * > outputs_
std::string EvaluateCommand(bool incl_rsp_file=false) const
Expand all variables in a command and return it as a string.
void LookupAndAppend(const void *item, std::vector< std::string > *out)
Lookup the explanations recorded for |item|, and append them to |*out|, if any.
void set_smart_terminal(bool smart)
void Print(std::string to_print, LineType type)
Overprints the current line.
void SetConsoleLocked(bool locked)
Lock or unlock the console.
bool supports_color() const
bool is_smart_terminal() const
void PrintOnNewLine(const std::string &to_print)
Prints a string on a new line, not overprinting previous output.
Information about a node in the dependency graph: the file, whether it's dirty, mtime,...
void UpdateRate(int update_hint, int64_t time_millis)
Implementation of the Status interface that prints the status as human-readable strings to stdout.
void PrintStatus(const Edge *edge, int64_t time_millis)
void BuildEdgeStarted(const Edge *edge, int64_t start_time_millis) override
int64_t cpu_time_millis_
How much cpu clock elapsed so far?
void Warning(const char *msg,...) override
void BuildFinished() override
SlidingRateInfo current_rate_
LinePrinter printer_
Prints progress output.
void Error(const char *msg,...) override
void EdgeAddedToPlan(const Edge *edge) override
Callbacks for the Plan to notify us about adding/removing Edge's.
void EdgeRemovedFromPlan(const Edge *edge) override
int64_t time_millis_
How much wall clock elapsed so far?
const char * progress_status_format_
The custom progress status format to use.
void BuildEdgeFinished(Edge *edge, int64_t start_time_millis, int64_t end_time_millis, ExitStatus exit_code, const std::string &output) override
void SnprintfRate(double rate, char(&buf)[S], const char *format) const
int eta_predictable_edges_total_
Out of all the edges, for how many do we know previous time?
int eta_unpredictable_edges_remaining_
For how many edges we don't know the previous run time?
void Info(const char *msg,...) override
int64_t eta_predictable_cpu_time_total_millis_
And how much time did they all take?
void RecalculateProgressPrediction()
StatusPrinter(const BuildConfig &config)
int eta_predictable_edges_remaining_
Out of all the non-finished edges, for how many do we know previous time?
void BuildStarted() override
const BuildConfig & config_
int64_t eta_predictable_cpu_time_remaining_millis_
And how much time will they all take?
std::string FormatProgressStatus(const char *progress_status_format, int64_t time_millis) const
Format the progress status string by replacing the placeholders.
double time_predicted_percentage_
What percentage of predicted total time have elapsed already?
Explanations * explanations_
An optional Explanations pointer, used to implement -d explain.
Abstract interface to object that tracks the status of a build: completion fraction,...
static Status * factory(const BuildConfig &)
creates the actual implementation
string StripAnsiEscapeCodes(const string &in)
void Fatal(const char *msg,...)
Log a fatal message and exit.
signed long long int64_t
A 64-bit integer type.