diff options
author | Klaus Aehlig <aehlig@google.com> | 2016-06-21 08:44:15 +0000 |
---|---|---|
committer | Philipp Wollermann <philwo@google.com> | 2016-06-21 09:59:33 +0000 |
commit | cd211eebe4a2eb776ecf7ee65cc5954aa1110e48 (patch) | |
tree | c3f9359bc3c877c1b361acce402209df56f47d0e | |
parent | 7ec10f916afa89975a3451b2083591d9191cd615 (diff) |
Add an option for the number of actions shown in the experimental UI
Currently, the experimental UI always shows the 3 oldest, still running actions.
While this seems a reasonable default, some users requested to be able to change
the number of actions shown. Hence replace the hard-coded value by a flag.
While there, also fix an off-by-one error in deciding when to put the ellipsis
symbol.
--
Change-Id: I037d208360fa1d3f100c99ab1ab1f5fc140138ac
Reviewed-on: https://bazel-review.googlesource.com/#/c/3811
MOS_MIGRATED_REVID=125427168
4 files changed, 56 insertions, 3 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/runtime/BlazeCommandEventHandler.java b/src/main/java/com/google/devtools/build/lib/runtime/BlazeCommandEventHandler.java index 635a4561a0..85fb3fa45c 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/BlazeCommandEventHandler.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/BlazeCommandEventHandler.java @@ -157,6 +157,13 @@ public class BlazeCommandEventHandler implements EventHandler { ) public boolean experimentalUiDebugAllEvents; + @Option( + name = "experimental_ui_actions_shown", + defaultValue = "3", + category = "hidden", + help = "Number of concurrent actions shown in the experimental new Bazel UI." + ) + public int experimentalUiActionsShown; public boolean useColor() { return useColorEnum == UseColor.YES || (useColorEnum == UseColor.AUTO && isATty); 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 6ad3e531d0..2605cc277b 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 @@ -94,6 +94,7 @@ public class ExperimentalEventHandler extends BlazeCommandEventHandler { this.cursorControl ? new ExperimentalStateTracker(clock, this.terminalWidth - 2) : new ExperimentalStateTracker(clock); + this.stateTracker.setSampleSize(options.experimentalUiActionsShown); this.numLinesProgressBar = 0; this.minimalDelayMillis = Math.round(options.showProgressRateLimit * 1000); this.minimalUpdateInterval = Math.max(this.minimalDelayMillis, MAXIMAL_UPDATE_DELAY_MILLIS); diff --git a/src/main/java/com/google/devtools/build/lib/runtime/ExperimentalStateTracker.java b/src/main/java/com/google/devtools/build/lib/runtime/ExperimentalStateTracker.java index f5fb46d1bb..5343bfa19e 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/ExperimentalStateTracker.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/ExperimentalStateTracker.java @@ -48,12 +48,13 @@ import java.util.TreeSet; */ class ExperimentalStateTracker { - static final int SAMPLE_SIZE = 3; static final long SHOW_TIME_THRESHOLD_SECONDS = 3; static final String ELLIPSIS = "..."; static final int NANOS_PER_SECOND = 1000000000; + private int sampleSize = 3; + private String status; private String additionalMessage; @@ -101,6 +102,13 @@ class ExperimentalStateTracker { this(clock, 0); } + /** + * Set the maximal number of actions shown in the progress bar. + */ + void setSampleSize(int sampleSize) { + this.sampleSize = sampleSize; + } + void buildStarted(BuildStartingEvent event) { status = "Loading"; additionalMessage = ""; @@ -368,10 +376,11 @@ class ExperimentalStateTracker { continue; } count++; - if (count > SAMPLE_SIZE) { + if (count > sampleSize) { + totalCount--; break; } - int width = (count >= SAMPLE_SIZE && count < actionCount) ? targetWidth - 8 : targetWidth - 4; + int width = (count >= sampleSize && count < actionCount) ? targetWidth - 8 : targetWidth - 4; terminalWriter.newline().append(" " + describeAction(action, nanoTime, width, toSkip)); } if (totalCount < actionCount) { diff --git a/src/test/java/com/google/devtools/build/lib/runtime/ExperimentalStateTrackerTest.java b/src/test/java/com/google/devtools/build/lib/runtime/ExperimentalStateTrackerTest.java index ead2c53e46..da25a610b9 100644 --- a/src/test/java/com/google/devtools/build/lib/runtime/ExperimentalStateTrackerTest.java +++ b/src/test/java/com/google/devtools/build/lib/runtime/ExperimentalStateTrackerTest.java @@ -199,6 +199,42 @@ public class ExperimentalStateTrackerTest extends FoundationTestCase { } @Test + public void testSampleSize() throws IOException { + // Verify that the number of actions shown in the progress bar can be set as sample size. + ManualClock clock = new ManualClock(); + clock.advanceMillis(TimeUnit.SECONDS.toMillis(123)); + ExperimentalStateTracker stateTracker = new ExperimentalStateTracker(clock); + clock.advanceMillis(TimeUnit.SECONDS.toMillis(2)); + + // Start 10 actions (numbered 0 to 9). + for (int i = 0; i < 10; i++) { + clock.advanceMillis(TimeUnit.SECONDS.toMillis(1)); + Action action = mockAction("Performing action A" + i + ".", "action_A" + i + ".out"); + stateTracker.actionStarted(new ActionStartedEvent(action, clock.nanoTime())); + } + + // For various sample sizes verify the progress bar + for (int i = 1; i < 11; i++) { + stateTracker.setSampleSize(i); + LoggingTerminalWriter terminalWriter = new LoggingTerminalWriter(/*discardHighlight=*/ true); + stateTracker.writeProgressBar(terminalWriter); + String output = terminalWriter.getTranscript(); + assertTrue( + "Action " + (i - 1) + " should still be shown in the output: '" + output, + output.contains("A" + (i - 1) + ".")); + assertFalse( + "Action " + i + " should not be shown in the output: " + output, + output.contains("A" + i + ".")); + if (i < 10) { + assertTrue("Ellipsis symbol should be shown in output: " + output, output.contains("...")); + } else { + assertFalse( + "Ellipsis symbol should not be shown in output: " + output, output.contains("...")); + } + } + } + + @Test public void testTimesShown() throws IOException { // For sufficiently long running actions, the time that has passed since their start is shown. // In the short version of the progress bar, this should be true at least for the oldest action. |