Add a count of rewound actions to `ActionRewindingStats`.
This will help to demonstrate the impact of the planned work to make action rewinding more precise by not rewinding all fileset and runfiles inputs when only one is lost.
Rename the Java class to `PostableActionRewindingStats` to avoid conflicting with the proto class.
PiperOrigin-RevId: 759252484
Change-Id: I64bf3145e5b42843e88f0891e2e087341aed6fdb
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeActionExecutor.java b/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeActionExecutor.java
index 2abbac0..a40ba17 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeActionExecutor.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeActionExecutor.java
@@ -480,6 +480,15 @@
}
/**
+ * Returns the count of actions rewound during the current build.
+ *
+ * <p>If an action is rewound multiple times, it is only counted once.
+ */
+ public int getRewoundActionCount() {
+ return rewoundActions.size();
+ }
+
+ /**
* Determines whether the action should have its progress events emitted.
*
* <p>Returns {@code false} for rewound actions, indicating that their progress events should be
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutor.java b/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutor.java
index eaf2b48..440223c 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutor.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutor.java
@@ -2471,9 +2471,8 @@
/** Called after a single Skyframe evaluation that involves action execution. */
private void cleanUpAfterSingleEvaluationWithActionExecution(ExtendedEventHandler eventHandler) {
setExecutionProgressReceiver(null);
-
- skyframeActionExecutor.executionOver();
actionRewindStrategy.reset(eventHandler);
+ skyframeActionExecutor.executionOver();
}
/**
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/rewinding/ActionRewindStrategy.java b/src/main/java/com/google/devtools/build/lib/skyframe/rewinding/ActionRewindStrategy.java
index 4082876..e417646 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/rewinding/ActionRewindStrategy.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/rewinding/ActionRewindStrategy.java
@@ -358,10 +358,11 @@
* rewind plans.
*/
public void reset(ExtendedEventHandler eventHandler) {
- ActionRewindingStats rewindingStats =
- new ActionRewindingStats(
+ PostableActionRewindingStats rewindingStats =
+ new PostableActionRewindingStats(
currentBuildLostInputRecords.size(),
currentBuildLostOutputRecords.size(),
+ skyframeActionExecutor.getRewoundActionCount(),
ImmutableList.copyOf(rewindEventSamples));
eventHandler.post(rewindingStats);
currentBuildLostInputRecords = ConcurrentHashMultiset.create();
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/rewinding/ActionRewindingStats.java b/src/main/java/com/google/devtools/build/lib/skyframe/rewinding/ActionRewindingStats.java
deleted file mode 100644
index ac0ba3f..0000000
--- a/src/main/java/com/google/devtools/build/lib/skyframe/rewinding/ActionRewindingStats.java
+++ /dev/null
@@ -1,50 +0,0 @@
-// Copyright 2019 The Bazel Authors. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package com.google.devtools.build.lib.skyframe.rewinding;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-
-import com.google.common.collect.ImmutableList;
-import com.google.devtools.build.lib.events.ExtendedEventHandler;
-import com.google.devtools.build.lib.skyframe.proto.ActionRewind.ActionRewindEvent;
-
-/** Event that encapsulates data about action rewinding during a build. */
-public final class ActionRewindingStats implements ExtendedEventHandler.Postable {
-
- private final int lostInputsCount;
- private final int lostOutputsCount;
- private final ImmutableList<ActionRewindEvent> actionRewindEvents;
-
- ActionRewindingStats(
- int lostInputsCount,
- int lostOutputsCount,
- ImmutableList<ActionRewindEvent> actionRewindEvents) {
- this.lostInputsCount = lostInputsCount;
- this.lostOutputsCount = lostOutputsCount;
- this.actionRewindEvents = checkNotNull(actionRewindEvents);
- }
-
- public int lostInputsCount() {
- return lostInputsCount;
- }
-
- public int lostOutputsCount() {
- return lostOutputsCount;
- }
-
- public ImmutableList<ActionRewindEvent> actionRewindEvents() {
- return actionRewindEvents;
- }
-}
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/rewinding/BUILD b/src/main/java/com/google/devtools/build/lib/skyframe/rewinding/BUILD
index 5a9000d..bd5e8d4 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/rewinding/BUILD
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/rewinding/BUILD
@@ -34,7 +34,7 @@
srcs = [
"ActionRewindException.java",
"ActionRewindStrategy.java",
- "ActionRewindingStats.java",
+ "PostableActionRewindingStats.java",
],
deps = [
":action_rewound_event",
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/rewinding/PostableActionRewindingStats.java b/src/main/java/com/google/devtools/build/lib/skyframe/rewinding/PostableActionRewindingStats.java
new file mode 100644
index 0000000..9905edd
--- /dev/null
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/rewinding/PostableActionRewindingStats.java
@@ -0,0 +1,34 @@
+// Copyright 2019 The Bazel Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package com.google.devtools.build.lib.skyframe.rewinding;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import com.google.common.collect.ImmutableList;
+import com.google.devtools.build.lib.events.ExtendedEventHandler;
+import com.google.devtools.build.lib.skyframe.proto.ActionRewind.ActionRewindEvent;
+
+/** Event that encapsulates data about action rewinding during a build. */
+public record PostableActionRewindingStats(
+ int lostInputsCount,
+ int lostOutputsCount,
+ int rewoundActionCount,
+ ImmutableList<ActionRewindEvent> actionRewindEvents)
+ implements ExtendedEventHandler.Postable {
+
+ public PostableActionRewindingStats {
+ checkNotNull(actionRewindEvents);
+ }
+}
diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/rewinding/RewindingTestsHelper.java b/src/test/java/com/google/devtools/build/lib/skyframe/rewinding/RewindingTestsHelper.java
index f257093..ed9668d 100644
--- a/src/test/java/com/google/devtools/build/lib/skyframe/rewinding/RewindingTestsHelper.java
+++ b/src/test/java/com/google/devtools/build/lib/skyframe/rewinding/RewindingTestsHelper.java
@@ -748,7 +748,7 @@
* This test sets up {@link ActionRewindStrategy#MAX_ACTION_REWIND_EVENTS} + 1 (N) genrules that
* consume 1 ... N inputs respectively and will build each of the genrules. All N inputs will be
* lost and throw a {@link LostInputsExecException} such that all of the genrule actions will
- * rewind. The {@link ActionRewindingStats} event will contain the top {@link
+ * rewind. The {@link PostableActionRewindingStats} event will contain the top {@link
* ActionRewindStrategy#MAX_ACTION_REWIND_EVENTS} action rewind events based on the maximum number
* of nodes invalidated for each rewind action plan. The expected action rewind events logged will
* not contain the genrule action with one input.
diff --git a/src/test/java/com/google/devtools/build/lib/testutil/ActionEventRecorder.java b/src/test/java/com/google/devtools/build/lib/testutil/ActionEventRecorder.java
index 3b9acbf..cea557b 100644
--- a/src/test/java/com/google/devtools/build/lib/testutil/ActionEventRecorder.java
+++ b/src/test/java/com/google/devtools/build/lib/testutil/ActionEventRecorder.java
@@ -26,8 +26,8 @@
import com.google.devtools.build.lib.actions.ActionResultReceivedEvent;
import com.google.devtools.build.lib.actions.ActionStartedEvent;
import com.google.devtools.build.lib.actions.CachedActionEvent;
-import com.google.devtools.build.lib.skyframe.rewinding.ActionRewindingStats;
import com.google.devtools.build.lib.skyframe.rewinding.ActionRewoundEvent;
+import com.google.devtools.build.lib.skyframe.rewinding.PostableActionRewindingStats;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -49,7 +49,7 @@
Collections.synchronizedList(new ArrayList<>());
private final List<ActionRewoundEvent> actionRewoundEvents =
Collections.synchronizedList(new ArrayList<>());
- private final List<ActionRewindingStats> actionRewindingStatsPosts =
+ private final List<PostableActionRewindingStats> actionRewindingStatsPosts =
Collections.synchronizedList(new ArrayList<>());
private Consumer<ActionRewoundEvent> actionRewoundEventSubscriber = e -> {};
@@ -78,7 +78,7 @@
return actionRewoundEvents;
}
- public List<ActionRewindingStats> getActionRewindingStatsPosts() {
+ public List<PostableActionRewindingStats> getActionRewindingStatsPosts() {
return actionRewindingStatsPosts;
}
@@ -128,7 +128,7 @@
@SuppressWarnings("unused")
@Subscribe
@AllowConcurrentEvents
- void actionRewindingStats(ActionRewindingStats actionRewindingStats) {
+ void actionRewindingStats(PostableActionRewindingStats actionRewindingStats) {
actionRewindingStatsPosts.add(actionRewindingStats);
}
@@ -226,32 +226,32 @@
}
/**
- * Asserts that the total lost input counts from posted {@link ActionRewindingStats} matches
- * expected results.
+ * Asserts that the total lost input counts from posted {@link PostableActionRewindingStats}
+ * matches expected results.
*
* @param totalLostInputCounts - The list of the counts of all lost inputs logged with each {@link
- * ActionRewindingStats} post.
+ * PostableActionRewindingStats} post.
*/
public void assertTotalLostInputCountsFromStats(ImmutableList<Integer> totalLostInputCounts) {
assertThat(actionRewindingStatsPosts).hasSize(totalLostInputCounts.size());
for (int postIndex = 0; postIndex < totalLostInputCounts.size(); postIndex++) {
- ActionRewindingStats actionRewindingStats = actionRewindingStatsPosts.get(postIndex);
+ PostableActionRewindingStats actionRewindingStats = actionRewindingStatsPosts.get(postIndex);
assertThat(actionRewindingStats.lostInputsCount())
.isEqualTo(totalLostInputCounts.get(postIndex));
}
}
/**
- * Asserts that the total lost output counts from posted {@link ActionRewindingStats} matches
- * expected results.
+ * Asserts that the total lost output counts from posted {@link PostableActionRewindingStats}
+ * matches expected results.
*
* @param totalLostOutputCounts - The list of the counts of all lost outputs logged with each
- * {@link ActionRewindingStats} post.
+ * {@link PostableActionRewindingStats} post.
*/
public void assertTotalLostOutputCountsFromStats(ImmutableList<Integer> totalLostOutputCounts) {
assertThat(actionRewindingStatsPosts).hasSize(totalLostOutputCounts.size());
for (int postIndex = 0; postIndex < totalLostOutputCounts.size(); postIndex++) {
- ActionRewindingStats actionRewindingStats = actionRewindingStatsPosts.get(postIndex);
+ PostableActionRewindingStats actionRewindingStats = actionRewindingStatsPosts.get(postIndex);
assertThat(actionRewindingStats.lostOutputsCount())
.isEqualTo(totalLostOutputCounts.get(postIndex));
}