Skip to content

Commit

Permalink
Debug action logs (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
bvatai-br authored Nov 28, 2024
1 parent d18abc6 commit dcb0724
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import com.google.devtools.build.lib.vfs.PathFragment;
import java.util.SortedMap;
import javax.annotation.Nullable;
import java.io.FileWriter;
import java.io.IOException;

/**
* A value class representing an action which can be executed remotely.
Expand All @@ -42,6 +44,7 @@ public class RemoteAction {
private final RemoteActionExecutionContext remoteActionExecutionContext;
private final RemotePathResolver remotePathResolver;
@Nullable private final MerkleTree merkleTree;
@Nullable private final MerkleTree merkleTreeForDebug;
private final long inputBytes;
private final long inputFiles;
private final Digest commandHash;
Expand All @@ -65,6 +68,7 @@ public class RemoteAction {
this.remoteActionExecutionContext = remoteActionExecutionContext;
this.remotePathResolver = remotePathResolver;
this.merkleTree = remoteDiscardMerkleTrees ? null : merkleTree;
this.merkleTreeForDebug = merkleTree;
this.inputBytes = merkleTree.getInputBytes();
this.inputFiles = merkleTree.getInputFiles();
this.commandHash = commandHash;
Expand All @@ -73,6 +77,39 @@ public class RemoteAction {
this.actionKey = actionKey;
}

private void writeDirectoryToFile(FileWriter writer, String root, MerkleTree t) throws IOException {
writer.write("[Root proto of " + root + "]\n");
if (t != null) {
writer.write(t.rootProto.toString());
for (String dirName : t.directories.keySet()) {
MerkleTree dir = t.directories.get(dirName);
writeDirectoryToFile(writer, root + "/" + dirName, dir);
}
} else {
writer.write("[merkleTree is null]\n");
}
}

public void writeToFile() {
String jsonPath = "/tmp/bazeldebug/" + actionKey.getDigest().getHash() + ".txt";
try (FileWriter writer = new FileWriter(jsonPath)) {
writer.write("[Action]\n");
writer.write(action.toString());
writer.write("\n\n");

writer.write("[Command]\n");
writer.write(command.toString());
writer.write("\n\n");

writer.write("[InputRoot]\n");
writeDirectoryToFile(writer, ".", merkleTreeForDebug);

System.out.println(jsonPath + " written.");
} catch (IOException e) {
e.printStackTrace();
}
}

public RemoteActionExecutionContext getRemoteActionExecutionContext() {
return remoteActionExecutionContext;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@
import io.reactivex.rxjava3.schedulers.Schedulers;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.File;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Collection;
Expand Down Expand Up @@ -670,7 +671,6 @@ public RemoteAction buildRemoteAction(Spawn spawn, SpawnExecutionContext context
buildSalt(spawn, spawnScrubber));

ActionKey actionKey = digestUtil.computeActionKey(action);

RequestMetadata metadata =
TracingMetadataUtils.buildMetadata(
buildRequestId, commandId, actionKey.getDigest().getHash(), spawn.getResourceOwner());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,8 @@ public void store(SpawnResult result) throws ExecException, InterruptedException
return;
}

action.writeToFile();

if (options.experimentalGuardAgainstConcurrentChanges) {
try (SilentCloseable c = prof.profile("checkForConcurrentModifications")) {
checkForConcurrentModifications();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,11 @@ private interface MerkleTreeDirectoryVisitor {

private Map<Digest, Directory> digestDirectoryMap;
private Map<Digest, PathOrBytes> digestFileMap;
@Nullable private final Directory rootProto;
private final Digest rootDigest;
private final SortedSet<DirectoryTree.FileNode> files;
@Nullable public final Directory rootProto;
public final Digest rootDigest;
public final SortedSet<DirectoryTree.FileNode> files;
private final SortedSet<DirectoryTree.SymlinkNode> symlinks;
private final SortedMap<String, MerkleTree> directories;
public final SortedMap<String, MerkleTree> directories;
private final long inputFiles;
private final long inputBytes;

Expand All @@ -123,6 +123,7 @@ private MerkleTree(
this.inputBytes = inputBytes;
}

// TODO
/** Returns the digest of the Merkle tree's root. */
@Nullable
public Directory getRootProto() {
Expand Down

0 comments on commit dcb0724

Please sign in to comment.