Log count and size of output files and top-level files seen this build to the BEP. Augment existing logging for source files to log count in addition to size.

PiperOrigin-RevId: 354612893
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/TreeArtifactValue.java b/src/main/java/com/google/devtools/build/lib/skyframe/TreeArtifactValue.java
index e02e068..777643e 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/TreeArtifactValue.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/TreeArtifactValue.java
@@ -28,6 +28,7 @@
 import com.google.devtools.build.lib.actions.Artifact.SpecialArtifact;
 import com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact;
 import com.google.devtools.build.lib.actions.FileArtifactValue;
+import com.google.devtools.build.lib.actions.FileStateType;
 import com.google.devtools.build.lib.actions.HasDigest;
 import com.google.devtools.build.lib.actions.cache.MetadataDigestUtils;
 import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec;
@@ -150,11 +151,13 @@
       new TreeArtifactValue(
           MetadataDigestUtils.fromMetadata(ImmutableMap.of()),
           ImmutableSortedMap.of(),
+          0L,
           /*archivedRepresentation=*/ null,
           /*entirelyRemote=*/ false);
 
   private final byte[] digest;
   private final ImmutableSortedMap<TreeFileArtifact, FileArtifactValue> childData;
+  private final long totalChildSize;
 
   /**
    * Optional archived representation of the entire tree artifact which can be sent instead of all
@@ -167,10 +170,12 @@
   private TreeArtifactValue(
       byte[] digest,
       ImmutableSortedMap<TreeFileArtifact, FileArtifactValue> childData,
+      long totalChildSize,
       @Nullable ArchivedRepresentation archivedRepresentation,
       boolean entirelyRemote) {
     this.digest = digest;
     this.childData = childData;
+    this.totalChildSize = totalChildSize;
     this.archivedRepresentation = archivedRepresentation;
     this.entirelyRemote = entirelyRemote;
   }
@@ -194,6 +199,10 @@
     return childData.keySet();
   }
 
+  public long getTotalChildBytes() {
+    return totalChildSize;
+  }
+
   /** Return archived representation of the tree artifact (if present). */
   Optional<ArchivedRepresentation> getArchivedRepresentation() {
     return Optional.ofNullable(archivedRepresentation);
@@ -264,6 +273,7 @@
     return new TreeArtifactValue(
         null,
         ImmutableSortedMap.of(),
+        0L,
         /*archivedRepresentation=*/ null,
         /*entirelyRemote=*/ false) {
       @Override
@@ -475,13 +485,19 @@
       boolean entirelyRemote =
           archivedRepresentation == null || archivedRepresentation.archivedFileValue().isRemote();
 
+      long totalChildSize = 0;
       for (Map.Entry<TreeFileArtifact, FileArtifactValue> childData : finalChildData.entrySet()) {
         // Digest will be deterministic because children are sorted.
         fingerprint.addPath(childData.getKey().getParentRelativePath());
-        childData.getValue().addTo(fingerprint);
+        FileArtifactValue metadata = childData.getValue();
+        metadata.addTo(fingerprint);
 
         // Tolerate a mix of local and remote children (b/152496153#comment80).
-        entirelyRemote &= childData.getValue().isRemote();
+        entirelyRemote &= metadata.isRemote();
+
+        if (metadata.getType() == FileStateType.REGULAR_FILE) {
+          totalChildSize += metadata.getSize();
+        }
       }
 
       if (archivedRepresentation != null) {
@@ -489,7 +505,11 @@
       }
 
       return new TreeArtifactValue(
-          fingerprint.digestAndReset(), finalChildData, archivedRepresentation, entirelyRemote);
+          fingerprint.digestAndReset(),
+          finalChildData,
+          totalChildSize,
+          archivedRepresentation,
+          entirelyRemote);
     }
   }
 }