Skip to content

Commit fa29175

Browse files
aehligbuchgr
authored andcommitted
Experimental UI: increase progress rate limit with time, if no in-place update
In the experimental UI, increase the rate limit for updates to the progress bar over time, if it cannot be updated in place. In this way, we can get snappy first progress descriptions, while not overwhelming the user with too many progress messages. Change-Id: I769f1a9ef4304b613d40ece42b87df22881549cd PiperOrigin-RevId: 152502295
1 parent d6fec93 commit fa29175

1 file changed

Lines changed: 22 additions & 4 deletions

File tree

src/main/java/com/google/devtools/build/lib/runtime/ExperimentalEventHandler.java

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,13 @@ public class ExperimentalEventHandler implements EventHandler {
5454
private static Logger LOG = Logger.getLogger(ExperimentalEventHandler.class.getName());
5555
/** Latest refresh of the progress bar, if contents other than time changed */
5656
static final long MAXIMAL_UPDATE_DELAY_MILLIS = 200L;
57-
/** Minimal rate limiting, if the progress bar cannot be updated in place */
58-
static final long NO_CURSES_MINIMAL_PROGRESS_RATE_LIMIT = 2000L;
57+
/** Minimal rate limiting (in ms), if the progress bar cannot be updated in place */
58+
static final long NO_CURSES_MINIMAL_PROGRESS_RATE_LIMIT = 1000L;
59+
/**
60+
* Minimal rate limiting, as fraction of the request time so far, if the progress bar cannot be
61+
* updated in place
62+
*/
63+
static final double NO_CURSES_MINIMAL_RELATIVE_PROGRESS_RATE_LMIT = 0.15;
5964
/** Periodic update interval of a time-dependent progress bar if it can be updated in place */
6065
static final long SHORT_REFRESH_MILLIS = 1000L;
6166
/** Periodic update interval of a time-dependent progress bar if it cannot be updated in place */
@@ -64,17 +69,18 @@ public class ExperimentalEventHandler implements EventHandler {
6469
private static final DateTimeFormatter TIMESTAMP_FORMAT =
6570
DateTimeFormat.forPattern("(HH:mm:ss.SSS) ");
6671

67-
private final long minimalDelayMillis;
6872
private final boolean cursorControl;
6973
private final Clock clock;
74+
private final long uiStartTimeMillis;
7075
private final AnsiTerminal terminal;
7176
private final boolean debugAllEvents;
7277
private final ExperimentalStateTracker stateTracker;
73-
private final long minimalUpdateInterval;
7478
private final boolean showProgress;
7579
private final boolean progressInTermTitle;
7680
private final boolean showTimestamp;
7781
private final OutErr outErr;
82+
private long minimalDelayMillis;
83+
private long minimalUpdateInterval;
7884
private long lastRefreshMillis;
7985
private long mustRefreshAfterMillis;
8086
private int numLinesProgressBar;
@@ -96,6 +102,7 @@ public ExperimentalEventHandler(
96102
this.progressInTermTitle = options.progressInTermTitle && options.useCursorControl();
97103
this.showTimestamp = options.showTimestamp;
98104
this.clock = clock;
105+
this.uiStartTimeMillis = clock.currentTimeMillis();
99106
this.debugAllEvents = options.experimentalUiDebugAllEvents;
100107
// If we have cursor control, we try to fit in the terminal width to avoid having
101108
// to wrap the progress bar. We will wrap the progress bar to terminalWidth - 1
@@ -447,6 +454,17 @@ private void doRefresh(boolean fromUpdateThread) {
447454
clearProgressBar();
448455
addProgressBar();
449456
terminal.flush();
457+
if (!cursorControl) {
458+
// If we can't update the progress bar in place, make sure we increase the update
459+
// interval as time progresses, to avoid too many progress messages in place.
460+
minimalDelayMillis =
461+
Math.max(
462+
minimalDelayMillis,
463+
Math.round(
464+
NO_CURSES_MINIMAL_RELATIVE_PROGRESS_RATE_LMIT
465+
* (clock.currentTimeMillis() - uiStartTimeMillis)));
466+
minimalUpdateInterval = Math.max(minimalDelayMillis, MAXIMAL_UPDATE_DELAY_MILLIS);
467+
}
450468
}
451469
} catch (IOException e) {
452470
LOG.warning("IO Error writing to output stream: " + e);

0 commit comments

Comments
 (0)