Skip to content

Commit

Permalink
Add option to handle edges from file write actions (like) actions cor…
Browse files Browse the repository at this point in the history
…rectly.

PiperOrigin-RevId: 518203038
Change-Id: I3c1e903a7ad0adb148e74b601383ad3308c250d5
  • Loading branch information
meisterT authored and copybara-github committed Mar 21, 2023
1 parent cd4e142 commit 4973166
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/main/java/com/google/devtools/build/lib/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ java_library(
"//src/main/java/com/google/devtools/build/lib/actions:package_roots",
"//src/main/java/com/google/devtools/build/lib/actions:resource_manager",
"//src/main/java/com/google/devtools/build/lib/actions:shared_action_event",
"//src/main/java/com/google/devtools/build/lib/analysis:actions/abstract_file_write_action",
"//src/main/java/com/google/devtools/build/lib/analysis:analysis_cluster",
"//src/main/java/com/google/devtools/build/lib/analysis:analysis_options",
"//src/main/java/com/google/devtools/build/lib/analysis:analysis_phase_complete_event",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public NestedSet<Artifact> getTools() {

@Override
public NestedSet<Artifact> getInputs() {
throw new UnsupportedOperationException();
return actionExecutionMetadata.getInputs();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import com.google.devtools.build.lib.actions.SpawnExecutedEvent;
import com.google.devtools.build.lib.actions.SpawnMetrics;
import com.google.devtools.build.lib.actions.SpawnResult;
import com.google.devtools.build.lib.analysis.actions.AbstractFileWriteAction;
import com.google.devtools.build.lib.bugreport.BugReport;
import com.google.devtools.build.lib.bugreport.BugReporter;
import com.google.devtools.build.lib.buildeventstream.BuildEvent.LocalFile.LocalFileCompression;
Expand Down Expand Up @@ -151,6 +152,14 @@ public static class ExecutionGraphOptions extends OptionsBase {
defaultValue = "true",
help = "Subscribe to ActionCompletionEvent in ExecutionGraphModule.")
public boolean logMissedActions;

@Option(
name = "experimental_execution_graph_enable_edges_from_filewrite_actions",
documentationCategory = OptionDocumentationCategory.UNDOCUMENTED,
effectTags = {OptionEffectTag.UNKNOWN},
defaultValue = "false",
help = "Handle edges from filewrite actions to their inputs correctly.")
public boolean logFileWriteEdges;
}

/** What level of dependency information to include in the dump. */
Expand Down Expand Up @@ -455,12 +464,22 @@ private ExecutionGraph.Node toProto(SpawnExecutedEvent event) {
metricsBuilder.putRetryMillisByError(entry.getKey(), entry.getValue());
}
metrics = null;

NestedSet<? extends ActionInput> inputFiles;
if (logFileWriteEdges && spawn.getResourceOwner() instanceof AbstractFileWriteAction) {
// In order to handle file write like actions correctly, get the inputs
// from the corresponding action.
inputFiles = spawn.getResourceOwner().getInputs();
} else {
inputFiles = spawn.getInputFiles();
}

// maybeAddEdges can take a while, so do it last and try to give up references to any objects
// we won't need.
maybeAddEdges(
nodeBuilder,
spawn.getOutputEdgesForExecutionGraph(),
spawn.getInputFiles(),
inputFiles,
spawn.getResourceOwner(),
spawn.getRunfilesSupplier(),
startMillis,
Expand Down Expand Up @@ -578,6 +597,7 @@ private NodeInfo(int index, long finishMs) {

private final BugReporter bugReporter;
private final boolean localLockFreeOutputEnabled;
private final boolean logFileWriteEdges;
private final Map<ActionInput, NodeInfo> outputToNode = new ConcurrentHashMap<>();
private final Map<ActionInput, Duration> outputToDiscoverInputsTime = new ConcurrentHashMap<>();
private final DependencyInfo depType;
Expand Down Expand Up @@ -605,12 +625,14 @@ private NodeInfo(int index, long finishMs) {
ActionDumpWriter(
BugReporter bugReporter,
boolean localLockFreeOutputEnabled,
boolean logFileWriteEdges,
OutputStream outStream,
UUID commandId,
DependencyInfo depType,
int queueSize) {
this.bugReporter = bugReporter;
this.localLockFreeOutputEnabled = localLockFreeOutputEnabled;
this.logFileWriteEdges = logFileWriteEdges;
this.outStream = outStream;
this.depType = depType;
if (queueSize < 0) {
Expand Down Expand Up @@ -772,6 +794,7 @@ private ActionDumpWriter createActionDumpWriter(CommandEnvironment env)
return new StreamingActionDumpWriter(
env.getRuntime().getBugReporter(),
env.getOptions().getOptions(LocalExecutionOptions.class).localLockfreeOutput,
executionGraphOptions.logFileWriteEdges,
newUploader(env, bepOptions).startUpload(LocalFileType.PERFORMANCE_LOG, null),
env.getCommandId(),
executionGraphOptions.depType,
Expand All @@ -784,6 +807,7 @@ private ActionDumpWriter createActionDumpWriter(CommandEnvironment env)
return new FilesystemActionDumpWriter(
env.getRuntime().getBugReporter(),
env.getOptions().getOptions(LocalExecutionOptions.class).localLockfreeOutput,
executionGraphOptions.logFileWriteEdges,
actionGraphFile,
env.getCommandId(),
executionGraphOptions.depType,
Expand All @@ -799,6 +823,7 @@ private static final class FilesystemActionDumpWriter extends ActionDumpWriter {
public FilesystemActionDumpWriter(
BugReporter bugReporter,
boolean localLockFreeOutputEnabled,
boolean logFileWriteEdges,
Path actionGraphFile,
UUID uuid,
DependencyInfo depType,
Expand All @@ -807,6 +832,7 @@ public FilesystemActionDumpWriter(
super(
bugReporter,
localLockFreeOutputEnabled,
logFileWriteEdges,
actionGraphFile.getOutputStream(),
uuid,
depType,
Expand Down Expand Up @@ -845,13 +871,15 @@ private static class StreamingActionDumpWriter extends ActionDumpWriter {
public StreamingActionDumpWriter(
BugReporter bugReporter,
boolean localLockFreeOutputEnabled,
boolean logFileWriteEdges,
UploadContext uploadContext,
UUID commandId,
DependencyInfo depType,
int queueSize) {
super(
bugReporter,
localLockFreeOutputEnabled,
logFileWriteEdges,
uploadContext.getOutputStream(),
commandId,
depType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,8 @@ public void failureInOutputDoesNotHang(
ActionDumpWriter writer =
new ActionDumpWriter(
BugReporter.defaultInstance(),
/*localLockFreeOutputEnabled=*/ false,
/* localLockFreeOutputEnabled= */ false,
/* logFileWriteEdges= */ false,
OutputStream.nullOutputStream(),
uuid,
DependencyInfo.NONE,
Expand All @@ -326,7 +327,8 @@ private void startLogging(
startLogging(
eventBus,
BugReporter.defaultInstance(),
/*localLockFreeOutputEnabled=*/ false,
/* localLockFreeOutputEnabled= */ false,
/* logFileWriteEdges= */ false,
uuid,
buffer,
depType);
Expand All @@ -336,11 +338,13 @@ private void startLogging(
EventBus eventBus,
BugReporter bugReporter,
boolean localLockFreeOutputEnabled,
boolean logFileWriteEdges,
UUID uuid,
OutputStream buffer,
DependencyInfo depType) {
ActionDumpWriter writer =
new ActionDumpWriter(bugReporter, localLockFreeOutputEnabled, buffer, uuid, depType, -1) {
new ActionDumpWriter(
bugReporter, localLockFreeOutputEnabled, logFileWriteEdges, buffer, uuid, depType, -1) {
@Override
protected void updateLogs(BuildToolLogCollection logs) {}
};
Expand Down Expand Up @@ -541,6 +545,7 @@ public void multipleSpawnsWithSameOutput_overlapping_recordsBothSpawnsWithoutRet
eventBus,
bugReporter,
localLockFreeOutput.optionValue,
/* logFileWriteEdges= */ false,
UUID.randomUUID(),
buffer,
DependencyInfo.ALL);
Expand Down Expand Up @@ -585,7 +590,8 @@ public void multipleSpawnsWithSameOutput_overlapping_ignoresSecondSpawnForDepend
startLogging(
eventBus,
BugReporter.defaultInstance(),
/*localLockFreeOutputEnabled=*/ true,
/* localLockFreeOutputEnabled= */ true,
/* logFileWriteEdges= */ false,
UUID.randomUUID(),
buffer,
DependencyInfo.ALL);
Expand Down

0 comments on commit 4973166

Please sign in to comment.