aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/runtime/ExperimentalEventHandler.java
diff options
context:
space:
mode:
authorGravatar Klaus Aehlig <aehlig@google.com>2016-04-11 14:01:27 +0000
committerGravatar Dmitry Lomov <dslomov@google.com>2016-04-12 13:57:29 +0000
commitbf066be6d1f8166101807ff94772bbeffe0252da (patch)
tree541031cbfd94001e3f59b1eb41e497286ffe21cd /src/main/java/com/google/devtools/build/lib/runtime/ExperimentalEventHandler.java
parentd17e6b8f79a9f86fd18b102a8a7db0bbe2dd61d0 (diff)
Keep output of experimental UI short if curses cannot be used
As the experimental UI should be usable in all situations, we also have to care about the situation where updating the status bar in place is not possible. In this case, we have to make sure we do not litter the output to much. To achieve this, - we use the short one-line version of the status bar, and - reduce the frequency for time-based updates. Unfortunately, this means that we have to further complicate the timing mechanisms for updating the progress bar. We now have 3 time intervals in place: - a short one, after which we update the progress bar, if we dropped an update due to too frequent events, - an intermediate one, describing the frequency of status bar updates due to time passing, and - a long one for purely time-based updates of the progress bar if we cannot update it in place. -- Change-Id: I5d59ba174c4d290b07181620e238362a8d21a6eb Reviewed-on: https://bazel-review.googlesource.com/#/c/3295 MOS_MIGRATED_REVID=119527089
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/runtime/ExperimentalEventHandler.java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/runtime/ExperimentalEventHandler.java25
1 files changed, 22 insertions, 3 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/runtime/ExperimentalEventHandler.java b/src/main/java/com/google/devtools/build/lib/runtime/ExperimentalEventHandler.java
index b852de611a..052d6cbb44 100644
--- a/src/main/java/com/google/devtools/build/lib/runtime/ExperimentalEventHandler.java
+++ b/src/main/java/com/google/devtools/build/lib/runtime/ExperimentalEventHandler.java
@@ -42,6 +42,12 @@ import java.util.logging.Logger;
*/
public class ExperimentalEventHandler extends BlazeCommandEventHandler {
private static Logger LOG = Logger.getLogger(ExperimentalEventHandler.class.getName());
+ /** Latest refresh of the progress bar, if contents other than time changed */
+ static final long MAXIMAL_UPDATE_DELAY_MILLIS = 200L;
+ /** Periodic update interval of a time-dependent progress bar if it can be updated in place */
+ static final long SHORT_REFRESH_MILLIS = 1000L;
+ /** Periodic update interval of a time-dependent progress bar if it cannot be updated in place */
+ static final long LONG_REFRESH_MILLIS = 5000L;
private final long minimalDelayMillis;
private final boolean cursorControl;
@@ -69,7 +75,7 @@ public class ExperimentalEventHandler extends BlazeCommandEventHandler {
this.stateTracker = new ExperimentalStateTracker(clock);
this.numLinesProgressBar = 0;
this.minimalDelayMillis = Math.round(options.showProgressRateLimit * 1000);
- this.minimalUpdateInterval = Math.max(this.minimalDelayMillis, 1000L);
+ this.minimalUpdateInterval = Math.max(this.minimalDelayMillis, MAXIMAL_UPDATE_DELAY_MILLIS);
// The progress bar has not been updated yet.
ignoreRefreshLimitOnce();
}
@@ -229,7 +235,7 @@ public class ExperimentalEventHandler extends BlazeCommandEventHandler {
long nowMillis = clock.currentTimeMillis();
if (lastRefreshMillis + minimalDelayMillis < nowMillis) {
try {
- if (progressBarNeedsRefresh || stateTracker.progressBarTimeDependent()) {
+ if (progressBarNeedsRefresh || timeBasedRefresh()) {
progressBarNeedsRefresh = false;
lastRefreshMillis = nowMillis;
clearProgressBar();
@@ -250,6 +256,19 @@ public class ExperimentalEventHandler extends BlazeCommandEventHandler {
}
}
+ /**
+ * Decide wheter the progress bar should be redrawn only for the reason
+ * that time has passed.
+ */
+ private synchronized boolean timeBasedRefresh () {
+ if (!stateTracker.progressBarTimeDependent()) {
+ return false;
+ }
+ long nowMillis = clock.currentTimeMillis();
+ long intervalMillis = cursorControl ? SHORT_REFRESH_MILLIS : LONG_REFRESH_MILLIS;
+ return lastRefreshMillis + intervalMillis < nowMillis;
+ }
+
private void ignoreRefreshLimitOnce() {
// Set refresh time variables in a state such that the next progress bar
// update will definitely be written out.
@@ -322,7 +341,7 @@ public class ExperimentalEventHandler extends BlazeCommandEventHandler {
if (cursorControl) {
terminalWriter = new LineWrappingAnsiTerminalWriter(terminalWriter, terminalWidth - 1);
}
- stateTracker.writeProgressBar(terminalWriter);
+ stateTracker.writeProgressBar(terminalWriter, /* shortVersion=*/ !cursorControl);
terminalWriter.newline();
numLinesProgressBar = countingTerminalWriter.getWrittenLines();
}