From f1b5d2bf37ba6cd10bf7ab4b51877d68eae97cbc Mon Sep 17 00:00:00 2001
From: Colin Cross <ccross@android.com>
Date: Thu, 28 Apr 2016 12:32:31 -0700
Subject: Fix NINJA_STATUS %e on dumb terminals

PR #999 made dumb terminals only output when edges
finish. BuildStatus::overall_rate_ stopwatch is only initialized to the
current time when PrintStatus is called with finished_edges_ == 0, but
on a dumb terminal it will be called for the first time when
finished_edge_ = 1, which results in very long elapsed times:
NINJA_STATUS="[%r processes, %f/%t @ %o/s : %es ] "
[0 processes, 2/2 @ 0.0/s : 1461869902.367s ]

Reset the stopwatches in BuildEdgeFinished before finshed_edges_ is
incremented instead.
---
 src/build.cc | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/src/build.cc b/src/build.cc
index 8c0fbf8..2c39636 100644
--- a/src/build.cc
+++ b/src/build.cc
@@ -109,6 +109,12 @@ void BuildStatus::BuildEdgeFinished(Edge* edge,
                                     int* start_time,
                                     int* end_time) {
   int64_t now = GetTimeMillis();
+
+  if (finished_edges_  == 0) {
+    overall_rate_.Restart();
+    current_rate_.Restart();
+  }
+
   ++finished_edges_;
 
   RunningEdgeMap::iterator i = running_edges_.find(edge);
@@ -256,10 +262,6 @@ void BuildStatus::PrintStatus(Edge* edge) {
   if (to_print.empty() || force_full_command)
     to_print = edge->GetBinding("command");
 
-  if (finished_edges_ == 0) {
-    overall_rate_.Restart();
-    current_rate_.Restart();
-  }
   to_print = FormatProgressStatus(progress_status_format_) + to_print;
 
   printer_.Print(to_print,
-- 
cgit v0.12