aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Klaus Aehlig <aehlig@google.com>2016-06-17 14:59:40 +0000
committerGravatar Philipp Wollermann <philwo@google.com>2016-06-20 09:34:26 +0000
commit9cf9300d667b8b5671077c73bc29b4803c95c340 (patch)
tree57845fe283fb1b07c1c4e6ab40e3ab48b31a3e61
parent0b26b425cc7927990e26a989e6ec3748d5b3ef76 (diff)
experimental UI: delay updates after action completion
Very often, when an action completes, a new one is started directly afterwards. With this in mind, delay the refresh after the completion of an action as long as acceptable by the refresh rate limiting. If indeed an action starts within that time, we have replaced a double refresh of the progress bar by a single one, thus make it appear less flickering. -- Change-Id: I0e9143d6bba9929265ad2b6a3699486a1d5b3b2b Reviewed-on: https://bazel-review.googlesource.com/#/c/3823 MOS_MIGRATED_REVID=125165516
-rw-r--r--src/main/java/com/google/devtools/build/lib/runtime/ExperimentalEventHandler.java28
1 files changed, 26 insertions, 2 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 b8216752e9..99b92fc841 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
@@ -64,6 +64,7 @@ public class ExperimentalEventHandler extends BlazeCommandEventHandler {
private final long minimalUpdateInterval;
private final boolean showProgress;
private long lastRefreshMillis;
+ private long mustRefreshAfterMillis;
private int numLinesProgressBar;
private boolean buildComplete;
private boolean progressBarNeedsRefresh;
@@ -287,7 +288,7 @@ public class ExperimentalEventHandler extends BlazeCommandEventHandler {
@Subscribe
public void actionCompletion(ActionCompletionEvent event) {
stateTracker.actionCompletion(event);
- refresh();
+ refreshSoon();
}
@Subscribe
@@ -351,7 +352,7 @@ public class ExperimentalEventHandler extends BlazeCommandEventHandler {
LOG.warning("IO Error writing to output stream: " + e);
}
}
- if (!stateTracker.progressBarTimeDependent()) {
+ if (!stateTracker.progressBarTimeDependent() && mustRefreshAfterMillis < lastRefreshMillis) {
stopUpdateThread();
}
} else {
@@ -362,6 +363,18 @@ public class ExperimentalEventHandler extends BlazeCommandEventHandler {
}
}
+ private void refreshSoon() {
+ // Schedule an update of the progress bar in the near future, unless there is already
+ // a future update scheduled.
+ long nowMillis = clock.currentTimeMillis();
+ synchronized (this) {
+ if (mustRefreshAfterMillis <= lastRefreshMillis) {
+ mustRefreshAfterMillis = Math.max(nowMillis + minimalUpdateInterval, lastRefreshMillis + 1);
+ }
+ }
+ startUpdateThread();
+ }
+
/**
* Decide wheter the progress bar should be redrawn only for the reason
* that time has passed.
@@ -372,6 +385,13 @@ public class ExperimentalEventHandler extends BlazeCommandEventHandler {
}
long nowMillis = clock.currentTimeMillis();
long intervalMillis = cursorControl ? SHORT_REFRESH_MILLIS : LONG_REFRESH_MILLIS;
+ if (lastRefreshMillis < mustRefreshAfterMillis
+ && mustRefreshAfterMillis < nowMillis + minimalDelayMillis) {
+ // Within the a smal interval from now, an update is scheduled anyway,
+ // so don't do a time-based update of the progress bar now, to avoid
+ // updates too close to each other.
+ return false;
+ }
return lastRefreshMillis + intervalMillis < nowMillis;
}
@@ -394,6 +414,10 @@ public class ExperimentalEventHandler extends BlazeCommandEventHandler {
try {
while (true) {
Thread.sleep(minimalUpdateInterval);
+ if (lastRefreshMillis < mustRefreshAfterMillis
+ && mustRefreshAfterMillis < clock.currentTimeMillis()) {
+ progressBarNeedsRefresh = true;
+ }
eventHandler.doRefresh();
}
} catch (InterruptedException e) {