Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding log sort flag to disable stable sort and get better memory performance in some situations #17354

Closed
wants to merge 15 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/main/java/com/google/devtools/build/lib/bazel/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ java_library(
"//src/main/java/com/google/devtools/build/lib/util/io",
"//src/main/java/com/google/devtools/build/lib/vfs",
"//src/main/protobuf:failure_details_java_proto",
"//src/main/protobuf:spawn_java_proto",
],
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@
import com.google.devtools.build.lib.remote.options.RemoteOptions;
import com.google.devtools.build.lib.runtime.BlazeModule;
import com.google.devtools.build.lib.runtime.CommandEnvironment;
import com.google.devtools.build.lib.exec.Protos.SpawnExec;
import com.google.devtools.build.lib.server.FailureDetails.Execution;
import com.google.devtools.build.lib.server.FailureDetails.Execution.Code;
import com.google.devtools.build.lib.server.FailureDetails.FailureDetail;
import com.google.devtools.build.lib.util.AbruptExitException;
import com.google.devtools.build.lib.util.DetailedExitCode;
import com.google.devtools.build.lib.util.io.AsynchronousFileOutputStream;
import com.google.devtools.build.lib.util.io.MessageOutputStream;
import com.google.devtools.build.lib.util.io.MessageOutputStreamWrapper.BinaryOutputStreamWrapper;
import com.google.devtools.build.lib.util.io.MessageOutputStreamWrapper.JsonOutputStreamWrapper;
import com.google.devtools.build.lib.util.io.MessageOutputStreamWrapper.MessageOutputStreamCollection;
Expand Down Expand Up @@ -162,7 +164,11 @@ public void afterCommand() throws AbruptExitException {
spawnLogContext.close();
if (!outputStreams.isEmpty()) {
InputStream in = rawOutput.getInputStream();
StableSort.stableSort(in, outputStreams);
if (spawnLogContext.shouldSort()) {
StableSort.stableSort(in, outputStreams);
} else {
ignoreSort(in, outputStreams);
}
outputStreams.close();
}
done = true;
Expand All @@ -183,6 +189,12 @@ public void afterCommand() throws AbruptExitException {
}
}

private void ignoreSort(InputStream in, MessageOutputStream out) throws IOException {
for (SpawnExec ex : StableSort.read(in)) {
out.write(ex);
}
}

private static DetailedExitCode createDetailedExitCode(String message, Code detailedCode) {
return DetailedExitCode.of(
FailureDetail.newBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
* <p>This is needed to allow textual diff comparisons of resultant logs.
*/
public final class StableSort {
private static ImmutableList<SpawnExec> read(InputStream in) throws IOException {
public static ImmutableList<SpawnExec> read(InputStream in) throws IOException {
ImmutableList.Builder<SpawnExec> result = ImmutableList.builder();
while (in.available() > 0) {
SpawnExec ex = SpawnExec.parseDelimitedFrom(in);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,17 @@ public boolean usingLocalTestJobs() {
+ " --subcommands (for displaying subcommands in terminal output).")
public PathFragment executionLogJsonFile;

@Option(
name = "execution_log_sort",
defaultValue = "true",
documentationCategory = OptionDocumentationCategory.UNCATEGORIZED,
effectTags = {OptionEffectTag.UNKNOWN},
help =
"Whether to sort the execution log. Set to false to improve memory"
+ " performance, at the cost of producing the log in nondeterministic"
+ " order.")
public boolean executionLogSort;

@Option(
name = "experimental_split_xml_generation",
defaultValue = "true",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,4 +332,8 @@ private Digest computeDigest(
.setSizeBytes(fileSize)
.build();
}

public boolean shouldSort() {
return executionOptions.executionLogSort;
}
}