소스 검색

Only display a progress meter once we spend 0.5 seconds on a task

The point of the progress meter is to let the user know that the
task is progressing, and give them a chance to estimate when it will
be complete.  If the task completes in under 0.5 seconds then it
is sufficiently fast enough that the user doesn't need to be kept
up-to-date on its progress; in fact showing the meter may just slow
the task down waiting on the tty to redraw.

We now delay the progress meter 0.5 seconds (or 1 second if the
Python time.time() function isn't accurate enough) to avoid any
really fast tasks, like a no-op local sync.

Signed-off-by: Shawn O. Pearce <sop@google.com>
Shawn O. Pearce 17 년 전
부모
커밋
2810cbc778
1개의 변경된 파일10개의 추가작업 그리고 1개의 파일을 삭제
  1. 10 1
      progress.py

+ 10 - 1
progress.py

@@ -14,6 +14,7 @@
 # limitations under the License.
 
 import sys
+from time import time
 from trace import IsTrace
 
 class Progress(object):
@@ -22,6 +23,8 @@ class Progress(object):
     self._total = total
     self._done = 0
     self._lastp = -1
+    self._start = time()
+    self._show = False
 
   def update(self, inc=1):
     self._done += inc
@@ -29,6 +32,12 @@ class Progress(object):
     if IsTrace():
       return
 
+    if not self._show:
+      if 0.5 <= time() - self._start:
+        self._show = True
+      else:
+        return
+
     if self._total <= 0:
       sys.stderr.write('\r%s: %d, ' % (
         self._title,
@@ -47,7 +56,7 @@ class Progress(object):
         sys.stderr.flush()
 
   def end(self):
-    if IsTrace():
+    if IsTrace() or not self._show:
       return
 
     if self._total <= 0: