Track strategies as part of SchedulingActionEvent.
An action's scheduling happens once a strategy has been selected for
execution, so add the strategy name to the SchedulingActionEvent message.
Necessary cleanup to address https://github.com/bazelbuild/bazel/issues/7345.
RELNOTES: None.
PiperOrigin-RevId: 235061057
diff --git a/src/main/java/com/google/devtools/build/lib/actions/SchedulingActionEvent.java b/src/main/java/com/google/devtools/build/lib/actions/SchedulingActionEvent.java
index ea1fa66..d9e542b 100644
--- a/src/main/java/com/google/devtools/build/lib/actions/SchedulingActionEvent.java
+++ b/src/main/java/com/google/devtools/build/lib/actions/SchedulingActionEvent.java
@@ -26,14 +26,21 @@
public class SchedulingActionEvent implements ProgressLike {
private final ActionExecutionMetadata action;
+ private final String strategy;
/** Constructs a new event. */
- public SchedulingActionEvent(ActionExecutionMetadata action) {
+ public SchedulingActionEvent(ActionExecutionMetadata action, String strategy) {
this.action = action;
+ this.strategy = strategy;
}
/** Gets the metadata associated with the action being scheduled. */
public ActionExecutionMetadata getActionMetadata() {
return action;
}
+
+ /** Gets the name of the strategy on which the action is scheduling. */
+ public String getStrategy() {
+ return strategy;
+ }
}
diff --git a/src/main/java/com/google/devtools/build/lib/exec/AbstractSpawnStrategy.java b/src/main/java/com/google/devtools/build/lib/exec/AbstractSpawnStrategy.java
index 189bb9e..79bfb90 100644
--- a/src/main/java/com/google/devtools/build/lib/exec/AbstractSpawnStrategy.java
+++ b/src/main/java/com/google/devtools/build/lib/exec/AbstractSpawnStrategy.java
@@ -271,7 +271,7 @@
eventHandler.post(new RunningActionEvent(action, name));
break;
case SCHEDULING:
- eventHandler.post(new SchedulingActionEvent(action));
+ eventHandler.post(new SchedulingActionEvent(action, name));
break;
default:
break;
diff --git a/src/test/java/com/google/devtools/build/lib/actions/ActionExecutionStatusReporterTest.java b/src/test/java/com/google/devtools/build/lib/actions/ActionExecutionStatusReporterTest.java
index 264f0e6..84d7c66 100644
--- a/src/test/java/com/google/devtools/build/lib/actions/ActionExecutionStatusReporterTest.java
+++ b/src/test/java/com/google/devtools/build/lib/actions/ActionExecutionStatusReporterTest.java
@@ -104,7 +104,7 @@
setPreparing(mockAction("action1"));
clock.advanceMillis(1000);
verifyWarningOutput("Still waiting for unfinished jobs");
- setScheduling(mockAction("action2"));
+ setScheduling(mockAction("action2"), "remote");
clock.advanceMillis(1000);
setRunning(mockAction("action3"), "remote");
clock.advanceMillis(1000);
@@ -130,7 +130,7 @@
verifyOutput("Still waiting for 1 job to complete:", "Preparing:", "action1, 1 s");
clock.advanceMillis(5000);
- setScheduling(action);
+ setScheduling(action, "remote");
clock.advanceMillis(1200);
// Only started *scheduling* 1200 ms ago, not 6200 ms ago.
verifyOutput("Still waiting for 1 job to complete:", "Scheduling:", "action1, 1 s");
@@ -149,7 +149,7 @@
setPreparing(action);
clock.advanceMillis(1000);
verifyOutput("Still waiting for 1 job to complete:", "Preparing:", "action1, 1 s");
- setScheduling(action);
+ setScheduling(action, "remote");
clock.advanceMillis(1000);
verifyOutput("Still waiting for 1 job to complete:", "Scheduling:", "action1, 1 s");
setRunning(action, "remote");
@@ -172,7 +172,7 @@
mockAction("local1"), mockAction("local2"), mockAction("local3"));
for (Action a : actions) {
- setScheduling(a);
+ setScheduling(a, "remote");
clock.advanceMillis(1000);
}
@@ -204,7 +204,7 @@
for (int i = 1; i <= 100; i++) {
Action a = mockAction("a" + i);
actions.add(a);
- setScheduling(a);
+ setScheduling(a, "remote");
clock.advanceMillis(1000);
}
verifyOutput("Still waiting for 100 jobs to complete:", "Scheduling:",
@@ -224,13 +224,13 @@
@Test
public void testOrdering() throws Exception {
verifyNoOutput();
- setScheduling(mockAction("a1"));
+ setScheduling(mockAction("a1"), "remote");
clock.advanceMillis(1000);
setPreparing(mockAction("b1"));
clock.advanceMillis(1000);
setPreparing(mockAction("b2"));
clock.advanceMillis(1000);
- setScheduling(mockAction("a2"));
+ setScheduling(mockAction("a2"), "remote");
clock.advanceMillis(1000);
verifyOutput("Still waiting for 4 jobs to complete:",
"Preparing:", "b1, 3 s", "b2, 2 s",
@@ -240,7 +240,7 @@
@Test
public void testNoProgressMessage() throws Exception {
verifyNoOutput();
- setScheduling(mockAction(null));
+ setScheduling(mockAction(null), "remote");
verifyOutput("Still waiting for 1 job to complete:", "Scheduling:", "default message, 0 s");
}
@@ -261,8 +261,8 @@
assertThat(ActionExecutionStatusReporter.getWaitTime(30, 30)).isEqualTo(30);
}
- private void setScheduling(ActionExecutionMetadata action) {
- eventBus.post(new SchedulingActionEvent(action));
+ private void setScheduling(ActionExecutionMetadata action, String strategy) {
+ eventBus.post(new SchedulingActionEvent(action, strategy));
}
private void setPreparing(Action action) {
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 8176c32..3366488 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
@@ -602,7 +602,7 @@
// Then action bar gets scheduled.
stateTracker.actionStarted(new ActionStartedEvent(actionBar, 123456701));
- stateTracker.schedulingAction(new SchedulingActionEvent(actionBar));
+ stateTracker.schedulingAction(new SchedulingActionEvent(actionBar, "bar-sandbox"));
terminalWriter = new LoggingTerminalWriter(/*discardHighlight=*/ true);
stateTracker.writeProgressBar(terminalWriter);
@@ -667,7 +667,7 @@
stateTracker.runningAction(new RunningActionEvent(actionFoo, "foo-sandbox"));
clock.advanceMillis(TimeUnit.SECONDS.toMillis(7));
stateTracker.actionStarted(new ActionStartedEvent(actionBar, clock.nanoTime()));
- stateTracker.schedulingAction(new SchedulingActionEvent(actionBar));
+ stateTracker.schedulingAction(new SchedulingActionEvent(actionBar, "bar-sandbox"));
clock.advanceMillis(TimeUnit.SECONDS.toMillis(21));
terminalWriter = new LoggingTerminalWriter(/*discardHighlight=*/ true);
@@ -748,7 +748,7 @@
ActionOwner owner = Mockito.mock(ActionOwner.class);
when(action.getOwner()).thenReturn(owner);
stateTracker.actionStarted(new ActionStartedEvent(action, 123456789 + i));
- stateTracker.schedulingAction(new SchedulingActionEvent(action));
+ stateTracker.schedulingAction(new SchedulingActionEvent(action, "xyz-sandbox"));
}
for (int i = 0; i < 3; i++) {