Skip to content
Snippets Groups Projects
Commit 19ae1975 authored by ajurkowski's avatar ajurkowski Committed by Copybara-Service
Browse files

Collect the number of invalidated `FileValue` nodes.

We already collect information about the number of `FileStateValue` nodes included in the diff. Expand the event with number of `FileValue` nodes invalidated during evaluation.

PiperOrigin-RevId: 392537693
parent c6509786
No related merge requests found
......@@ -13,39 +13,42 @@
// limitations under the License.
package com.google.devtools.build.lib.actions;
import com.google.auto.value.AutoValue;
import com.google.common.collect.ImmutableSet;
import com.google.devtools.build.lib.vfs.PathFragment;
import java.util.Set;
/**
* A message sent conveying a set of changed files. This is sent over the event bus if a build is
* discovered to have changed files. If many files have changed, the set of changed files will
* be empty, but {@link #getChangedFileCount} will still return the correct number.
* discovered to have changed files. If many files have changed, the set of changed files will be
* empty, but {@link #changedFileCount} will still return the correct number.
*/
public class ChangedFilesMessage {
private final Set<PathFragment> changedFiles;
private final int changedFileCount;
public ChangedFilesMessage(Set<PathFragment> changedFiles, int changedFileCount) {
this.changedFiles = ImmutableSet.copyOf(changedFiles);
this.changedFileCount = changedFileCount;
}
@AutoValue
public abstract class ChangedFilesMessage {
/**
* Returns a set with one PathFragment for each file that was changed since the last build, or
* an empty set if the set is unknown or would be too big.
* Returns a set with one PathFragment for each file that was changed since the last build, or an
* empty set if the set is unknown or would be too big.
*/
public Set<PathFragment> getChangedFiles() {
return changedFiles;
}
public abstract ImmutableSet<PathFragment> changedFiles();
/**
* Returns the number of changed files. This will always be the correct number of files, even when
* {@link #getChangedFiles} might return an empty set, because the actual set would be too big.
* {@link #changedFiles} might return an empty set, because the actual set would be too big.
*/
public int getChangedFileCount() {
return changedFileCount;
public abstract int changedFileCount();
/**
* Returns the number of {@link FileValue} nodes invalidated in the build.
*
* <p>This is different from {@link #changedFiles}, in particular a single file change can result
* with multiple {@linkplain FileValue FVs}.
*/
public abstract int invalidatedFileValueCount();
public static ChangedFilesMessage create(
Set<PathFragment> changedFiles, int changedFileCount, int invalidatedFileValueCount) {
return new AutoValue_ChangedFilesMessage(
ImmutableSet.copyOf(changedFiles), changedFileCount, invalidatedFileValueCount);
}
}
......@@ -230,6 +230,19 @@ public final class SequencedSkyframeExecutor extends SkyframeExecutor {
return recordingDiffer;
}
@Override
protected SkyframeProgressReceiver newSkyframeProgressReceiver() {
return new SkyframeProgressReceiver() {
@Override
public void invalidated(SkyKey skyKey, InvalidationState state) {
super.invalidated(skyKey, state);
if (state == InvalidationState.DIRTY && skyKey instanceof FileValue.Key) {
incrementalBuildMonitor.reportInvalidatedFileValue();
}
}
};
}
@Nullable
@Override
public WorkspaceInfoFromDiff sync(
......
......@@ -23,6 +23,7 @@ import com.google.devtools.build.lib.vfs.RootedPath;
import com.google.devtools.build.skyframe.SkyKey;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.atomic.LongAdder;
/**
* A package-private class intended to track a small number of modified files during the build. This
......@@ -35,6 +36,7 @@ class SkyframeIncrementalBuildMonitor {
private Set<PathFragment> files = new HashSet<>();
private int fileCount;
private final LongAdder invalidatedFileValueCount = new LongAdder();
public void accrue(Iterable<SkyKey> invalidatedValues) {
for (SkyKey skyKey : invalidatedValues) {
......@@ -56,8 +58,14 @@ class SkyframeIncrementalBuildMonitor {
fileCount++;
}
@ThreadSafety.ThreadSafe
public void reportInvalidatedFileValue() {
invalidatedFileValueCount.increment();
}
public void alertListeners(EventBus eventBus) {
Set<PathFragment> changedFiles = (files != null) ? files : ImmutableSet.<PathFragment>of();
eventBus.post(new ChangedFilesMessage(changedFiles, fileCount));
Set<PathFragment> changedFiles = (files != null) ? files : ImmutableSet.of();
eventBus.post(
ChangedFilesMessage.create(changedFiles, fileCount, invalidatedFileValueCount.intValue()));
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment