Include the file count in ChangedFilesMessage.

--
MOS_MIGRATED_REVID=116292374
diff --git a/src/main/java/com/google/devtools/build/lib/actions/ChangedFilesMessage.java b/src/main/java/com/google/devtools/build/lib/actions/ChangedFilesMessage.java
index f2d0ea8..09b439c 100644
--- a/src/main/java/com/google/devtools/build/lib/actions/ChangedFilesMessage.java
+++ b/src/main/java/com/google/devtools/build/lib/actions/ChangedFilesMessage.java
@@ -20,17 +20,32 @@
 
 /**
  * A message sent conveying a set of changed files. This is sent over the event bus if a build is
- * discovered to have few changed files. If many files have changed, it will not be sent at all.
+ * 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.
  */
 public class ChangedFilesMessage {
 
   private final Set<PathFragment> changedFiles;
+  private final int changedFileCount;
 
-  public ChangedFilesMessage(Set<PathFragment> changedFiles) {
+  public ChangedFilesMessage(Set<PathFragment> changedFiles, int changedFileCount) {
     this.changedFiles = ImmutableSet.copyOf(changedFiles);
+    this.changedFileCount = changedFileCount;
   }
 
+  /**
+   * 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;
   }
+
+  /**
+   * 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.
+   */
+  public int getChangedFileCount() {
+    return changedFileCount;
+  }
 }
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeIncrementalBuildMonitor.java b/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeIncrementalBuildMonitor.java
index a719bec..bb27716 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeIncrementalBuildMonitor.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeIncrementalBuildMonitor.java
@@ -13,6 +13,7 @@
 // limitations under the License.
 package com.google.devtools.build.lib.skyframe;
 
+import com.google.common.collect.ImmutableSet;
 import com.google.common.eventbus.EventBus;
 import com.google.devtools.build.lib.actions.ChangedFilesMessage;
 import com.google.devtools.build.lib.concurrent.ThreadSafety;
@@ -30,9 +31,11 @@
  */
 @ThreadSafety.ThreadCompatible
 class SkyframeIncrementalBuildMonitor {
-  private Set<PathFragment> files = new HashSet<>();
   private static final int MAX_FILES = 100;
 
+  private Set<PathFragment> files = new HashSet<>();
+  private int fileCount;
+
   public void accrue(Iterable<SkyKey> invalidatedValues) {
     for (SkyKey skyKey : invalidatedValues) {
       if (skyKey.functionName().equals(SkyFunctions.FILE_STATE)) {
@@ -49,11 +52,12 @@
         files = null;
       }
     }
+
+    fileCount++;
   }
 
   public void alertListeners(EventBus eventBus) {
-    if (files != null) {
-      eventBus.post(new ChangedFilesMessage(files));
-    }
+    Set<PathFragment> changedFiles = (files != null) ? files : ImmutableSet.<PathFragment>of();
+    eventBus.post(new ChangedFilesMessage(changedFiles, fileCount));
   }
 }